From f1681f465f044dc0b16c68d9af7d2423ce36ee97 Mon Sep 17 00:00:00 2001 From: Daniel Mizerski Date: Mon, 3 May 2021 09:50:24 +0200 Subject: [PATCH] (Wiring) Change Sticky to be handled by physics (but with disabled force on it) --- common/systems/src/phys.rs | 15 +++++++++++---- server/src/cmd.rs | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/systems/src/phys.rs b/common/systems/src/phys.rs index c83d6861e9..65cddd045d 100644 --- a/common/systems/src/phys.rs +++ b/common/systems/src/phys.rs @@ -271,6 +271,7 @@ impl<'a> PhysicsData<'a> { spatial_grid } + #[allow(clippy::nonminimal_bool)] fn apply_pushback(&mut self, job: &mut Job, spatial_grid: &SpatialGrid) { span!(_guard, "Apply pushback"); job.cpu_stats.measure(ParMode::Rayon); @@ -295,10 +296,9 @@ impl<'a> PhysicsData<'a> { read.char_states.maybe(), ) .par_join() - .filter(|(_, _, _, _, _, _, _, sticky, physics, _, _)| { - sticky.is_none() || (physics.on_wall.is_none() && !physics.on_ground) + .map(|(e, p, v, vd, m, c, _, sticky, ph, pr, c_s)| { + (e, p, v, vd, m, c, sticky, ph, pr, c_s) }) - .map(|(e, p, v, vd, m, c, _, _, ph, pr, c_s)| (e, p, v, vd, m, c, ph, pr, c_s)) .map_init( || { prof_span!(guard, "physics e<>e rayon job"); @@ -312,10 +312,13 @@ impl<'a> PhysicsData<'a> { previous_cache, mass, collider, + sticky, physics, projectile, char_state_maybe, )| { + let is_sticky = sticky.is_some(); + let is_mid_air = physics.on_wall.is_none() && physics.on_ground; let mut entity_entity_collision_checks = 0; let mut entity_entity_collisions = 0; @@ -427,7 +430,11 @@ impl<'a> PhysicsData<'a> { // with a terrain-like entity, or if we are a // terrain-like // entity - if diff.magnitude_squared() > 0.0 + // + // Don't apply force when entity is a sticky which is on the + // ground (or on the wall) + if !(is_sticky && !is_mid_air) + && diff.magnitude_squared() > 0.0 && !is_projectile && !matches!( collider_other, diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 48a663ca13..f3370560bf 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1716,7 +1716,6 @@ fn handle_spawn_wiring( // Obviously it is a WIP - use it for debug let mut pos = position(server, target, "target")?; - pos.0.z += 1.0; pos.0.x += 3.0; let mut outputs1 = HashMap::new(); @@ -1744,7 +1743,8 @@ fn handle_spawn_wiring( }], inputs: HashMap::new(), outputs: outputs1, - }); + }) + .with(comp::Sticky); let ent1 = builder1.build(); pos.0.x += 3.0;