From f027594ab470b382e0fe7e2cc45362d9ebfc12fb Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 21 Feb 2024 05:24:12 -0800 Subject: [PATCH] before and after not needed currently --- src/physics.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/physics.rs b/src/physics.rs index 43808f6..db25b8f 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -488,6 +488,19 @@ enum MoveState{ Fly, } impl MoveState{ + //call this after state.move_state is changed + fn changed(&self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){ + match self{ + MoveState::Fly=>body.acceleration=Planar64Vec3::ZERO, + MoveState::Air=>{ + //calculate base acceleration + let a=touching.base_acceleration(models,style,camera,input_state); + //set_acceleration clips according to contacts + set_acceleration(body,touching,models,hitbox_mesh,a); + }, + _=>(), + } + } //function to coerce &mut self into &self fn apply_to_body(&self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){ match self{ @@ -569,18 +582,6 @@ impl MoveState{ } } } -fn move_state_edge(old_move_state:&MoveState,new_move_state:&MoveState,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){ - match new_move_state{ - MoveState::Fly=>body.acceleration=Planar64Vec3::ZERO, - MoveState::Air=>{ - //calculate base acceleration - let a=touching.base_acceleration(models,style,camera,input_state); - //set_acceleration clips according to contacts - set_acceleration(body,touching,models,hitbox_mesh,a); - }, - _=>(), - } -} #[derive(Clone,Default)] pub struct PhysicsOutputState{ @@ -955,7 +956,7 @@ impl PhysicsState { self.move_state.next_move_instruction(&self.style.strafe,self.time) } fn set_move_state(&mut self,data:&PhysicsData,move_state:MoveState){ - move_state_edge(&self.move_state,&move_state,&mut self.body,&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state); + move_state.changed(&mut self.body,&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state); self.move_state=move_state; }