diff --git a/Cargo.lock b/Cargo.lock index 1a6bb54a..0624781f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,7 +234,7 @@ checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9" [[package]] name = "godot" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#3148d7b6028fc59a9a14e924acc342378b7d4a73" +source = "git+https://github.com/godot-rust/gdext?branch=master#a20bb8595c06ade1ff0cf0a0bd2fe31624206040" dependencies = [ "godot-core", "godot-macros", @@ -243,7 +243,7 @@ dependencies = [ [[package]] name = "godot-bindings" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#3148d7b6028fc59a9a14e924acc342378b7d4a73" +source = "git+https://github.com/godot-rust/gdext?branch=master#a20bb8595c06ade1ff0cf0a0bd2fe31624206040" dependencies = [ "gdextension-api", ] @@ -251,12 +251,12 @@ dependencies = [ [[package]] name = "godot-cell" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#3148d7b6028fc59a9a14e924acc342378b7d4a73" +source = "git+https://github.com/godot-rust/gdext?branch=master#a20bb8595c06ade1ff0cf0a0bd2fe31624206040" [[package]] name = "godot-codegen" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#3148d7b6028fc59a9a14e924acc342378b7d4a73" +source = "git+https://github.com/godot-rust/gdext?branch=master#a20bb8595c06ade1ff0cf0a0bd2fe31624206040" dependencies = [ "godot-bindings", "heck", @@ -269,7 +269,7 @@ dependencies = [ [[package]] name = "godot-core" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#3148d7b6028fc59a9a14e924acc342378b7d4a73" +source = "git+https://github.com/godot-rust/gdext?branch=master#a20bb8595c06ade1ff0cf0a0bd2fe31624206040" dependencies = [ "glam", "godot-bindings", @@ -282,7 +282,7 @@ dependencies = [ [[package]] name = "godot-ffi" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#3148d7b6028fc59a9a14e924acc342378b7d4a73" +source = "git+https://github.com/godot-rust/gdext?branch=master#a20bb8595c06ade1ff0cf0a0bd2fe31624206040" dependencies = [ "gensym", "godot-bindings", @@ -294,7 +294,7 @@ dependencies = [ [[package]] name = "godot-macros" version = "0.1.3" -source = "git+https://github.com/godot-rust/gdext?branch=master#3148d7b6028fc59a9a14e924acc342378b7d4a73" +source = "git+https://github.com/godot-rust/gdext?branch=master#a20bb8595c06ade1ff0cf0a0bd2fe31624206040" dependencies = [ "godot-bindings", "proc-macro2", @@ -975,9 +975,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "spade" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d676a3ce6cfd1e455199fefcf82db082f970872ce017df660f076a4e07a0d64" +checksum = "766195f983f4098dc3bf37fb66bd609f6e6258c4b8db684d05252b2c694cdbcd" dependencies = [ "hashbrown", "num-traits", diff --git a/src/rapier_wrapper/physics_hooks.rs b/src/rapier_wrapper/physics_hooks.rs index 8daceb8b..ff353baf 100644 --- a/src/rapier_wrapper/physics_hooks.rs +++ b/src/rapier_wrapper/physics_hooks.rs @@ -2,7 +2,6 @@ use rapier::prelude::*; use crate::rapier_wrapper::prelude::*; use crate::servers::rapier_physics_singleton::PhysicsCollisionObjects; -use crate::spaces::rapier_space::RapierSpace; #[derive(Default)] pub struct OneWayDirection { pub body1: bool, @@ -28,6 +27,7 @@ pub struct PhysicsHooksCollisionFilter<'a> { pub collision_filter_body_callback: &'a CollisionFilterCallback, pub collision_modify_contacts_callback: &'a CollisionModifyContactsCallback, pub physics_collision_objects: &'a PhysicsCollisionObjects, + pub last_step: Real, } impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { fn filter_contact_pair(&self, context: &PairFilterContext) -> Option { @@ -81,7 +81,6 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { if let Some(contact) = context.manifold.find_deepest_contact() { dist = -contact.dist; } - let last_step = RapierSpace::get_last_step(); let rigid_body_1_linvel = one_way_direction.previous_linear_velocity1; let rigid_body_2_linvel = one_way_direction.previous_linear_velocity2; // ghost collisions @@ -91,7 +90,7 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { return; } let normal_dot_velocity = normal.dot(&rigid_body_1_linvel.normalize()); - let velocity_magnitude = rigid_body_1_linvel.magnitude() * last_step; + let velocity_magnitude = rigid_body_1_linvel.magnitude() * self.last_step; let length_along_normal = velocity_magnitude * Real::max(normal_dot_velocity, 0.0); if normal_dot_velocity >= -DEFAULT_EPSILON { let diff = dist - length_along_normal; @@ -110,7 +109,7 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { return; } let normal_dot_velocity = normal.dot(&rigid_body_2_linvel.normalize()); - let velocity_magnitude = rigid_body_2_linvel.magnitude() * last_step; + let velocity_magnitude = rigid_body_2_linvel.magnitude() * self.last_step; let length_along_normal = velocity_magnitude * Real::max(normal_dot_velocity, 0.0); if normal_dot_velocity >= -DEFAULT_EPSILON { let diff = dist - length_along_normal; @@ -129,7 +128,7 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { let body_margin1 = one_way_direction.pixel_body1_margin; let motion_len = rigid_body_2_linvel.magnitude(); let velocity_dot1 = rigid_body_2_linvel.normalize().dot(&allowed_local_n1); - let length_along_normal = motion_len * Real::max(velocity_dot1, 0.0) * last_step; + let length_along_normal = motion_len * Real::max(velocity_dot1, 0.0) * self.last_step; contact_is_pass_through |= velocity_dot1 <= DEFAULT_EPSILON && dist - length_along_normal > body_margin1 && length_along_normal > DEFAULT_EPSILON; @@ -137,7 +136,7 @@ impl<'a> PhysicsHooks for PhysicsHooksCollisionFilter<'a> { let velocity_dot2 = rigid_body_1_linvel.normalize().dot(&allowed_local_n2); let motion_len = rigid_body_1_linvel.magnitude(); let body_margin2 = one_way_direction.pixel_body2_margin; - let length_along_normal = motion_len * Real::max(velocity_dot2, 0.0) * last_step; + let length_along_normal = motion_len * Real::max(velocity_dot2, 0.0) * self.last_step; contact_is_pass_through |= velocity_dot2 <= DEFAULT_EPSILON && dist - length_along_normal > body_margin2 && length_along_normal > DEFAULT_EPSILON; diff --git a/src/rapier_wrapper/physics_world.rs b/src/rapier_wrapper/physics_world.rs index 7a10f617..5aa9a415 100644 --- a/src/rapier_wrapper/physics_world.rs +++ b/src/rapier_wrapper/physics_world.rs @@ -163,6 +163,7 @@ impl PhysicsWorld { collision_filter_body_callback: &collision_filter_body_callback, collision_modify_contacts_callback: &collision_modify_contacts_callback, physics_collision_objects, + last_step: RapierSpace::get_last_step(), }; // Initialize the event collector. let (collision_send, collision_recv) = crossbeam::channel::unbounded();