This commit is contained in:
Quaternions 2025-01-15 21:41:44 -08:00
parent 7f9a16a56d
commit 035736e7af
2 changed files with 24 additions and 4 deletions

View File

@ -1,6 +1,6 @@
use crate::integer::Time; use crate::integer::Time;
#[derive(Debug)] #[derive(Clone,Debug)]
pub struct TimedInstruction<I,T>{ pub struct TimedInstruction<I,T>{
pub time:Time<T>, pub time:Time<T>,
pub instruction:I, pub instruction:I,

View File

@ -64,19 +64,28 @@ impl Simulation{
} }
} }
#[derive(Default)]
pub struct Recording{
instructions:Vec<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>,
}
impl Recording{
fn clear(&mut self){
self.instructions.clear();
}
}
pub struct Replay{ pub struct Replay{
last_instruction_id:usize, last_instruction_id:usize,
instructions:Vec<PhysicsInputInstruction>, recording:Recording,
simulation:Simulation, simulation:Simulation,
} }
impl Replay{ impl Replay{
pub const fn new( pub const fn new(
instructions:Vec<PhysicsInputInstruction>, recording:Recording,
simulation:Simulation, simulation:Simulation,
)->Self{ )->Self{
Self{ Self{
last_instruction_id:0, last_instruction_id:0,
instructions, recording,
simulation, simulation,
} }
} }
@ -87,6 +96,8 @@ pub struct Session{
mouse_interpolator:crate::mouse_interpolator::MouseInterpolator, mouse_interpolator:crate::mouse_interpolator::MouseInterpolator,
//gui:GuiState //gui:GuiState
simulation:Simulation, simulation:Simulation,
// below fields not included in lite session
recording:Recording,
replays:Vec<Replay>, replays:Vec<Replay>,
} }
impl Session{ impl Session{
@ -98,9 +109,13 @@ impl Session{
user_settings, user_settings,
mouse_interpolator:MouseInterpolator::new(), mouse_interpolator:MouseInterpolator::new(),
simulation, simulation,
recording:Default::default(),
replays:Vec::new(), replays:Vec::new(),
} }
} }
fn clear_recording(&mut self){
self.recording.clear();
}
fn change_map(&mut self,map:&strafesnet_common::map::CompleteMap){ fn change_map(&mut self,map:&strafesnet_common::map::CompleteMap){
self.simulation.physics.generate_models(map); self.simulation.physics.generate_models(map);
} }
@ -147,11 +162,13 @@ impl InstructionConsumer<Instruction<'_>> for Session{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::SetControl(set_control_instruction)); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::SetControl(set_control_instruction));
}, },
Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndRestart))=>{ Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndRestart))=>{
self.clear_recording();
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset)); 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::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity())));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Restart)); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Restart));
}, },
Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndSpawn(mode_id,spawn_id)))=>{ 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::Mode(ModeInstruction::Reset));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))); 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))); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Spawn(mode_id,spawn_id)));
@ -166,6 +183,7 @@ impl InstructionConsumer<Instruction<'_>> for Session{
_=self.simulation.timer.set_paused(ins.time,paused); _=self.simulation.timer.set_paused(ins.time,paused);
} }
Instruction::ChangeMap(complete_map)=>{ Instruction::ChangeMap(complete_map)=>{
self.clear_recording();
self.change_map(complete_map); self.change_map(complete_map);
// ResetAndSpawn // ResetAndSpawn
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset)); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Mode(ModeInstruction::Reset));
@ -183,6 +201,8 @@ impl InstructionConsumer<StepInstruction> for Session{
fn process_instruction(&mut self,ins:TimedInstruction<StepInstruction,Self::TimeInner>){ fn process_instruction(&mut self,ins:TimedInstruction<StepInstruction,Self::TimeInner>){
let time=self.simulation.timer.time(ins.time); let time=self.simulation.timer.time(ins.time);
if let Some(instruction)=self.mouse_interpolator.pop_buffered_instruction(ins.set_time(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); self.simulation.physics.run_input_instruction(instruction);
} }
} }