Fix egui session panel sync with engine state
The session UI panel was not updating when networking started via control socket because poll_engine_events used commands.insert_resource which queued updates until end of schedule. The UI could run before the command was applied. Fixed by: - Initialize CurrentSession at startup in offline state (session.rs) - Use direct ResMut mutation in poll_engine_events (engine_bridge.rs) - Check session.state instead of resource existence (session_ui.rs) This ensures Bevy's change detection triggers immediately when engine events update the session state. Refs #131, #132 Signed-off-by: Sienna Meridian Satterwhite <sienna@r3t.io>
This commit is contained in:
@@ -6,17 +6,17 @@
|
||||
use bevy::prelude::*;
|
||||
use libmarathon::{
|
||||
networking::{
|
||||
EntityLockRegistry, NetworkEntityMap, NodeVectorClock, VectorClock,
|
||||
CurrentSession, EntityLockRegistry, NetworkEntityMap, NodeVectorClock, Session, VectorClock,
|
||||
},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Initialize offline resources on app startup
|
||||
///
|
||||
/// This sets up the vector clock and networking-related resources, but does NOT
|
||||
/// create a session. Sessions only exist when networking is active.
|
||||
/// This sets up the vector clock and networking-related resources.
|
||||
/// Creates an offline CurrentSession that will be updated when networking starts.
|
||||
pub fn initialize_offline_resources(world: &mut World) {
|
||||
info!("Initializing offline resources (no session yet)...");
|
||||
info!("Initializing offline resources...");
|
||||
|
||||
// Create node ID (persists for this app instance)
|
||||
let node_id = Uuid::new_v4();
|
||||
@@ -32,5 +32,11 @@ pub fn initialize_offline_resources(world: &mut World) {
|
||||
world.insert_resource(NetworkEntityMap::default());
|
||||
world.insert_resource(EntityLockRegistry::default());
|
||||
|
||||
info!("Offline resources initialized (vector clock ready)");
|
||||
// Create offline session (will be updated when networking starts)
|
||||
// This ensures CurrentSession resource always exists for UI binding
|
||||
let offline_session_id = libmarathon::networking::SessionId::new();
|
||||
let offline_session = Session::new(offline_session_id);
|
||||
world.insert_resource(CurrentSession::new(offline_session, VectorClock::new()));
|
||||
|
||||
info!("Offline resources initialized (vector clock ready, session created in offline state)");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user