diff --git a/.gitignore b/.gitignore index dbde8b67..b47c31a8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ blender_assets.cats.txt* installer/ Trunk.toml + +trace-*.json \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c138a5a6..7fe76593 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -715,6 +715,8 @@ dependencies = [ "bevy_ecs", "bevy_utils", "console_error_panic_hook", + "tracing-chrome", + "tracing-error", "tracing-log", "tracing-subscriber", "tracing-wasm", @@ -960,6 +962,7 @@ dependencies = [ "naga", "once_cell", "parking_lot", + "profiling", "regex", "serde", "smallvec", @@ -2470,6 +2473,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" + [[package]] name = "khronos-egl" version = "4.1.0" @@ -3309,6 +3318,20 @@ name = "profiling" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74605f360ce573babfe43964cbe520294dcb081afbf8c108fc6e23036b4da2df" +dependencies = [ + "profiling-procmacros", + "tracing", +] + +[[package]] +name = "profiling-procmacros" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a1e2417ef905b8ad94215f8a607bd2d0f5d13d416d18dca4a530811e8a0674c" +dependencies = [ + "quote", + "syn", +] [[package]] name = "quote" @@ -4085,6 +4108,18 @@ dependencies = [ "syn", ] +[[package]] +name = "tracing-chrome" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1ac1f6a3a47e9c755e65ef974653c978da2246487a16044a8ee1d9a0a67257c" +dependencies = [ + "crossbeam", + "json", + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-core" version = "0.1.30" @@ -4095,6 +4130,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + [[package]] name = "tracing-log" version = "0.1.3" diff --git a/Cargo.toml b/Cargo.toml index bf390b64..27ae5214 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ native-dev = [ native = [ "bevy_rapier3d/parallel", - "bevy_rapier3d/simd-nightly", "bevy_hanabi", ] @@ -47,6 +46,10 @@ wasm = [ "bevy_rapier3d/wasm-bindgen" ] +tracing = [ + "bevy/trace_chrome" +] + [dependencies] bevy = { version = "^0.9.1", default-features = false } bevy_kira_audio = "0.13" @@ -67,7 +70,7 @@ iyes_progress = "0.7.1" unicode-segmentation = "1.10.1" bevy_hanabi = { version = "0.5", optional = true } anyhow = "1.0.69" -bevy_rapier3d = { version = "0.20", features = ["serde-serialize"] } +bevy_rapier3d = { version = "0.20", features = ["serde-serialize", "simd-nightly"] } # keep the following in sync with Bevy's dependencies winit = { version = "0.27", default-features = false } diff --git a/readme.md b/readme.md index 16ae1cfe..057c45ba 100644 --- a/readme.md +++ b/readme.md @@ -35,7 +35,7 @@ Native: ```bash cargo run ``` -WASM (not fully functional yet, see [#11](https://github.com/janhohenheim/foxtrot/issues/11)): +WASM (runs best on Chromium based browsers): ```bash trunk serve --no-default-features --features core,dev,wasm ``` diff --git a/src/level_instantiation/spawning.rs b/src/level_instantiation/spawning.rs index 5a934e10..91cdc5b1 100644 --- a/src/level_instantiation/spawning.rs +++ b/src/level_instantiation/spawning.rs @@ -73,11 +73,15 @@ impl Plugin for SpawningPlugin { impl<'w, 's, 'a> PrimedGameObjectSpawner<'w, 's, 'a> { pub fn spawn<'c: 'a>(&'c mut self, object: GameObject, transform: Transform) -> Result { + #[cfg(feature = "tracing")] + let _span = info_span!("spawn").entered(); self.outer_spawner.implementors[&object].spawn(self, object, transform) } } fn load_assets_for_spawner(mut commands: Commands, mut mesh_assets: ResMut>) { + #[cfg(feature = "tracing")] + let _span = info_span!("load_assets_for_spawner").entered(); let mut implementors = HashMap::new(); for game_object in GameObject::iter() { diff --git a/src/level_instantiation/spawning/animation_link.rs b/src/level_instantiation/spawning/animation_link.rs index 34a69adf..571e9ca3 100644 --- a/src/level_instantiation/spawning/animation_link.rs +++ b/src/level_instantiation/spawning/animation_link.rs @@ -17,6 +17,8 @@ pub fn link_animations( animations_entity_link_query: Query<&AnimationEntityLink>, mut commands: Commands, ) { + #[cfg(feature = "tracing")] + let _span = info_span!("link_animations").entered(); for entity in player_query.iter() { let top_entity = get_top_parent(entity, &parent_query); if animations_entity_link_query.get(top_entity).is_ok() { diff --git a/src/level_instantiation/spawning/post_spawn_modification.rs b/src/level_instantiation/spawning/post_spawn_modification.rs index 68bb7194..69744394 100644 --- a/src/level_instantiation/spawning/post_spawn_modification.rs +++ b/src/level_instantiation/spawning/post_spawn_modification.rs @@ -5,6 +5,8 @@ use regex::Regex; use std::sync::LazyLock; pub fn set_hidden(mut added_name: Query<(&Name, &mut Visibility), Added>) { + #[cfg(feature = "tracing")] + let _span = info_span!("set_hidden").entered(); for (name, mut visibility) in added_name.iter_mut() { if name.to_lowercase().contains("[hidden]") { visibility.is_visible = false; @@ -16,6 +18,8 @@ pub fn despawn_removed( mut commands: Commands, mut added_name: Query<(Entity, &Name), Added>, ) { + #[cfg(feature = "tracing")] + let _span = info_span!("despawn_removed").entered(); for (entity, name) in added_name.iter_mut() { if name.to_lowercase().contains("[remove]") { commands.entity(entity).insert(Despawn { recursive: true }); @@ -29,6 +33,8 @@ pub fn generate_tangents( mut mesh_asset_events: EventReader>, mut meshes: ResMut>, ) { + #[cfg(feature = "tracing")] + let _span = info_span!("generate_tangents").entered(); for event in mesh_asset_events.iter() { if let AssetEvent::Created { handle } = event { // Guaranteed to work because we just created the mesh @@ -52,6 +58,8 @@ pub fn set_color( material_handles: Query<&Handle>, mut standard_materials: ResMut>, ) -> Result<()> { + #[cfg(feature = "tracing")] + let _span = info_span!("set_color").entered(); for (name, children) in added_name.iter() { if let Some(captures) = COLOR_REGEX.captures(&name.to_lowercase()) { let color = Color::rgba_u8( diff --git a/src/movement/general_movement.rs b/src/movement/general_movement.rs index 18303ced..d7906956 100644 --- a/src/movement/general_movement.rs +++ b/src/movement/general_movement.rs @@ -57,6 +57,8 @@ fn update_grounded( mut query: Query<(Entity, &Transform, &Collider, &mut Grounded)>, rapier_context: Res, ) { + #[cfg(feature = "tracing")] + let _span = info_span!("update_grounded").entered(); for (entity, transform, collider, mut grounded) in &mut query { let height = collider.raw.compute_local_aabb().maxs.y; grounded.0 = rapier_context @@ -79,6 +81,8 @@ pub fn reset_movement_components( mut walking: Query<&mut Walking>, mut jumpers: Query<&mut Jumping>, ) { + #[cfg(feature = "tracing")] + let _span = info_span!("reset_movement_components").entered(); for mut force in &mut forces { *force = default(); } @@ -103,6 +107,8 @@ pub fn apply_jumping( &Transform, )>, ) { + #[cfg(feature = "tracing")] + let _span = info_span!("apply_jumping").entered(); for (grounded, mut impulse, mut velocity, mass, jump, transform) in &mut character_query { if jump.requested && grounded.0 { let up = transform.up(); @@ -117,6 +123,8 @@ pub fn apply_jumping( } fn rotate_characters(time: Res