|
|
|
|
@@ -534,20 +534,20 @@ enum MoveState{
|
|
|
|
|
}
|
|
|
|
|
impl MoveState{
|
|
|
|
|
//call this after state.move_state is changed
|
|
|
|
|
fn apply_enum(&self,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
fn apply_enum(&self,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
match self{
|
|
|
|
|
MoveState::Fly=>body.acceleration=vec3::ZERO,
|
|
|
|
|
MoveState::Air=>{
|
|
|
|
|
//calculate base acceleration
|
|
|
|
|
let a=touching.base_acceleration(models,style,camera,input_state);
|
|
|
|
|
//set_acceleration clips according to contacts
|
|
|
|
|
set_acceleration_cull(body,touching,models,hitbox_mesh,a);
|
|
|
|
|
set_acceleration(body,touching,models,hitbox_mesh,a);
|
|
|
|
|
},
|
|
|
|
|
_=>(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//function to coerce &mut self into &self
|
|
|
|
|
fn apply_to_body(&self,body:&mut Body,touching:&mut 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{
|
|
|
|
|
MoveState::Air=>(),
|
|
|
|
|
MoveState::Water=>(),
|
|
|
|
|
@@ -555,14 +555,14 @@ impl MoveState{
|
|
|
|
|
//set velocity according to current control state
|
|
|
|
|
let v=style.get_propulsion_control_dir(camera,input_state.controls)*80;
|
|
|
|
|
//set_velocity clips velocity according to current touching state
|
|
|
|
|
set_velocity_cull(body,touching,models,hitbox_mesh,v);
|
|
|
|
|
set_velocity(body,touching,models,hitbox_mesh,v);
|
|
|
|
|
},
|
|
|
|
|
MoveState::Walk(walk_state)
|
|
|
|
|
|MoveState::Ladder(walk_state)
|
|
|
|
|
=>{
|
|
|
|
|
//accelerate towards walk target or do nothing
|
|
|
|
|
let a=walk_state.target.acceleration();
|
|
|
|
|
set_acceleration_cull(body,touching,models,hitbox_mesh,a);
|
|
|
|
|
set_acceleration(body,touching,models,hitbox_mesh,a);
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -625,20 +625,20 @@ impl MoveState{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//lmao idk this is convenient
|
|
|
|
|
fn apply_enum_and_input_and_body(&mut self,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
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_enum(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
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:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
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_enum(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
self.apply_to_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
}
|
|
|
|
|
fn apply_input_and_body(&mut self,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
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:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
|
|
|
|
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);
|
|
|
|
|
@@ -808,7 +808,7 @@ impl TouchingState{
|
|
|
|
|
a
|
|
|
|
|
}
|
|
|
|
|
fn constrain_velocity(&self,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,velocity:Planar64Vec3)->Planar64Vec3{
|
|
|
|
|
let contacts=self.contacts.iter().map(|contact|{
|
|
|
|
|
let contacts:Vec<_>=self.contacts.iter().map(|contact|{
|
|
|
|
|
let n=contact_normal(models,hitbox_mesh,contact);
|
|
|
|
|
crate::push_solve::Contact{
|
|
|
|
|
position:vec3::ZERO,
|
|
|
|
|
@@ -819,7 +819,7 @@ impl TouchingState{
|
|
|
|
|
crate::push_solve::push_solve(&contacts,velocity)
|
|
|
|
|
}
|
|
|
|
|
fn constrain_acceleration(&self,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,acceleration:Planar64Vec3)->Planar64Vec3{
|
|
|
|
|
let contacts=self.contacts.iter().map(|contact|{
|
|
|
|
|
let contacts:Vec<_>=self.contacts.iter().map(|contact|{
|
|
|
|
|
let n=contact_normal(models,hitbox_mesh,contact);
|
|
|
|
|
crate::push_solve::Contact{
|
|
|
|
|
position:vec3::ZERO,
|
|
|
|
|
@@ -930,10 +930,10 @@ impl PhysicsState{
|
|
|
|
|
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,&mut self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
|
|
|
|
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,&mut self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
|
|
|
|
self.move_state.apply_input_and_body(&mut self.body,&self.touching,&data.models,&data.hitbox_mesh,&self.style,&self.camera,&self.input_state);
|
|
|
|
|
}
|
|
|
|
|
//state mutated on collision:
|
|
|
|
|
//Accelerator
|
|
|
|
|
@@ -1341,7 +1341,7 @@ fn teleport(
|
|
|
|
|
time:Time,
|
|
|
|
|
){
|
|
|
|
|
set_position(point,move_state,body,touching,run,mode_state,mode,models,hitbox_mesh,bvh,style,camera,input_state,time);
|
|
|
|
|
set_acceleration_cull(body,touching,models,hitbox_mesh,style.gravity);
|
|
|
|
|
set_acceleration(body,touching,models,hitbox_mesh,style.gravity);
|
|
|
|
|
}
|
|
|
|
|
enum TeleportToSpawnError{
|
|
|
|
|
NoModel,
|
|
|
|
|
@@ -1522,7 +1522,10 @@ fn collision_start_contact(
|
|
|
|
|
time:Time,
|
|
|
|
|
){
|
|
|
|
|
let incident_velocity=body.velocity;
|
|
|
|
|
let clipped_velocity=touching.constrain_velocity(models,hitbox_mesh,incident_velocity);
|
|
|
|
|
//add to touching
|
|
|
|
|
touching.insert(Collision::Contact(contact));
|
|
|
|
|
//clip v
|
|
|
|
|
set_velocity(body,touching,models,hitbox_mesh,incident_velocity);
|
|
|
|
|
let mut allow_jump=true;
|
|
|
|
|
let model_id=contact.model_id.into();
|
|
|
|
|
let mut allow_run_teleport_behaviour=not_spawn_at(mode,model_id);
|
|
|
|
|
@@ -1530,7 +1533,7 @@ fn collision_start_contact(
|
|
|
|
|
Some(gameplay_attributes::ContactingBehaviour::Surf)=>(),
|
|
|
|
|
Some(gameplay_attributes::ContactingBehaviour::Cling)=>println!("Unimplemented!"),
|
|
|
|
|
&Some(gameplay_attributes::ContactingBehaviour::Elastic(elasticity))=>{
|
|
|
|
|
let reflected_velocity=body.velocity+((clipped_velocity-incident_velocity)*Planar64::raw(elasticity as i64+1)).fix_1();
|
|
|
|
|
let reflected_velocity=body.velocity+((body.velocity-incident_velocity)*Planar64::raw(elasticity as i64+1)).fix_1();
|
|
|
|
|
set_velocity(body,touching,models,hitbox_mesh,reflected_velocity);
|
|
|
|
|
},
|
|
|
|
|
Some(gameplay_attributes::ContactingBehaviour::Ladder(contacting_ladder))=>
|
|
|
|
|
@@ -1557,6 +1560,21 @@ fn collision_start_contact(
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
match &attr.general.trajectory{
|
|
|
|
|
Some(trajectory)=>{
|
|
|
|
|
match trajectory{
|
|
|
|
|
gameplay_attributes::SetTrajectory::AirTime(_)=>todo!(),
|
|
|
|
|
gameplay_attributes::SetTrajectory::Height(_)=>todo!(),
|
|
|
|
|
gameplay_attributes::SetTrajectory::TargetPointTime{..}=>todo!(),
|
|
|
|
|
gameplay_attributes::SetTrajectory::TargetPointSpeed{..}=>todo!(),
|
|
|
|
|
&gameplay_attributes::SetTrajectory::Velocity(velocity)=>{
|
|
|
|
|
move_state.cull_velocity(velocity,body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
},
|
|
|
|
|
gameplay_attributes::SetTrajectory::DotVelocity{..}=>todo!(),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
None=>(),
|
|
|
|
|
}
|
|
|
|
|
//I love making functions with 10 arguments to dodge the borrow checker
|
|
|
|
|
if allow_run_teleport_behaviour{
|
|
|
|
|
run_teleport_behaviour(model_id,attr.general.wormhole.as_ref(),mode,move_state,body,touching,run,mode_state,models,hitbox_mesh,bvh,style,camera,input_state,time);
|
|
|
|
|
@@ -1584,21 +1602,6 @@ fn collision_start_contact(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
match &attr.general.trajectory{
|
|
|
|
|
Some(trajectory)=>{
|
|
|
|
|
match trajectory{
|
|
|
|
|
gameplay_attributes::SetTrajectory::AirTime(_)=>todo!(),
|
|
|
|
|
gameplay_attributes::SetTrajectory::Height(_)=>todo!(),
|
|
|
|
|
gameplay_attributes::SetTrajectory::TargetPointTime { target_point: _, time: _ }=>todo!(),
|
|
|
|
|
gameplay_attributes::SetTrajectory::TargetPointSpeed { target_point: _, speed: _, trajectory_choice: _ }=>todo!(),
|
|
|
|
|
&gameplay_attributes::SetTrajectory::Velocity(velocity)=>{
|
|
|
|
|
move_state.cull_velocity(velocity,body,touching,models,hitbox_mesh,style,camera,input_state);
|
|
|
|
|
},
|
|
|
|
|
gameplay_attributes::SetTrajectory::DotVelocity { direction: _, dot: _ }=>todo!(),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
None=>(),
|
|
|
|
|
}
|
|
|
|
|
//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);
|
|
|
|
|
@@ -2262,7 +2265,7 @@ mod test{
|
|
|
|
|
// spawn threads
|
|
|
|
|
println!("spawning up to {thread_limit} threads...");
|
|
|
|
|
let mut active_thread_count=0;
|
|
|
|
|
for _ in 0..thread_limit{
|
|
|
|
|
while active_thread_count<thread_limit{
|
|
|
|
|
if let Some(dir_entry_result)=read_dir.next(){
|
|
|
|
|
if let Some(file_path)=get_file_path(dir_entry_result?)?{
|
|
|
|
|
active_thread_count+=1;
|
|
|
|
|
|