From f92b550eed96ce6cbf29796effcc736520334cf2 Mon Sep 17 00:00:00 2001 From: PraxTube Date: Wed, 27 Sep 2023 09:25:14 +0200 Subject: [PATCH 1/2] feat: Add input in examples to trigger a desync --- examples/README.md | 1 + examples/ex_game/ex_game.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index aaf8289..87f0197 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,6 +11,7 @@ There is no real game, just movement with ice physics. Optionally, you can speci - S to accelerate backwards - A to turn left - D to turn right +- SPACE to move player 1 to (0, 0) locally (this will create a desync) ### Important Disclaimer - Determinism diff --git a/examples/ex_game/ex_game.rs b/examples/ex_game/ex_game.rs index af0f5a9..cbcf500 100644 --- a/examples/ex_game/ex_game.rs +++ b/examples/ex_game/ex_game.rs @@ -161,7 +161,8 @@ impl Game { #[allow(dead_code)] // creates a compact representation of currently pressed keys and serializes it - pub fn local_input(&self, handle: PlayerHandle) -> Input { + pub fn local_input(&mut self, handle: PlayerHandle) -> Input { + self.trigger_desync(); let mut inp: u8 = 0; if handle == self.local_handles[0] { @@ -197,6 +198,14 @@ impl Game { Input { inp } } + // move player one to origin on local session only + // this will create a forced desync (unless player one is already at the origin) + pub fn trigger_desync(&mut self) { + if is_key_pressed(KeyCode::Space) { + self.game_state.positions[0] = (0.0, 0.0); + } + } + #[allow(dead_code)] pub const fn current_frame(&self) -> i32 { self.game_state.frame From b2f9d9a7df2ff8b1509407d2932c540a4b1080b8 Mon Sep 17 00:00:00 2001 From: PraxTube Date: Fri, 20 Oct 2023 10:42:37 +0200 Subject: [PATCH 2/2] fix: Add info text for causing desync --- examples/ex_game/ex_game.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/ex_game/ex_game.rs b/examples/ex_game/ex_game.rs index cbcf500..4aa1b29 100644 --- a/examples/ex_game/ex_game.rs +++ b/examples/ex_game/ex_game.rs @@ -150,8 +150,16 @@ impl Game { "Frame {}: Checksum {}", self.periodic_checksum.0, self.periodic_checksum.1 ); + let force_desync_info_str = format!("Press SPACE to trigger a desync"); draw_text(&last_checksum_str, 20.0, 20.0, 30.0, WHITE); draw_text(&periodic_checksum_str, 20.0, 40.0, 30.0, WHITE); + draw_text( + &force_desync_info_str, + 90.0, + WINDOW_HEIGHT * 9.0 / 10.0, + 30.0, + WHITE, + ); } #[allow(dead_code)]