From f67843cc590675821873488eca3d43f3585d2110 Mon Sep 17 00:00:00 2001 From: Sofia Date: Sun, 26 Jul 2026 19:50:37 +0300 Subject: [PATCH] Clear replay players when replay ends --- rust/src/game_manager.rs | 2 +- rust/src/player/local_player.rs | 2 +- rust/src/replay.rs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index 67f4917..d26ff0d 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -346,7 +346,7 @@ impl Game { .map(|g| g.cast::()) } - pub fn start_playback(&mut self, time_delta: f64) { + pub fn start_playback(&mut self, time_delta: f64, spectated_id: u16) { if let Some(recorder) = &self.replay_recorder { let mut playback = ReplayPlayback::new_alloc(); playback.bind_mut().replay = recorder.bind().replay.clone(); diff --git a/rust/src/player/local_player.rs b/rust/src/player/local_player.rs index 611e741..ffacd83 100644 --- a/rust/src/player/local_player.rs +++ b/rust/src/player/local_player.rs @@ -364,7 +364,7 @@ impl ICharacterBody3D for LocalPlayer { camera.set_current(true); } - game.start_playback(-5.); + game.start_playback(-5., killer_id); } } } diff --git a/rust/src/replay.rs b/rust/src/replay.rs index 90f23af..09c14c0 100644 --- a/rust/src/replay.rs +++ b/rust/src/replay.rs @@ -21,6 +21,8 @@ pub struct ReplayPlayback { pub current_time: f64, + pub spectated_player_id: u16, + base: Base, } @@ -28,6 +30,16 @@ pub struct ReplayPlayback { impl INode for ReplayPlayback { fn ready(&mut self) {} + fn process(&mut self, _: f64) { + if let Some(character) = self.player_characters.get_mut(&self.spectated_player_id) { + if let Some(camera) = &mut character.bind_mut().spectator_camera { + if !camera.is_current() { + camera.make_current(); + } + } + } + } + fn physics_process(&mut self, delta: f64) { self.current_time += delta; @@ -77,6 +89,13 @@ impl INode for ReplayPlayback { } self.current_frame_idx += 1; } + + if self.current_frame_idx >= self.replay.frames.len() { + for (id, mut character) in self.player_characters.clone() { + character.queue_free(); + self.player_characters.remove(&id); + } + } } fn exit_tree(&mut self) {