2025-12-13 22:22:05 +00:00
|
|
|
//! App-level offline resource management
|
|
|
|
|
//!
|
|
|
|
|
//! Sets up vector clock and networking resources. Sessions are created later
|
|
|
|
|
//! when the user starts networking.
|
|
|
|
|
|
|
|
|
|
use bevy::prelude::*;
|
|
|
|
|
use libmarathon::{
|
|
|
|
|
networking::{
|
2025-12-24 11:32:30 +00:00
|
|
|
CurrentSession, EntityLockRegistry, NetworkEntityMap, NodeVectorClock, Session, VectorClock,
|
2025-12-13 22:22:05 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
/// Initialize offline resources on app startup
|
|
|
|
|
///
|
2025-12-24 11:32:30 +00:00
|
|
|
/// This sets up the vector clock and networking-related resources.
|
|
|
|
|
/// Creates an offline CurrentSession that will be updated when networking starts.
|
2025-12-13 22:22:05 +00:00
|
|
|
pub fn initialize_offline_resources(world: &mut World) {
|
2025-12-24 11:32:30 +00:00
|
|
|
info!("Initializing offline resources...");
|
2025-12-13 22:22:05 +00:00
|
|
|
|
|
|
|
|
// Create node ID (persists for this app instance)
|
|
|
|
|
let node_id = Uuid::new_v4();
|
|
|
|
|
info!("Node ID: {}", node_id);
|
|
|
|
|
|
|
|
|
|
// Insert vector clock resource (always available, offline or online)
|
|
|
|
|
world.insert_resource(NodeVectorClock {
|
|
|
|
|
node_id,
|
|
|
|
|
clock: VectorClock::new(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Insert networking resources (available from startup, even before networking starts)
|
|
|
|
|
world.insert_resource(NetworkEntityMap::default());
|
|
|
|
|
world.insert_resource(EntityLockRegistry::default());
|
|
|
|
|
|
2025-12-24 11:32:30 +00:00
|
|
|
// 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)");
|
2025-12-13 22:22:05 +00:00
|
|
|
}
|