From 035736e7af3ac2035ed83f3cbf9dc7162f57016f Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 15 Jan 2025 21:41:44 -0800 Subject: [PATCH] record --- lib/common/src/instruction.rs | 2 +- strafe-client/src/session.rs | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/common/src/instruction.rs b/lib/common/src/instruction.rs index 867ab7f..d39b899 100644 --- a/lib/common/src/instruction.rs +++ b/lib/common/src/instruction.rs @@ -1,6 +1,6 @@ use crate::integer::Time; -#[derive(Debug)] +#[derive(Clone,Debug)] pub struct TimedInstruction{ pub time:Time, pub instruction:I, diff --git a/strafe-client/src/session.rs b/strafe-client/src/session.rs index 6bd782c..1a913d5 100644 --- a/strafe-client/src/session.rs +++ b/strafe-client/src/session.rs @@ -64,19 +64,28 @@ impl Simulation{ } } +#[derive(Default)] +pub struct Recording{ + instructions:Vec>, +} +impl Recording{ + fn clear(&mut self){ + self.instructions.clear(); + } +} pub struct Replay{ last_instruction_id:usize, - instructions:Vec, + recording:Recording, simulation:Simulation, } impl Replay{ pub const fn new( - instructions:Vec, + recording:Recording, simulation:Simulation, )->Self{ Self{ last_instruction_id:0, - instructions, + recording, simulation, } } @@ -87,6 +96,8 @@ pub struct Session{ mouse_interpolator:crate::mouse_interpolator::MouseInterpolator, //gui:GuiState simulation:Simulation, + // below fields not included in lite session + recording:Recording, replays:Vec, } impl Session{ @@ -98,9 +109,13 @@ impl Session{ user_settings, mouse_interpolator:MouseInterpolator::new(), simulation, + recording:Default::default(), replays:Vec::new(), } } + fn clear_recording(&mut self){ + self.recording.clear(); + } fn change_map(&mut self,map:&strafesnet_common::map::CompleteMap){ self.simulation.physics.generate_models(map); } @@ -147,11 +162,13 @@ impl InstructionConsumer> for Session{ run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::SetControl(set_control_instruction)); }, Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndRestart))=>{ + self.clear_recording(); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset)); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Restart)); }, Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndSpawn(mode_id,spawn_id)))=>{ + self.clear_recording(); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset)); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Spawn(mode_id,spawn_id))); @@ -166,6 +183,7 @@ impl InstructionConsumer> for Session{ _=self.simulation.timer.set_paused(ins.time,paused); } Instruction::ChangeMap(complete_map)=>{ + self.clear_recording(); self.change_map(complete_map); // ResetAndSpawn run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset)); @@ -183,6 +201,8 @@ impl InstructionConsumer for Session{ fn process_instruction(&mut self,ins:TimedInstruction){ let time=self.simulation.timer.time(ins.time); if let Some(instruction)=self.mouse_interpolator.pop_buffered_instruction(ins.set_time(time)){ + //record + self.recording.instructions.push(instruction.clone()); self.simulation.physics.run_input_instruction(instruction); } }