forked from StrafesNET/strafe-client
pull out collision handlers into functions
This commit is contained in:
parent
b9e34f53c3
commit
cfee6f119f
107
src/physics.rs
107
src/physics.rs
@ -634,7 +634,7 @@ pub struct ContactCollision{
|
|||||||
face_id:model_physics::MinkowskiFace,
|
face_id:model_physics::MinkowskiFace,
|
||||||
convex_mesh_id:ConvexMeshId,
|
convex_mesh_id:ConvexMeshId,
|
||||||
}
|
}
|
||||||
#[derive(Debug,Clone,Eq,Hash,PartialEq)]
|
#[derive(Debug,Clone,Copy,Eq,Hash,PartialEq)]
|
||||||
pub struct IntersectCollision{
|
pub struct IntersectCollision{
|
||||||
convex_mesh_id:ConvexMeshId,
|
convex_mesh_id:ConvexMeshId,
|
||||||
}
|
}
|
||||||
@ -1271,25 +1271,16 @@ fn run_teleport_behaviour(wormhole:&Option<gameplay_attributes::Wormhole>,models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedInstruction<PhysicsInternalInstruction>){
|
fn collision_start_contact(
|
||||||
state.time=ins.time;
|
state:&mut PhysicsState,
|
||||||
let should_advance_body=match ins.instruction{
|
data:&PhysicsData,
|
||||||
PhysicsInternalInstruction::CollisionStart(_)
|
contacting:&gameplay_attributes::ContactingAttributes,
|
||||||
|PhysicsInternalInstruction::CollisionEnd(_)
|
general:&gameplay_attributes::GeneralAttributes,
|
||||||
|PhysicsInternalInstruction::StrafeTick
|
contact:ContactCollision,
|
||||||
|PhysicsInternalInstruction::ReachWalkTargetVelocity=>true,
|
){
|
||||||
};
|
|
||||||
if should_advance_body{
|
|
||||||
state.body.advance_time(state.time);
|
|
||||||
}
|
|
||||||
match ins.instruction{
|
|
||||||
PhysicsInternalInstruction::CollisionStart(collision)=>{
|
|
||||||
let convex_mesh_id=collision.convex_mesh_id();
|
|
||||||
match (data.models.attr(convex_mesh_id.model_id),&collision){
|
|
||||||
(PhysicsCollisionAttributes::Contact{contacting,general},&Collision::Contact(contact))=>{
|
|
||||||
let incident_velocity=state.body.velocity;
|
let incident_velocity=state.body.velocity;
|
||||||
//add to touching
|
//add to touching
|
||||||
state.touching.insert(collision);
|
state.touching.insert(Collision::Contact(contact));
|
||||||
//clip v
|
//clip v
|
||||||
set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,incident_velocity);
|
set_velocity(&mut state.body,&state.touching,&data.models,&data.hitbox_mesh,incident_velocity);
|
||||||
match &contacting.contact_behaviour{
|
match &contacting.contact_behaviour{
|
||||||
@ -1324,7 +1315,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
|||||||
}
|
}
|
||||||
//I love making functions with 10 arguments to dodge the borrow checker
|
//I love making functions with 10 arguments to dodge the borrow checker
|
||||||
if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){
|
if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){
|
||||||
run_teleport_behaviour(&general.wormhole,&data.models,mode,&state.style,&data.hitbox_mesh,&mut state.mode_state,&mut state.touching,&mut state.body,convex_mesh_id);
|
run_teleport_behaviour(&general.wormhole,&data.models,mode,&state.style,&data.hitbox_mesh,&mut state.mode_state,&mut state.touching,&mut state.body,contact.convex_mesh_id);
|
||||||
}
|
}
|
||||||
if state.style.get_control(Controls::Jump,state.input_state.controls){
|
if state.style.get_control(Controls::Jump,state.input_state.controls){
|
||||||
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()){
|
||||||
@ -1351,16 +1342,23 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
|||||||
//doing enum to set the acceleration when surfing
|
//doing enum to set the acceleration when surfing
|
||||||
//doing input_and_body to refresh the walk state if you hit a wall while accelerating
|
//doing input_and_body to refresh the walk state if you hit a wall while accelerating
|
||||||
state.apply_enum_and_input_and_body(data);
|
state.apply_enum_and_input_and_body(data);
|
||||||
},
|
}
|
||||||
(PhysicsCollisionAttributes::Intersect{intersecting:_,general},Collision::Intersect(_intersect))=>{
|
|
||||||
|
fn collision_start_intersect(
|
||||||
|
state:&mut PhysicsState,
|
||||||
|
data:&PhysicsData,
|
||||||
|
intersecting:&gameplay_attributes::IntersectingAttributes,
|
||||||
|
general:&gameplay_attributes::GeneralAttributes,
|
||||||
|
intersect:IntersectCollision,
|
||||||
|
){
|
||||||
//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
|
||||||
state.touching.insert(collision);
|
state.touching.insert(Collision::Intersect(intersect));
|
||||||
//insta booster!
|
//insta booster!
|
||||||
if let Some(booster)=&general.booster{
|
if let Some(booster)=&general.booster{
|
||||||
state.cull_velocity(data,booster.boost(state.body.velocity));
|
state.cull_velocity(data,booster.boost(state.body.velocity));
|
||||||
}
|
}
|
||||||
if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){
|
if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){
|
||||||
let zone=mode.get_zone(convex_mesh_id.model_id.into());
|
let zone=mode.get_zone(intersect.convex_mesh_id.model_id.into());
|
||||||
match zone{
|
match zone{
|
||||||
Some(gameplay_modes::Zone::Start)=>{
|
Some(gameplay_modes::Zone::Start)=>{
|
||||||
println!("@@@@ Starting new run!");
|
println!("@@@@ Starting new run!");
|
||||||
@ -1375,16 +1373,18 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
|||||||
Some(gameplay_modes::Zone::Anticheat)=>state.run.flag(run::FlagReason::Anticheat),
|
Some(gameplay_modes::Zone::Anticheat)=>state.run.flag(run::FlagReason::Anticheat),
|
||||||
None=>(),
|
None=>(),
|
||||||
}
|
}
|
||||||
run_teleport_behaviour(&general.wormhole,&data.models,mode,&state.style,&data.hitbox_mesh,&mut state.mode_state,&mut state.touching,&mut state.body,convex_mesh_id);
|
run_teleport_behaviour(&general.wormhole,&data.models,mode,&state.style,&data.hitbox_mesh,&mut state.mode_state,&mut state.touching,&mut state.body,intersect.convex_mesh_id);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_=>panic!("invalid pair"),
|
|
||||||
}
|
fn collision_end_contact(
|
||||||
},
|
state:&mut PhysicsState,
|
||||||
PhysicsInternalInstruction::CollisionEnd(collision)=>{
|
data:&PhysicsData,
|
||||||
match (data.models.attr(collision.convex_mesh_id().model_id),&collision){
|
_contacting:&gameplay_attributes::ContactingAttributes,
|
||||||
(PhysicsCollisionAttributes::Contact{contacting:_,general:_},&Collision::Contact(contact))=>{
|
_general:&gameplay_attributes::GeneralAttributes,
|
||||||
state.touching.remove(&collision);//remove contact before calling contact_constrain_acceleration
|
contact:ContactCollision,
|
||||||
|
){
|
||||||
|
state.touching.remove(&Collision::Contact(contact));//remove contact before calling contact_constrain_acceleration
|
||||||
//check ground
|
//check ground
|
||||||
//TODO do better
|
//TODO do better
|
||||||
//this is inner code from state.cull_velocity
|
//this is inner code from state.cull_velocity
|
||||||
@ -1395,11 +1395,17 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
|||||||
},
|
},
|
||||||
None=>state.apply_enum_and_body(data),
|
None=>state.apply_enum_and_body(data),
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
(PhysicsCollisionAttributes::Intersect{intersecting: _,general:_},Collision::Intersect(_))=>{
|
fn collision_end_intersect(
|
||||||
state.touching.remove(&collision);
|
state:&mut PhysicsState,
|
||||||
|
data:&PhysicsData,
|
||||||
|
_intersecting:&gameplay_attributes::IntersectingAttributes,
|
||||||
|
_general:&gameplay_attributes::GeneralAttributes,
|
||||||
|
intersect:IntersectCollision,
|
||||||
|
){
|
||||||
|
state.touching.remove(&Collision::Intersect(intersect));
|
||||||
if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){
|
if let Some(mode)=data.modes.get_mode(state.mode_state.get_mode_id()){
|
||||||
let zone=mode.get_zone(collision.convex_mesh_id().model_id.into());
|
let zone=mode.get_zone(intersect.convex_mesh_id.model_id.into());
|
||||||
match zone{
|
match zone{
|
||||||
Some(gameplay_modes::Zone::Start)=>{
|
Some(gameplay_modes::Zone::Start)=>{
|
||||||
match state.run.start(state.time){
|
match state.run.start(state.time){
|
||||||
@ -1410,7 +1416,34 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim
|
|||||||
_=>(),
|
_=>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedInstruction<PhysicsInternalInstruction>){
|
||||||
|
state.time=ins.time;
|
||||||
|
let should_advance_body=match ins.instruction{
|
||||||
|
PhysicsInternalInstruction::CollisionStart(_)
|
||||||
|
|PhysicsInternalInstruction::CollisionEnd(_)
|
||||||
|
|PhysicsInternalInstruction::StrafeTick
|
||||||
|
|PhysicsInternalInstruction::ReachWalkTargetVelocity=>true,
|
||||||
|
};
|
||||||
|
if should_advance_body{
|
||||||
|
state.body.advance_time(state.time);
|
||||||
|
}
|
||||||
|
match ins.instruction{
|
||||||
|
PhysicsInternalInstruction::CollisionStart(collision)=>{
|
||||||
|
match (data.models.attr(collision.convex_mesh_id().model_id),&collision){
|
||||||
|
(PhysicsCollisionAttributes::Contact{contacting,general},&Collision::Contact(contact))=>
|
||||||
|
collision_start_contact(state,data,contacting,general,contact),
|
||||||
|
(PhysicsCollisionAttributes::Intersect{intersecting,general},&Collision::Intersect(intersect))=>
|
||||||
|
collision_start_intersect(state,data,intersecting,general,intersect),
|
||||||
|
_=>panic!("invalid pair"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PhysicsInternalInstruction::CollisionEnd(collision)=>{
|
||||||
|
match (data.models.attr(collision.convex_mesh_id().model_id),&collision){
|
||||||
|
(PhysicsCollisionAttributes::Contact{contacting,general},&Collision::Contact(contact))=>
|
||||||
|
collision_end_contact(state,data,contacting,general,contact),
|
||||||
|
(PhysicsCollisionAttributes::Intersect{intersecting,general},&Collision::Intersect(intersect))=>
|
||||||
|
collision_end_intersect(state,data,intersecting,general,intersect),
|
||||||
_=>panic!("invalid pair"),
|
_=>panic!("invalid pair"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user