session instruction changes for control and playback

This commit is contained in:
Quaternions 2025-01-15 22:59:59 -08:00
parent 035736e7af
commit 15a9136fc4
3 changed files with 101 additions and 26 deletions

View File

@ -1,13 +1,17 @@
use crate::graphics_worker::Instruction as GraphicsInstruction; use crate::graphics_worker::Instruction as GraphicsInstruction;
use crate::session::{SessionInputInstruction,Instruction as SessionInstruction,Session,Simulation}; use crate::session::{
Session,Simulation,SessionInputInstruction,SessionControlInstruction,SessionPlaybackInstruction,
Instruction as SessionInstruction,
};
use strafesnet_common::instruction::{TimedInstruction,InstructionConsumer}; use strafesnet_common::instruction::{TimedInstruction,InstructionConsumer};
use strafesnet_common::physics::Time as PhysicsTime; use strafesnet_common::physics::Time as PhysicsTime;
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner}; use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
use strafesnet_common::timer::Timer; use strafesnet_common::timer::Timer;
pub enum Instruction{ pub enum Instruction{
Input(SessionInputInstruction), SessionInput(SessionInputInstruction),
SetPaused(bool), SessionControl(SessionControlInstruction),
SessionPlayback(SessionPlaybackInstruction),
Render, Render,
Resize(winit::dpi::PhysicalSize<u32>), Resize(winit::dpi::PhysicalSize<u32>),
ChangeMap(strafesnet_common::map::CompleteMap), ChangeMap(strafesnet_common::map::CompleteMap),
@ -42,11 +46,14 @@ pub fn new<'a>(
}; };
} }
match ins.instruction{ match ins.instruction{
Instruction::Input(unbuffered_instruction)=>{ Instruction::SessionInput(unbuffered_instruction)=>{
run_session_instruction!(ins.time,SessionInstruction::Input(unbuffered_instruction)); run_session_instruction!(ins.time,SessionInstruction::Input(unbuffered_instruction));
}, },
Instruction::SetPaused(paused)=>{ Instruction::SessionControl(unbuffered_instruction)=>{
run_session_instruction!(ins.time,SessionInstruction::SetPaused(paused)); run_session_instruction!(ins.time,SessionInstruction::Control(unbuffered_instruction));
},
Instruction::SessionPlayback(unbuffered_instruction)=>{
run_session_instruction!(ins.time,SessionInstruction::Playback(unbuffered_instruction));
}, },
Instruction::Render=>{ Instruction::Render=>{
run_session_instruction!(ins.time,SESSION_INSTRUCTION_IDLE); run_session_instruction!(ins.time,SESSION_INSTRUCTION_IDLE);

View File

@ -16,9 +16,9 @@ use crate::settings::UserSettings;
pub enum Instruction<'a>{ pub enum Instruction<'a>{
Input(SessionInputInstruction), Input(SessionInputInstruction),
SetPaused(bool), Control(SessionControlInstruction),
Playback(SessionPlaybackInstruction),
ChangeMap(&'a strafesnet_common::map::CompleteMap), ChangeMap(&'a strafesnet_common::map::CompleteMap),
//Graphics(crate::graphics_worker::Instruction),
} }
pub enum SessionInputInstruction{ pub enum SessionInputInstruction{
@ -35,6 +35,20 @@ pub enum ImplicitModeInstruction{
ResetAndSpawn(strafesnet_common::gameplay_modes::ModeId,strafesnet_common::gameplay_modes::StageId), ResetAndSpawn(strafesnet_common::gameplay_modes::ModeId,strafesnet_common::gameplay_modes::StageId),
} }
pub enum SessionControlInstruction{
SetPaused(bool),
// copy the current session simulation recording into a replay and view it
CopyRecordingIntoReplayAndSpectate,
StopSpectate,
}
pub enum SessionPlaybackInstruction{
SkipForward,
SkipBack,
TogglePaused,
DecreaseTimescale,
IncreaseTimescale,
}
pub struct FrameState{ pub struct FrameState{
pub body:crate::physics::Body, pub body:crate::physics::Body,
pub camera:crate::physics::PhysicsCamera, pub camera:crate::physics::PhysicsCamera,
@ -176,12 +190,21 @@ impl InstructionConsumer<Instruction<'_>> for Session{
Instruction::Input(SessionInputInstruction::Misc(other_other_instruction))=>{ Instruction::Input(SessionInputInstruction::Misc(other_other_instruction))=>{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(other_other_instruction)); run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Misc(other_other_instruction));
}, },
Instruction::SetPaused(paused)=>{ Instruction::Control(SessionControlInstruction::SetPaused(paused))=>{
// don't flush the buffered instructions in the mouse interpolator // don't flush the buffered instructions in the mouse interpolator
// until the mouse is confirmed to be not moving at a later time // until the mouse is confirmed to be not moving at a later time
// what if they pause for 5ms lmao // what if they pause for 5ms lmao
_=self.simulation.timer.set_paused(ins.time,paused); _=self.simulation.timer.set_paused(ins.time,paused);
} },
Instruction::Control(SessionControlInstruction::CopyRecordingIntoReplayAndSpectate)=>{
todo!();
},
Instruction::Control(SessionControlInstruction::StopSpectate)=>{
todo!();
},
Instruction::Playback(_)=>{
todo!();
},
Instruction::ChangeMap(complete_map)=>{ Instruction::ChangeMap(complete_map)=>{
self.clear_recording(); self.clear_recording();
self.change_map(complete_map); self.change_map(complete_map);

View File

@ -2,7 +2,7 @@ use strafesnet_common::instruction::TimedInstruction;
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner}; use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
use strafesnet_common::physics::{MiscInstruction,SetControlInstruction}; use strafesnet_common::physics::{MiscInstruction,SetControlInstruction};
use crate::physics_worker::Instruction as PhysicsWorkerInstruction; use crate::physics_worker::Instruction as PhysicsWorkerInstruction;
use crate::session::SessionInputInstruction; use crate::session::{SessionInputInstruction,SessionControlInstruction,SessionPlaybackInstruction};
pub enum Instruction{ pub enum Instruction{
Resize(winit::dpi::PhysicalSize<u32>), Resize(winit::dpi::PhysicalSize<u32>),
@ -37,7 +37,7 @@ impl WindowContext<'_>{
//pause unpause //pause unpause
self.physics_thread.send(TimedInstruction{ self.physics_thread.send(TimedInstruction{
time, time,
instruction:PhysicsWorkerInstruction::SetPaused(!state), instruction:PhysicsWorkerInstruction::SessionControl(SessionControlInstruction::SetPaused(!state)),
}).unwrap(); }).unwrap();
//recalculate pressed keys on focus //recalculate pressed keys on focus
}, },
@ -92,29 +92,74 @@ impl WindowContext<'_>{
}, },
(keycode,state)=>{ (keycode,state)=>{
let s=state.is_pressed(); let s=state.is_pressed();
if let Some(session_input_instruction)=match keycode{
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Space)=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetJump(s))), // internal variants for this scope
enum SessionInstructionSubset{
Input(SessionInputInstruction),
Control(SessionControlInstruction),
Playback(SessionPlaybackInstruction),
}
macro_rules! input_ctrl{
($variant:ident,$state:expr)=>{
Some(SessionInstructionSubset::Input(SessionInputInstruction::SetControl(SetControlInstruction::$variant($state))))
};
}
macro_rules! input_misc{
($variant:ident,$state:expr)=>{
s.then_some(SessionInstructionSubset::Input(SessionInputInstruction::Misc(MiscInstruction::$variant)))
};
}
macro_rules! session_ctrl{
($variant:ident,$state:expr)=>{
s.then_some(SessionInstructionSubset::Control(SessionControlInstruction::$variant))
};
}
macro_rules! session_playback{
($variant:ident,$state:expr)=>{
s.then_some(SessionInstructionSubset::Playback(SessionPlaybackInstruction::$variant))
};
}
impl From<SessionInstructionSubset> for PhysicsWorkerInstruction{
fn from(value:SessionInstructionSubset)->Self{
match value{
SessionInstructionSubset::Input(session_input_instruction)=>PhysicsWorkerInstruction::SessionInput(session_input_instruction),
SessionInstructionSubset::Control(session_control_instruction)=>PhysicsWorkerInstruction::SessionControl(session_control_instruction),
SessionInstructionSubset::Playback(session_playback_instruction)=>PhysicsWorkerInstruction::SessionPlayback(session_playback_instruction),
}
}
}
if let Some(session_instruction)=match keycode{
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Space)=>input_ctrl!(SetJump,s),
// TODO: bind system so playback pausing can use spacebar
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter)=>session_playback!(TogglePaused,s),
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowUp)=>session_playback!(IncreaseTimescale,s),
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowDown)=>session_playback!(DecreaseTimescale,s),
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowLeft)=>session_playback!(SkipBack,s),
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowRight)=>session_playback!(SkipForward,s),
winit::keyboard::Key::Character(key)=>match key.as_str(){ winit::keyboard::Key::Character(key)=>match key.as_str(){
"W"|"w"=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetMoveForward(s))), "W"|"w"=>input_ctrl!(SetMoveForward,s),
"A"|"a"=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetMoveLeft(s))), "A"|"a"=>input_ctrl!(SetMoveLeft,s),
"S"|"s"=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetMoveBack(s))), "S"|"s"=>input_ctrl!(SetMoveBack,s),
"D"|"d"=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetMoveRight(s))), "D"|"d"=>input_ctrl!(SetMoveRight,s),
"E"|"e"=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetMoveUp(s))), "E"|"e"=>input_ctrl!(SetMoveUp,s),
"Q"|"q"=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetMoveDown(s))), "Q"|"q"=>input_ctrl!(SetMoveDown,s),
"Z"|"z"=>Some(SessionInputInstruction::SetControl(SetControlInstruction::SetZoom(s))), "Z"|"z"=>input_ctrl!(SetZoom,s),
"R"|"r"=>s.then(||{ "R"|"r"=>s.then(||{
//mouse needs to be reset since the position is absolute //mouse needs to be reset since the position is absolute
self.mouse_pos=glam::DVec2::ZERO; self.mouse_pos=glam::DVec2::ZERO;
SessionInputInstruction::Mode(crate::session::ImplicitModeInstruction::ResetAndRestart) SessionInstructionSubset::Input(SessionInputInstruction::Mode(crate::session::ImplicitModeInstruction::ResetAndRestart))
}), }),
"F"|"f"=>s.then_some(SessionInputInstruction::Misc(MiscInstruction::PracticeFly)), "F"|"f"=>input_misc!(PracticeFly,s),
"B"|"b"=>session_ctrl!(CopyRecordingIntoReplayAndSpectate,s),
"X"|"x"=>session_ctrl!(StopSpectate,s),
_=>None, _=>None,
}, },
_=>None, _=>None,
}{ }{
self.physics_thread.send(TimedInstruction{ self.physics_thread.send(TimedInstruction{
time, time,
instruction:PhysicsWorkerInstruction::Input(session_input_instruction), instruction:session_instruction.into(),
}).unwrap(); }).unwrap();
} }
}, },
@ -138,7 +183,7 @@ impl WindowContext<'_>{
self.mouse_pos+=glam::dvec2(delta.0,delta.1); self.mouse_pos+=glam::dvec2(delta.0,delta.1);
self.physics_thread.send(TimedInstruction{ self.physics_thread.send(TimedInstruction{
time, time,
instruction:PhysicsWorkerInstruction::Input(SessionInputInstruction::Mouse(self.mouse_pos.as_ivec2())), instruction:PhysicsWorkerInstruction::SessionInput(SessionInputInstruction::Mouse(self.mouse_pos.as_ivec2())),
}).unwrap(); }).unwrap();
}, },
winit::event::DeviceEvent::MouseWheel { winit::event::DeviceEvent::MouseWheel {
@ -148,7 +193,7 @@ impl WindowContext<'_>{
if false{//self.physics.style.use_scroll{ if false{//self.physics.style.use_scroll{
self.physics_thread.send(TimedInstruction{ self.physics_thread.send(TimedInstruction{
time, time,
instruction:PhysicsWorkerInstruction::Input(SessionInputInstruction::SetControl(SetControlInstruction::SetJump(true))),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump instruction:PhysicsWorkerInstruction::SessionInput(SessionInputInstruction::SetControl(SetControlInstruction::SetJump(true))),//activates the immediate jump path, but the style modifier prevents controls&CONTROL_JUMP bit from being set to auto jump
}).unwrap(); }).unwrap();
} }
}, },