diff --git a/src/physics.rs b/src/physics.rs index 4b962be..962d2da 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -490,21 +490,12 @@ enum MoveState{ impl MoveState{ fn apply_to_body(&self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){ match self{ - MoveState::Air=>{ - //calculate base acceleration - let mut a=touching.base_acceleration(models,style,camera,input_state); - //clip according to contacts - touching.constrain_acceleration(models,hitbox_mesh,&mut a); - //something - set_acceleration(body,touching,models,hitbox_mesh,a); - }, + MoveState::Air=>(), MoveState::Water=>(), MoveState::Fly=>{ //set velocity according to current control state - let mut v=style.get_propulsion_control_dir(camera,input_state.controls)*80; - //clip velocity according to current touching state - touching.constrain_velocity(models,hitbox_mesh,&mut v); - //apply to body + let v=style.get_propulsion_control_dir(camera,input_state.controls)*80; + //set_velocity clips velocity according to current touching state set_velocity(body,touching,models,hitbox_mesh,v); }, MoveState::Walk(walk_state) @@ -519,8 +510,9 @@ impl MoveState{ /// changes the move state and then applies it to body fn apply_input(&mut self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){ match self{ - MoveState::Fly=>(), - MoveState::Air|MoveState::Water=>(), + MoveState::Fly + |MoveState::Air + |MoveState::Water=>(), MoveState::Walk(ContactMoveState{target,contact,jump_direction:_})=>{ if let Some(walk_settings)=&style.walk{ let (gravity,target_velocity,normal)=ground_things(walk_settings,contact,touching,models,hitbox_mesh,style,camera,input_state); @@ -576,6 +568,18 @@ 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{ @@ -949,6 +953,10 @@ impl PhysicsState { fn next_move_instruction(&self)->Option>{ 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); + self.move_state=move_state; + } //state mutated on collision: //Accelerator @@ -1313,8 +1321,7 @@ fn run_teleport_behaviour(wormhole:&Option,models //ladder walkstate let (gravity,target_velocity,normal)=ladder_things(ladder_settings,contact,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state); let walk_state=ContactMoveState::ladder(ladder_settings,&state.body,gravity,target_velocity,contact.clone(),normal); - state.move_state=MoveState::Ladder(walk_state); - state.move_state.apply_to_body(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state); + state.set_move_state(&data,MoveState::Ladder(walk_state)); }, Some(gameplay_attributes::ContactingBehaviour::NoJump)=>todo!("nyi"), None=>if let Some(walk_settings)=&state.style.walk{ @@ -1322,8 +1329,7 @@ fn run_teleport_behaviour(wormhole:&Option,models //ground let (gravity,target_velocity,normal)=ground_things(walk_settings,contact,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state); let walk_state=ContactMoveState::ground(walk_settings,&state.body,gravity,target_velocity,contact.clone(),normal); - state.move_state=MoveState::Walk(walk_state); - state.move_state.apply_to_body(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state); + state.set_move_state(&data,MoveState::Walk(walk_state)); } }, } @@ -1350,7 +1356,10 @@ fn run_teleport_behaviour(wormhole:&Option,models if let (Some(jump_settings),Some(walk_state))=(&state.style.jump,state.move_state.get_walk_state()){ let jump_dir=walk_state.jump_direction.direction(&data.models,&data.hitbox_mesh,&walk_state.contact); v=jump_settings.jumped_velocity(&state.style,jump_dir,v); - set_velocity_cull(&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,v); + if set_velocity_cull(&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,v){ + //wrong!!! + state.set_move_state(&data,MoveState::Air); + } } } match &general.trajectory{ @@ -1366,8 +1375,10 @@ fn run_teleport_behaviour(wormhole:&Option,models }, None=>(), } + //get rid of this garbage set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,v); - state.move_state.apply_input(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state); + //use a different function????? + //state.move_state.apply_input(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state); }, (PhysicsCollisionAttributes::Intersect{intersecting: _,general},Collision::Intersect(intersect))=>{ //I think that setting the velocity to 0 was preventing surface contacts from entering an infinite loop @@ -1404,7 +1415,8 @@ fn run_teleport_behaviour(wormhole:&Option,models //this is wrong but will work ig //need to note which push planes activate in push solve and keep those if set_velocity_cull(&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,v){ - //? + //wrong!!! + state.set_move_state(&data,MoveState::Air); } } } @@ -1462,8 +1474,8 @@ fn run_teleport_behaviour(wormhole:&Option,models let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity); //TODO: be more precise about contacts if set_velocity_cull(&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,jumped_velocity){ - state.move_state=MoveState::Air; - b_refresh_walk_target=true; + //wrong!!! + state.set_move_state(&data,MoveState::Air); } } } @@ -1482,18 +1494,15 @@ fn run_teleport_behaviour(wormhole:&Option,models ).unwrap_or(Planar64Vec3::ZERO); set_position(&mut state.body,&mut state.touching,spawn_point); set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,Planar64Vec3::ZERO); - state.move_state=MoveState::Air; - //b_refresh_walk_target will figure out gravity and stuff + state.set_move_state(&data,MoveState::Air); }, PhysicsInputInstruction::PracticeFly=>{ match &state.move_state{ MoveState::Fly=>{ - state.move_state=MoveState::Air; - state.body.acceleration=state.style.gravity; + state.set_move_state(&data,MoveState::Air); }, _=>{ - state.move_state=MoveState::Fly; - state.body.acceleration=Planar64Vec3::ZERO; + state.set_move_state(&data,MoveState::Fly); }, } },