From 806b615e2bdefe93d5dc9f0eafe6ab2a4641d136 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Tue, 11 Jun 2024 12:14:03 -0400 Subject: [PATCH] println debugging --- crates/bevy_app/src/app.rs | 28 +++++++++++++----------- crates/bevy_app/src/sub_app.rs | 1 + crates/bevy_ecs/src/event/collections.rs | 2 ++ crates/bevy_ecs/src/event/registry.rs | 7 +++++- crates/bevy_ecs/src/event/update.rs | 5 +++++ 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 1391250ac9b4f..c93d4e099b8e7 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -925,7 +925,7 @@ mod tests { change_detection::{DetectChanges, ResMut}, component::Component, entity::Entity, - event::{Event, EventWriter, Events}, + event::{Event, EventWriter}, query::With, removal_detection::RemovedComponents, schedule::{IntoSystemConfigs, ScheduleLabel}, @@ -1280,35 +1280,37 @@ mod tests { #[derive(Event, Clone)] struct TestEvent; + println!("Starting test"); + let mut app = App::new(); app.add_event::(); // Starts empty - let test_events = app.world().resource::>(); - assert_eq!(test_events.len(), 0); - assert_eq!(test_events.iter_current_update_events().count(), 0); + //let test_events = app.world().resource::>(); + //assert_eq!(test_events.len(), 0); + //assert_eq!(test_events.iter_current_update_events().count(), 0); app.update(); // Sending one event app.world_mut().send_event(TestEvent); - let test_events = app.world().resource::>(); - assert_eq!(test_events.len(), 1); - assert_eq!(test_events.iter_current_update_events().count(), 1); + //let test_events = app.world().resource::>(); + //assert_eq!(test_events.len(), 1); + //assert_eq!(test_events.iter_current_update_events().count(), 1); app.update(); // Sending two events on the next frame app.world_mut().send_event(TestEvent); app.world_mut().send_event(TestEvent); - let test_events = app.world().resource::>(); - assert_eq!(test_events.len(), 3); // Events are double-buffered, so we see 1 + 2 = 3 - assert_eq!(test_events.iter_current_update_events().count(), 2); + //let test_events = app.world().resource::>(); + //assert_eq!(test_events.len(), 3); // Events are double-buffered, so we see 1 + 2 = 3 + //assert_eq!(test_events.iter_current_update_events().count(), 2); app.update(); // Sending zero events - let test_events = app.world().resource::>(); - assert_eq!(test_events.len(), 2); // Events are double-buffered, so we see 2 + 0 = 2 - assert_eq!(test_events.iter_current_update_events().count(), 0); + //let test_events = app.world().resource::>(); + //assert_eq!(test_events.len(), 2); // Events are double-buffered, so we see 2 + 0 = 2 + //assert_eq!(test_events.iter_current_update_events().count(), 0); } } diff --git a/crates/bevy_app/src/sub_app.rs b/crates/bevy_app/src/sub_app.rs index 59ad4eca8b105..e60029323e165 100644 --- a/crates/bevy_app/src/sub_app.rs +++ b/crates/bevy_app/src/sub_app.rs @@ -307,6 +307,7 @@ impl SubApp { { if !self.world.contains_resource::>() { EventRegistry::register_event::(self.world_mut()); + println!("Registered event: {:?}", std::any::type_name::()); } self diff --git a/crates/bevy_ecs/src/event/collections.rs b/crates/bevy_ecs/src/event/collections.rs index 79f7b85668096..37e4f5c295d42 100644 --- a/crates/bevy_ecs/src/event/collections.rs +++ b/crates/bevy_ecs/src/event/collections.rs @@ -172,6 +172,8 @@ impl Events { /// /// If you need access to the events that were removed, consider using [`Events::update_drain`]. pub fn update(&mut self) { + println!("Updating events!"); + std::mem::swap(&mut self.events_a, &mut self.events_b); self.events_b.clear(); self.events_b.start_event_count = self.event_count; diff --git a/crates/bevy_ecs/src/event/registry.rs b/crates/bevy_ecs/src/event/registry.rs index 06587ddc35aa7..472e3080664d4 100644 --- a/crates/bevy_ecs/src/event/registry.rs +++ b/crates/bevy_ecs/src/event/registry.rs @@ -8,6 +8,7 @@ use bevy_ecs::{ }; #[doc(hidden)] +#[derive(Debug)] struct RegisteredEvent { component_id: ComponentId, // Required to flush the secondary buffer and drop events even if left unchanged. @@ -19,7 +20,7 @@ struct RegisteredEvent { /// A registry of all of the [`Events`] in the [`World`], used by [`event_update_system`] /// to update all of the events. -#[derive(Resource, Default)] +#[derive(Resource, Default, Debug)] pub struct EventRegistry { pub(super) needs_update: bool, event_updates: Vec, @@ -46,7 +47,11 @@ impl EventRegistry { /// Updates all of the registered events in the World. pub fn run_updates(&mut self, world: &mut World, last_change_tick: Tick) { + println!("Running event updates"); + for registered_event in &mut self.event_updates { + println!("Checking if we should update an event"); + // Bypass the type ID -> Component ID lookup with the cached component ID. if let Some(events) = world.get_resource_mut_by_id(registered_event.component_id) { let has_changed = events.has_changed_since(last_change_tick); diff --git a/crates/bevy_ecs/src/event/update.rs b/crates/bevy_ecs/src/event/update.rs index aa2d62bedc46b..ca3beb5a9b7f1 100644 --- a/crates/bevy_ecs/src/event/update.rs +++ b/crates/bevy_ecs/src/event/update.rs @@ -23,6 +23,7 @@ pub fn signal_event_update_system(signal: Option>) { /// A system that calls [`Events::update`] on all registered [`Events`] in the world. pub fn event_update_system(world: &mut World, mut last_change_tick: Local) { + println!("Running event_update_system"); if world.contains_resource::() { world.resource_scope(|world, mut registry: Mut| { registry.run_updates(world, *last_change_tick); @@ -35,6 +36,10 @@ pub fn event_update_system(world: &mut World, mut last_change_tick: Local) /// A run condition for [`event_update_system`]. pub fn event_update_condition(signal: Option>) -> bool { + println!("Checking if we should run event_update_system"); + + println!("signal: {:?}", signal); + // If we haven't got a signal to update the events, but we *could* get such a signal // return early and update the events later. signal.map_or(false, |signal| signal.needs_update)