// Simulation module - Core simulation plugin and systems // Implements deterministic tick-based simulation (D-010 principle 4) use bevy_app::prelude::*; use bevy_ecs::schedule::IntoScheduleConfigs; pub mod chunk_streaming; // Phase sub-plugins (#843) pub mod contraband; pub mod dialogue; pub mod economy; pub mod economy_plugin; pub mod examine; pub mod follow; pub mod generator; pub mod input; pub mod input_plugin; pub mod interaction; pub mod inventory; pub mod knowledge_grant; pub mod line_pool; pub mod listening; pub mod modification; pub mod monologue; pub mod movement; pub mod movement_plugin; pub mod npc_components; pub mod npc_knowledge_transfer; pub mod path_follow; pub mod pathfinding; pub mod poi; pub mod poi_discovery; pub mod pressure; pub mod rng; pub mod save_io; pub mod save_state; pub mod social_plugin; pub mod sound; pub mod spatial; pub mod stance; pub mod ticker; pub mod tier; pub mod time; pub mod time_plugin; pub mod triangle; pub mod zone; /// Core simulation plugin — shell that delegates to phase sub-plugins (#843). /// /// Each sub-plugin owns its domain's systems, resources, and phase assignment. /// No system registration happens here — only sub-plugin composition and /// shared resources needed by multiple sub-plugins. /// /// `seed` is threaded through to [`economy_plugin::EconomyPlugin`] so the /// economy simulation uses the world seed from `StartupMessage` (#826). pub struct SimulationPlugin { pub seed: u64, } impl Plugin for SimulationPlugin { fn build(&self, app: &mut App) { // Tier marker components (D-026) — must register before behavior systems app.add_plugins(tier::TierPlugin); // Shared resources needed by multiple sub-plugins. // Each sub-plugin inits its own domain-specific resources. app.insert_resource(rng::SimRng::new(self.seed)) .init_resource::() .init_resource::() // Triangle escalation event queue (#250) — consumed by storyteller + npc plugins .init_resource::() // Cross-plugin resource safety: init resources that may be read by other plugins // before those plugins register. Prevents "resource not found" in standalone tests. .init_resource::() .init_resource::() .init_resource::(); // Background worker pools (#843 Part C) — off-tick computation on separate cores. // Stub handlers for now; real implementations plug in at Phase 5+. app.insert_resource(crate::workers::stubs::ChunkGenWorker::new(2)); app.insert_resource(crate::workers::stubs::NpcPrepWorker::new(1)); app.insert_resource(crate::workers::stubs::OffscreenTickWorker::new(1)); // Phase sub-plugins (#843) — each owns its domain app.add_plugins(time_plugin::TimePlugin); app.add_plugins(input_plugin::InputPlugin); app.add_plugins(movement_plugin::MovementPlugin); app.add_plugins(social_plugin::SocialPlugin); app.add_plugins(economy_plugin::EconomyPlugin { seed: self.seed }); // Background worker tick integration (#843 Part C) app.add_systems( Update, crate::workers::systems::poll_worker_results .in_set(crate::tick_phases::TickPhase::PreInput), ); app.add_systems( Update, crate::workers::systems::push_worker_requests .in_set(crate::tick_phases::TickPhase::PostSnapshot), ); // save_load is an exclusive system (takes &mut World). // Exclusive systems in Bevy 0.18 cannot use .in_set() — use .before()/.after() // to position it within the Snapshot phase window. app.add_systems( Update, save_io::execute_save_load .before(crate::perception::observer::compute_observer_snapshot), ); tracing::debug!("SimulationPlugin initialized"); } }