|
|
|
|
@@ -517,7 +517,7 @@ impl MoveState{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//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){
|
|
|
|
|
fn update_fly_velocity(&self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
match self{
|
|
|
|
|
MoveState::Air=>(),
|
|
|
|
|
MoveState::Water=>(),
|
|
|
|
|
@@ -533,7 +533,7 @@ impl MoveState{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// changes the move state
|
|
|
|
|
fn apply_input(&mut self,body:&Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
fn update_walk_target(&mut self,body:&Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
match self{
|
|
|
|
|
MoveState::Fly
|
|
|
|
|
|MoveState::Air
|
|
|
|
|
@@ -590,22 +590,11 @@ impl MoveState{
|
|
|
|
|
MoveState::Fly=>None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//lmao idk this is convenient
|
|
|
|
|
fn apply_enum_and_input_and_body(&mut self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
self.apply_input(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
self.apply_to_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
}
|
|
|
|
|
fn apply_enum_and_body(&mut self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
self.apply_to_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
}
|
|
|
|
|
fn apply_input_and_body(&mut self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
self.apply_input(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
self.apply_to_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
}
|
|
|
|
|
fn set_move_state(&mut self,move_state:MoveState,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
*self=move_state;
|
|
|
|
|
//this function call reads the above state that was just set
|
|
|
|
|
self.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
@@ -618,10 +607,11 @@ impl MoveState{
|
|
|
|
|
self.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
}else{
|
|
|
|
|
// stopped touching something else while walking
|
|
|
|
|
self.apply_enum_and_input_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
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.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state),
|
|
|
|
|
None=>self.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -945,9 +935,6 @@ impl PhysicsState{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
fn apply_input_and_body(&mut self,data:&PhysicsData){
|
|
|
|
|
self.move_state.apply_input_and_body(&mut self.body,&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
|
|
|
|
}
|
|
|
|
|
fn acceleration(&self,data:&PhysicsData)->Planar64Vec3{
|
|
|
|
|
self.move_state.acceleration(&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state)
|
|
|
|
|
}
|
|
|
|
|
@@ -1196,43 +1183,43 @@ impl<'a> PhysicsContext<'a>{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//this is the one who asks
|
|
|
|
|
fn next_instruction_internal(state:&PhysicsState,data:&PhysicsData,time_limit:Time)->Option<TimedInstruction<InternalInstruction,Time>>{
|
|
|
|
|
//JUST POLLING!!! NO MUTATION
|
|
|
|
|
let mut collector=instruction::InstructionCollector::new(time_limit);
|
|
|
|
|
//this is the one who asks
|
|
|
|
|
fn next_instruction_internal(state:&PhysicsState,data:&PhysicsData,time_limit:Time)->Option<TimedInstruction<InternalInstruction,Time>>{
|
|
|
|
|
//JUST POLLING!!! NO MUTATION
|
|
|
|
|
let mut collector=instruction::InstructionCollector::new(time_limit);
|
|
|
|
|
|
|
|
|
|
collector.collect(state.next_move_instruction());
|
|
|
|
|
collector.collect(state.next_move_instruction());
|
|
|
|
|
|
|
|
|
|
let trajectory=state.body.with_acceleration(state.acceleration(data));
|
|
|
|
|
//check for collision ends
|
|
|
|
|
state.touching.predict_collision_end(&mut collector,&data.models,&data.hitbox_mesh,&trajectory,state.time);
|
|
|
|
|
//check for collision starts
|
|
|
|
|
let mut aabb=aabb::Aabb::default();
|
|
|
|
|
trajectory.grow_aabb(&mut aabb,state.time,collector.time());
|
|
|
|
|
aabb.inflate(data.hitbox_mesh.halfsize);
|
|
|
|
|
//relative to moving platforms
|
|
|
|
|
//let relative_body=state.body.relative_to(&Body::ZERO);
|
|
|
|
|
data.bvh.sample_aabb(&aabb,&mut |convex_mesh_id|{
|
|
|
|
|
if state.touching.contains(convex_mesh_id){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//no checks are needed because of the time limits.
|
|
|
|
|
let model_mesh=data.models.mesh(*convex_mesh_id);
|
|
|
|
|
let minkowski=model_physics::MinkowskiMesh::minkowski_sum(model_mesh,data.hitbox_mesh.transformed_mesh());
|
|
|
|
|
collector.collect(minkowski.predict_collision_in(&trajectory,state.time..collector.time())
|
|
|
|
|
.map(|(face,dt)|
|
|
|
|
|
TimedInstruction{
|
|
|
|
|
time:trajectory.time+dt.into(),
|
|
|
|
|
instruction:InternalInstruction::CollisionStart(
|
|
|
|
|
Collision::new(*convex_mesh_id,face),
|
|
|
|
|
dt
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
collector.take()
|
|
|
|
|
}
|
|
|
|
|
let trajectory=state.body.with_acceleration(state.acceleration(data));
|
|
|
|
|
//check for collision ends
|
|
|
|
|
state.touching.predict_collision_end(&mut collector,&data.models,&data.hitbox_mesh,&trajectory,state.time);
|
|
|
|
|
//check for collision starts
|
|
|
|
|
let mut aabb=aabb::Aabb::default();
|
|
|
|
|
trajectory.grow_aabb(&mut aabb,state.time,collector.time());
|
|
|
|
|
aabb.inflate(data.hitbox_mesh.halfsize);
|
|
|
|
|
//relative to moving platforms
|
|
|
|
|
//let relative_body=state.body.relative_to(&Body::ZERO);
|
|
|
|
|
data.bvh.sample_aabb(&aabb,&mut |convex_mesh_id|{
|
|
|
|
|
if state.touching.contains(convex_mesh_id){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//no checks are needed because of the time limits.
|
|
|
|
|
let model_mesh=data.models.mesh(*convex_mesh_id);
|
|
|
|
|
let minkowski=model_physics::MinkowskiMesh::minkowski_sum(model_mesh,data.hitbox_mesh.transformed_mesh());
|
|
|
|
|
collector.collect(minkowski.predict_collision_in(&trajectory,state.time..collector.time())
|
|
|
|
|
.map(|(face,dt)|
|
|
|
|
|
TimedInstruction{
|
|
|
|
|
time:trajectory.time+dt.into(),
|
|
|
|
|
instruction:InternalInstruction::CollisionStart(
|
|
|
|
|
Collision::new(*convex_mesh_id,face),
|
|
|
|
|
dt
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
collector.take()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn contact_normal(
|
|
|
|
|
@@ -1620,7 +1607,8 @@ fn collision_start_contact(
|
|
|
|
|
}
|
|
|
|
|
//doing enum to set the acceleration when surfing
|
|
|
|
|
//doing input_and_body to refresh the walk state if you hit a wall while accelerating
|
|
|
|
|
move_state.apply_enum_and_input_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn collision_start_intersect(
|
|
|
|
|
@@ -1676,7 +1664,7 @@ fn collision_start_intersect(
|
|
|
|
|
None=>(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
move_state.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
move_state.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
run_teleport_behaviour(intersect.convex_mesh_id.model_id.into(),attr.general.wormhole.as_ref(),mode,move_state,body,touching,run,mode_state,models,hitbox_mesh,bvh,style,camera,input_state,time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1704,10 +1692,11 @@ fn collision_end_contact(
|
|
|
|
|
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.apply_enum_and_input_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
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.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state),
|
|
|
|
|
None=>move_state.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn collision_end_intersect(
|
|
|
|
|
@@ -1726,7 +1715,7 @@ fn collision_end_intersect(
|
|
|
|
|
time:Time,
|
|
|
|
|
){
|
|
|
|
|
touching.remove_intersect(convex_mesh_id);
|
|
|
|
|
move_state.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
move_state.update_fly_velocity(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
if let Some(mode)=mode{
|
|
|
|
|
let zone=mode.get_zone(convex_mesh_id.model_id.into());
|
|
|
|
|
match zone{
|
|
|
|
|
@@ -1799,9 +1788,10 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
|
|
|
|
let control_dir=state.style.get_control_dir(masked_controls);
|
|
|
|
|
if control_dir!=vec3::zero(){
|
|
|
|
|
// manually advance time
|
|
|
|
|
state.body=state.body.with_acceleration(state.acceleration(data)).extrapolated_body(state.time);
|
|
|
|
|
let extrapolated_body=state.body.with_acceleration(state.acceleration(data)).extrapolated_body(state.time);
|
|
|
|
|
let camera_mat=state.camera.simulate_move_rotation_y(state.input_state.lerp_delta(state.time).x);
|
|
|
|
|
if let Some(ticked_velocity)=strafe_settings.tick_velocity(state.body.velocity,(camera_mat*control_dir).with_length(Planar64::ONE).divide().wrap_1()){
|
|
|
|
|
if let Some(ticked_velocity)=strafe_settings.tick_velocity(extrapolated_body.velocity,(camera_mat*control_dir).with_length(Planar64::ONE).divide().wrap_1()){
|
|
|
|
|
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);
|
|
|
|
|
@@ -1958,7 +1948,8 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
if b_refresh_walk_target{
|
|
|
|
|
state.apply_input_and_body(data);
|
|
|
|
|
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);
|
|
|
|
|
//also check if accelerating away from surface
|
|
|
|
|
}
|
|
|
|
|
|