|
|
|
|
@@ -495,6 +495,27 @@ impl StyleHelper for StyleModifiers{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[derive(Clone,Debug)]
|
|
|
|
|
struct StrafeTickState{
|
|
|
|
|
tick_number:u64,
|
|
|
|
|
}
|
|
|
|
|
impl StrafeTickState{
|
|
|
|
|
fn new(time:Time,settings:&gameplay_style::StrafeSettings)->Self{
|
|
|
|
|
// let time=n*seconds/ticks;
|
|
|
|
|
let time=time.nanos() as i128;
|
|
|
|
|
let ticks=settings.tick_rate.num() as i128;
|
|
|
|
|
let seconds=settings.tick_rate.den() as i128;
|
|
|
|
|
let tick_number=(time*ticks/seconds) as u64;
|
|
|
|
|
StrafeTickState{tick_number}
|
|
|
|
|
}
|
|
|
|
|
fn next_tick(&self,settings:&gameplay_style::StrafeSettings)->Time{
|
|
|
|
|
let n=self.tick_number as i128;
|
|
|
|
|
let ticks=settings.tick_rate.num() as i128;
|
|
|
|
|
let seconds=settings.tick_rate.den() as i128;
|
|
|
|
|
let time=n*seconds/ticks;
|
|
|
|
|
Time::from_nanos(time as i64)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#[derive(Clone,Debug)]
|
|
|
|
|
enum MoveState{
|
|
|
|
|
Air,
|
|
|
|
|
Walk(ContactMoveState),
|
|
|
|
|
@@ -572,7 +593,7 @@ impl MoveState{
|
|
|
|
|
=>None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn next_move_instruction(&self,strafe:&Option<gameplay_style::StrafeSettings>,time:Time)->Option<TimedInstruction<InternalInstruction,Time>>{
|
|
|
|
|
fn next_move_instruction(&self,strafe:Option<&gameplay_style::StrafeSettings>,strafe_tick_state:&StrafeTickState)->Option<TimedInstruction<InternalInstruction,Time>>{
|
|
|
|
|
//check if you have a valid walk state and create an instruction
|
|
|
|
|
match self{
|
|
|
|
|
MoveState::Walk(walk_state)|MoveState::Ladder(walk_state)=>match &walk_state.target{
|
|
|
|
|
@@ -586,7 +607,7 @@ impl MoveState{
|
|
|
|
|
}
|
|
|
|
|
MoveState::Air=>strafe.as_ref().map(|strafe|{
|
|
|
|
|
TimedInstruction{
|
|
|
|
|
time:strafe.next_tick(time),
|
|
|
|
|
time:strafe_tick_state.next_tick(strafe),
|
|
|
|
|
//only poll the physics if there is a before and after mouse event
|
|
|
|
|
instruction:InternalInstruction::StrafeTick
|
|
|
|
|
}
|
|
|
|
|
@@ -871,6 +892,7 @@ pub struct PhysicsState{
|
|
|
|
|
//gameplay_state
|
|
|
|
|
mode_state:ModeState,
|
|
|
|
|
move_state:MoveState,
|
|
|
|
|
strafe_tick_state:StrafeTickState,
|
|
|
|
|
//run is non optional: when you spawn in a run is created
|
|
|
|
|
//the run cannot be finished unless you start it by visiting
|
|
|
|
|
//a start zone. If you change mode, a new run is created.
|
|
|
|
|
@@ -889,6 +911,7 @@ impl Default for PhysicsState{
|
|
|
|
|
input_state:InputState::default(),
|
|
|
|
|
_world:WorldState{},
|
|
|
|
|
mode_state:ModeState::default(),
|
|
|
|
|
strafe_tick_state:StrafeTickState::new(Time::ZERO,&StyleModifiers::default().strafe.unwrap()),
|
|
|
|
|
run:run::Run::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -935,7 +958,7 @@ impl PhysicsState{
|
|
|
|
|
*self=Self::default();
|
|
|
|
|
}
|
|
|
|
|
fn next_move_instruction(&self)->Option<TimedInstruction<InternalInstruction,Time>>{
|
|
|
|
|
self.move_state.next_move_instruction(&self.style.strafe,self.time)
|
|
|
|
|
self.move_state.next_move_instruction(self.style.strafe.as_ref(),&self.strafe_tick_state)
|
|
|
|
|
}
|
|
|
|
|
fn cull_velocity(&mut self,data:&PhysicsData,velocity:Planar64Vec3){
|
|
|
|
|
self.move_state.cull_velocity(velocity,&mut self.body,&mut self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
|
|
|
|
@@ -1793,6 +1816,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
InternalInstruction::StrafeTick=>{
|
|
|
|
|
state.strafe_tick_state.tick_number+=1;
|
|
|
|
|
//TODO make this less huge
|
|
|
|
|
if let Some(strafe_settings)=&state.style.strafe{
|
|
|
|
|
let controls=state.input_state.controls;
|
|
|
|
|
|