rename physics instructions

This commit is contained in:
Quaternions 2025-01-15 20:19:20 -08:00
parent 6fa0f1c83e
commit 814e573d91
6 changed files with 46 additions and 46 deletions

View File

@ -7,16 +7,16 @@ pub type Time=crate::integer::Time<TimeInner>;
#[derive(Clone,Debug)]
pub enum Instruction{
Mouse(MouseInstruction),
Other(OtherInstruction),
NonMouse(NonMouseInstruction),
}
impl Instruction{
pub const IDLE:Self=Self::Other(OtherInstruction::Other(OtherOtherInstruction::Idle));
pub const IDLE:Self=Self::NonMouse(NonMouseInstruction::Misc(MiscInstruction::Idle));
}
#[derive(Clone,Debug)]
pub enum OtherInstruction{
pub enum NonMouseInstruction{
SetControl(SetControlInstruction),
Mode(ModeInstruction),
Other(OtherOtherInstruction),
Misc(MiscInstruction),
}
#[derive(Clone,Debug)]
pub enum MouseInstruction{
@ -50,7 +50,7 @@ pub enum ModeInstruction{
Spawn(crate::gameplay_modes::ModeId,crate::gameplay_modes::StageId),
}
#[derive(Clone,Debug)]
pub enum OtherOtherInstruction{
pub enum MiscInstruction{
/// Idle: there were no input events, but the simulation is safe to advance to this timestep
Idle,
PracticeFly,

View File

@ -4,7 +4,7 @@ use strafesnet_common::physics::{
TimeInner as PhysicsTimeInner,
Time as PhysicsTime,
MouseInstruction,
OtherInstruction,
NonMouseInstruction,
};
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
use strafesnet_common::instruction::{InstructionConsumer,InstructionEmitter,TimedInstruction};
@ -19,7 +19,7 @@ const MOUSE_TIMEOUT:SessionTime=SessionTime::from_millis(10);
#[derive(Clone,Debug)]
pub enum Instruction{
MoveMouse(glam::IVec2),
Other(OtherInstruction),
Other(NonMouseInstruction),
}
pub enum StepInstruction{
@ -164,7 +164,7 @@ impl MouseInterpolator{
if let Some(ins)=ins_other{
let instruction=TimedInstruction{
time:ins.time,
instruction:PhysicsInputInstruction::Other(ins.instruction),
instruction:PhysicsInputInstruction::NonMouse(ins.instruction),
};
if matches!(self.buffer_state,BufferState::Unbuffered){
self.output.push_back(instruction);

View File

@ -19,7 +19,7 @@ type MouseState=strafesnet_common::mouse::MouseState<TimeInner>;
//external influence
//this is how you influence the physics from outside
use strafesnet_common::physics::{Instruction,OtherInstruction,MouseInstruction,ModeInstruction,OtherOtherInstruction,SetControlInstruction};
use strafesnet_common::physics::{Instruction,NonMouseInstruction,MouseInstruction,ModeInstruction,MiscInstruction,SetControlInstruction};
//internal influence
//when the physics asks itself what happens next, this is how it's represented
@ -1736,13 +1736,13 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
let should_advance_body=match ins.instruction{
//the body may as well be a quantum wave function
//as far as these instruction are concerned (they don't care where it is)
Instruction::Other(OtherInstruction::Other(OtherOtherInstruction::SetSensitivity(..)))
|Instruction::Other(OtherInstruction::Mode(_))
|Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetZoom(..)))
|Instruction::Other(OtherInstruction::Other(OtherOtherInstruction::Idle))=>false,
Instruction::NonMouse(NonMouseInstruction::Misc(MiscInstruction::SetSensitivity(..)))
|Instruction::NonMouse(NonMouseInstruction::Mode(_))
|Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetZoom(..)))
|Instruction::NonMouse(NonMouseInstruction::Misc(MiscInstruction::Idle))=>false,
//these controls only update the body if you are on the ground
Instruction::Mouse(_)
|Instruction::Other(OtherInstruction::SetControl(_))=>{
|Instruction::NonMouse(NonMouseInstruction::SetControl(_))=>{
match &state.move_state{
MoveState::Fly
|MoveState::Water
@ -1752,7 +1752,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
}
},
//the body must be updated unconditionally
Instruction::Other(OtherInstruction::Other(OtherOtherInstruction::PracticeFly))=>true,
Instruction::NonMouse(NonMouseInstruction::Misc(MiscInstruction::PracticeFly))=>true,
};
if should_advance_body{
state.body.advance_time(state.time);
@ -1768,14 +1768,14 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
state.camera.move_mouse(m0.pos-state.input_state.mouse.pos);
state.input_state.replace_mouse(m0,m1);
},
Instruction::Other(OtherInstruction::Other(OtherOtherInstruction::SetSensitivity(sensitivity)))=>state.camera.sensitivity=sensitivity,
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetMoveForward(s)))=>state.input_state.set_control(Controls::MoveForward,s),
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetMoveLeft(s)))=>state.input_state.set_control(Controls::MoveLeft,s),
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetMoveBack(s)))=>state.input_state.set_control(Controls::MoveBackward,s),
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetMoveRight(s)))=>state.input_state.set_control(Controls::MoveRight,s),
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetMoveUp(s)))=>state.input_state.set_control(Controls::MoveUp,s),
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetMoveDown(s)))=>state.input_state.set_control(Controls::MoveDown,s),
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetJump(s)))=>{
Instruction::NonMouse(NonMouseInstruction::Misc(MiscInstruction::SetSensitivity(sensitivity)))=>state.camera.sensitivity=sensitivity,
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetMoveForward(s)))=>state.input_state.set_control(Controls::MoveForward,s),
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetMoveLeft(s)))=>state.input_state.set_control(Controls::MoveLeft,s),
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetMoveBack(s)))=>state.input_state.set_control(Controls::MoveBackward,s),
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetMoveRight(s)))=>state.input_state.set_control(Controls::MoveRight,s),
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetMoveUp(s)))=>state.input_state.set_control(Controls::MoveUp,s),
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetMoveDown(s)))=>state.input_state.set_control(Controls::MoveDown,s),
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetJump(s)))=>{
state.input_state.set_control(Controls::Jump,s);
if let Some(walk_state)=state.move_state.get_walk_state(){
if let Some(jump_settings)=&state.style.jump{
@ -1787,16 +1787,16 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
}
b_refresh_walk_target=false;
},
Instruction::Other(OtherInstruction::SetControl(SetControlInstruction::SetZoom(s)))=>{
Instruction::NonMouse(NonMouseInstruction::SetControl(SetControlInstruction::SetZoom(s)))=>{
state.input_state.set_control(Controls::Zoom,s);
b_refresh_walk_target=false;
},
Instruction::Other(OtherInstruction::Mode(ModeInstruction::Reset))=>{
Instruction::NonMouse(NonMouseInstruction::Mode(ModeInstruction::Reset))=>{
//totally reset physics state
state.reset_to_default();
b_refresh_walk_target=false;
},
Instruction::Other(OtherInstruction::Mode(ModeInstruction::Restart))=>{
Instruction::NonMouse(NonMouseInstruction::Mode(ModeInstruction::Restart))=>{
//teleport to start zone
let mode=data.modes.get_mode(state.mode_state.get_mode_id());
let spawn_point=mode.and_then(|mode|
@ -1812,7 +1812,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
b_refresh_walk_target=false;
}
// Spawn does not necessarily imply reset
Instruction::Other(OtherInstruction::Mode(ModeInstruction::Spawn(mode_id,stage_id)))=>{
Instruction::NonMouse(NonMouseInstruction::Mode(ModeInstruction::Spawn(mode_id,stage_id)))=>{
//spawn at a particular stage
if let Some(mode)=data.modes.get_mode(mode_id){
if let Some(stage)=mode.get_stage(stage_id){
@ -1826,7 +1826,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
}
b_refresh_walk_target=false;
},
Instruction::Other(OtherInstruction::Other(OtherOtherInstruction::PracticeFly))=>{
Instruction::NonMouse(NonMouseInstruction::Misc(MiscInstruction::PracticeFly))=>{
match &state.move_state{
MoveState::Fly=>{
state.set_move_state(data,MoveState::Air);
@ -1837,7 +1837,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
}
b_refresh_walk_target=false;
},
Instruction::Other(OtherInstruction::Other(OtherOtherInstruction::Idle))=>{
Instruction::NonMouse(NonMouseInstruction::Misc(MiscInstruction::Idle))=>{
//literally idle!
b_refresh_walk_target=false;
},

View File

@ -13,7 +13,7 @@ pub enum Instruction{
ChangeMap(strafesnet_common::map::CompleteMap),
}
const SESSION_INSTRUCTION_IDLE:SessionInstruction=SessionInstruction::Input(SessionInputInstruction::Other(strafesnet_common::physics::OtherOtherInstruction::Idle));
const SESSION_INSTRUCTION_IDLE:SessionInstruction=SessionInstruction::Input(SessionInputInstruction::Misc(strafesnet_common::physics::MiscInstruction::Idle));
pub fn new<'a>(
mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>,

View File

@ -3,7 +3,7 @@ use strafesnet_common::instruction::{InstructionConsumer,InstructionEmitter,Inst
// session represents the non-hardware state of the client.
// Ideally it is a deterministic state which is atomically updated by instructions, same as the simulation state.
use strafesnet_common::physics::{
ModeInstruction,OtherInstruction,OtherOtherInstruction,
ModeInstruction,NonMouseInstruction,MiscInstruction,
Instruction as PhysicsInputInstruction,
TimeInner as PhysicsTimeInner,
Time as PhysicsTime
@ -25,7 +25,7 @@ pub enum SessionInputInstruction{
Mouse(glam::IVec2),
SetControl(strafesnet_common::physics::SetControlInstruction),
Mode(ImplicitModeInstruction),
Other(strafesnet_common::physics::OtherOtherInstruction),
Misc(strafesnet_common::physics::MiscInstruction),
}
/// Implicit mode instruction are fed separately to session.
/// Session generates the explicit mode instructions interlaced with a SetSensitivity instruction
@ -144,20 +144,20 @@ impl InstructionConsumer<Instruction<'_>> for Session{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::MoveMouse(pos));
},
Instruction::Input(SessionInputInstruction::SetControl(set_control_instruction))=>{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::SetControl(set_control_instruction)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::SetControl(set_control_instruction)));
},
Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndRestart))=>{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Mode(ModeInstruction::Reset)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Other(OtherOtherInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Mode(ModeInstruction::Restart)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Mode(ModeInstruction::Reset)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Mode(ModeInstruction::Restart)));
},
Instruction::Input(SessionInputInstruction::Mode(ImplicitModeInstruction::ResetAndSpawn(mode_id,spawn_id)))=>{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Mode(ModeInstruction::Reset)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Other(OtherOtherInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Mode(ModeInstruction::Spawn(mode_id,spawn_id))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Mode(ModeInstruction::Reset)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Mode(ModeInstruction::Spawn(mode_id,spawn_id))));
},
Instruction::Input(SessionInputInstruction::Other(other_other_instruction))=>{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Other(other_other_instruction)));
Instruction::Input(SessionInputInstruction::Misc(other_other_instruction))=>{
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Misc(other_other_instruction)));
},
Instruction::SetPaused(paused)=>{
// don't flush the buffered instructions in the mouse interpolator
@ -168,9 +168,9 @@ impl InstructionConsumer<Instruction<'_>> for Session{
Instruction::ChangeMap(complete_map)=>{
self.change_map(complete_map);
// ResetAndSpawn
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Mode(ModeInstruction::Reset)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Other(OtherOtherInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(OtherInstruction::Mode(ModeInstruction::Spawn(ModeId::MAIN,StageId::FIRST))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Mode(ModeInstruction::Reset)));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Misc(MiscInstruction::SetSensitivity(self.user_settings().calculate_sensitivity()))));
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Other(NonMouseInstruction::Mode(ModeInstruction::Spawn(ModeId::MAIN,StageId::FIRST))));
},
};

View File

@ -1,6 +1,6 @@
use strafesnet_common::instruction::TimedInstruction;
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
use strafesnet_common::physics::{OtherInstruction,OtherOtherInstruction,SetControlInstruction};
use strafesnet_common::physics::{MiscInstruction,SetControlInstruction};
use crate::physics_worker::Instruction as PhysicsWorkerInstruction;
use crate::session::SessionInputInstruction;
@ -107,7 +107,7 @@ impl WindowContext<'_>{
self.mouse_pos=glam::DVec2::ZERO;
SessionInputInstruction::Mode(crate::session::ImplicitModeInstruction::ResetAndRestart)
}),
"F"|"f"=>s.then_some(SessionInputInstruction::Other(OtherOtherInstruction::PracticeFly)),
"F"|"f"=>s.then_some(SessionInputInstruction::Misc(MiscInstruction::PracticeFly)),
_=>None,
},
_=>None,