diff --git a/src/config.rs b/src/config.rs index f7a6953cd5..c4f4b1ba6a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,6 +21,13 @@ pub struct EngineConfig { #[arg(short = 'R', long)] pub hot_reload: bool, + /// Sets the sync test distance during local play. + /// + /// This is useful for developers for testing game rollback determinism without having to start + /// a network game. + #[arg(short = 'C', long, default_value = "0")] + pub sync_test_check_distance: usize, + /// The directory to load assets from #[arg(short, long, env = ASSET_DIR_ENV_VAR)] pub asset_dir: Option, diff --git a/src/session.rs b/src/session.rs index e3016ada88..8907020f13 100644 --- a/src/session.rs +++ b/src/session.rs @@ -11,6 +11,7 @@ use bevy_ggrs::{ use jumpy_matchmaker_proto::TargetClient; use crate::{ + config::ENGINE_CONFIG, networking::{client::NetClient, proto::ClientMatchInfo}, player, prelude::*, @@ -103,9 +104,7 @@ impl<'w, 's> SessionManager<'w, 's> { builder = builder .with_input_delay(INPUT_DELAY) .with_num_players(player::MAX_PLAYERS) - // TODO: Add some flag to enable the non-zero check distance, instead of wasting - // processing power for local games. - .with_check_distance(7); + .with_check_distance(ENGINE_CONFIG.sync_test_check_distance); for i in 0..player::MAX_PLAYERS { builder = builder.add_player(ggrs::PlayerType::Local, i).unwrap(); diff --git a/src/ui/editor.rs b/src/ui/editor.rs index 6efb20c192..82cdfe7e88 100644 --- a/src/ui/editor.rs +++ b/src/ui/editor.rs @@ -13,6 +13,7 @@ use crate::{ metadata::{GameMeta, MapLayerKind, MapLayerMeta, MapMeta}, player::input::PlayerInputs, prelude::*, + session::SessionManager, utils::ResetManager, }; @@ -154,6 +155,7 @@ struct EditorTopBar<'w, 's> { map_meta: Query<'w, 's, &'static MapMeta>, map_handle: Query<'w, 's, &'static AssetHandle>, settings: ResMut<'w, EditorState>, + session_manager: SessionManager<'w, 's>, } impl<'w, 's> WidgetSystem for EditorTopBar<'w, 's> { @@ -248,6 +250,7 @@ impl<'w, 's> WidgetSystem for EditorTopBar<'w, 's> { .spawn() .insert(handle) .insert(Rollback::new(params.rids.next_id())); + params.session_manager.start_session(); } } }); @@ -668,6 +671,7 @@ struct EditorCentralPanel<'w, 's> { With, >, localization: Res<'w, Localization>, + session_manager: SessionManager<'w, 's>, } struct MapCreateInfo { @@ -827,6 +831,7 @@ fn map_open_dialog(ui: &mut egui::Ui, params: &mut EditorCentralPanel) { ) { if ui.button(&map_name).clicked() { params.commands.spawn().insert(map_handle); + params.session_manager.start_session(); *params.show_map_open = false; } }