add touching_changed function
This commit is contained in:
@@ -608,25 +608,26 @@ impl MoveState{
|
||||
*self=move_state;
|
||||
//this function call reads the above state that was just set
|
||||
self.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
// Never used? make body immutable
|
||||
self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}
|
||||
fn cull_velocity(&mut self,velocity:Planar64Vec3,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
||||
//TODO: be more precise about contacts
|
||||
if set_velocity_cull(body,touching,models,hitbox_mesh,velocity){
|
||||
// TODO do better
|
||||
// TODO: unduplicate this code
|
||||
match self.get_walk_state(){
|
||||
// did you stop touching the thing you were walking on?
|
||||
Some(walk_state)=>if !touching.contains_contact(&walk_state.contact.convex_mesh_id){
|
||||
self.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
self.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
}
|
||||
self.touching_changed(body,touching,models,hitbox_mesh,style,camera,input_state,|contact|!touching.contains_contact(&contact.convex_mesh_id));
|
||||
}
|
||||
}
|
||||
fn touching_changed(&mut self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState,is_contact_removed:impl Fn(&ContactCollision)->bool){
|
||||
match self.get_walk_state(){
|
||||
// did you stop touching the thing you were walking on?
|
||||
Some(walk_state)=>if is_contact_removed(&walk_state.contact){
|
||||
self.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
self.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -964,9 +965,6 @@ impl PhysicsState{
|
||||
fn next_move_instruction(&self)->Option<TimedInstruction<InternalInstruction,Time>>{
|
||||
self.move_state.next_move_instruction(&self.style.strafe,self.time)
|
||||
}
|
||||
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);
|
||||
}
|
||||
fn set_move_state(&mut self,data:&PhysicsData,move_state:MoveState){
|
||||
self.move_state.set_move_state(move_state,&mut self.body,&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
||||
}
|
||||
@@ -1726,20 +1724,7 @@ fn collision_end_contact(
|
||||
//check ground
|
||||
//TODO do better
|
||||
//this is inner code from move_state.cull_velocity
|
||||
match move_state.get_walk_state(){
|
||||
// did you stop touching the thing you were walking on?
|
||||
// This does not check the face! Is that a bad thing? It should be
|
||||
// impossible to stop touching a different face than you started touching...
|
||||
Some(walk_state)=>if &walk_state.contact.convex_mesh_id==convex_mesh_id{
|
||||
move_state.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
move_state.update_walk_target(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
move_state.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>move_state.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
}
|
||||
move_state.touching_changed(body,touching,models,hitbox_mesh,style,camera,input_state,|contact|contact.convex_mesh_id==*convex_mesh_id);
|
||||
}
|
||||
fn collision_end_intersect(
|
||||
move_state:&mut MoveState,
|
||||
@@ -1836,7 +1821,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
||||
state.body=extrapolated_body;
|
||||
//this is wrong but will work ig
|
||||
//need to note which push planes activate in push solve and keep those
|
||||
state.cull_velocity(data,ticked_velocity);
|
||||
state.move_state.cull_velocity(ticked_velocity,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1920,7 +1905,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
let jump_dir=walk_state.jump_direction.direction(&data.models,&data.hitbox_mesh,&walk_state.contact);
|
||||
let booster_option=data.models.contact_attr(walk_state.contact.convex_mesh_id.model_id).general.booster.as_ref();
|
||||
let jumped_velocity=jump_settings.jumped_velocity(&state.style,jump_dir,state.body.velocity,booster_option);
|
||||
state.cull_velocity(data,jumped_velocity);
|
||||
state.move_state.cull_velocity(jumped_velocity,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
}
|
||||
}
|
||||
b_refresh_walk_target=false;
|
||||
@@ -1993,7 +1978,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
||||
if b_refresh_walk_target{
|
||||
state.move_state.update_walk_target(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
state.move_state.update_fly_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
state.cull_velocity(data,state.body.velocity);
|
||||
state.move_state.cull_velocity(state.body.velocity,&mut state.body,&mut state.touching,&data.models,&data.hitbox_mesh,&state.style,&state.camera,&state.input_state);
|
||||
//also check if accelerating away from surface
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user