From fd5d71e1af56710afb45f16a55cb5cdc33a60bda Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 18 Sep 2023 13:44:43 -0700 Subject: [PATCH] use hashset for contacts --- src/body.rs | 9 +++++++-- src/main.rs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/body.rs b/src/body.rs index 7960d246..87d69dbf 100644 --- a/src/body.rs +++ b/src/body.rs @@ -91,7 +91,8 @@ impl MouseInterpolationState { pub struct PhysicsState { pub body: Body, pub hitbox_size: glam::Vec3, - pub contacts: Vec, + pub contacts: std::collections::HashSet::, + //pub intersections: Vec, //temp pub models_cringe_clone: Vec, pub temp_control_dir: glam::Vec3, @@ -111,7 +112,7 @@ pub struct PhysicsState { pub jump_trying: bool, } -#[derive(Clone,Copy)] +#[derive(Clone,Copy,Hash,Eq,PartialEq)] pub enum AabbFace{ Right,//+X Top, @@ -256,6 +257,8 @@ impl Model { } //need non-face (full model) variant for CanCollide false objects +//OR have a separate list from contacts for model intersection +#[derive(Eq, Hash, PartialEq)] pub struct RelativeCollision { face: TreyMeshFace,//just an id model: u32,//using id to avoid lifetimes @@ -651,6 +654,7 @@ impl crate::instruction::InstructionConsumer for PhysicsStat }, _ => (), } + self.contacts.insert(c); }, PhysicsInstruction::CollisionEnd(c) => { //check ground @@ -661,6 +665,7 @@ impl crate::instruction::InstructionConsumer for PhysicsStat }, _ => (), } + self.contacts.remove(&c); }, PhysicsInstruction::StrafeTick => { //let control_dir=self.get_control_dir();//this should respect your mouse interpolation settings diff --git a/src/main.rs b/src/main.rs index 514e7e53..51f18486 100644 --- a/src/main.rs +++ b/src/main.rs @@ -304,7 +304,7 @@ impl strafe_client::framework::Example for Skybox { jump_trying: false, temp_control_dir: glam::Vec3::ZERO, walkspeed: 18.0, - contacts: Vec::::new(), + contacts: std::collections::HashSet::new(), models_cringe_clone: modeldatas.iter().map(|m|strafe_client::body::Model::new(m.transform)).collect(), walk_target_velocity: glam::Vec3::ZERO, hitbox_size: glam::vec3(2.0,5.0,2.0),