it works??

This commit is contained in:
Quaternions 2024-02-21 05:05:02 -08:00
parent eb34cce746
commit 9bf3f55191

View File

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