(Wiring) Change Sticky to be handled by physics (but with disabled force on it)

This commit is contained in:
Daniel Mizerski 2021-05-03 09:50:24 +02:00
parent f5c7f99846
commit f1681f465f
2 changed files with 13 additions and 6 deletions

View File

@ -271,6 +271,7 @@ impl<'a> PhysicsData<'a> {
spatial_grid spatial_grid
} }
#[allow(clippy::nonminimal_bool)]
fn apply_pushback(&mut self, job: &mut Job<Sys>, spatial_grid: &SpatialGrid) { fn apply_pushback(&mut self, job: &mut Job<Sys>, spatial_grid: &SpatialGrid) {
span!(_guard, "Apply pushback"); span!(_guard, "Apply pushback");
job.cpu_stats.measure(ParMode::Rayon); job.cpu_stats.measure(ParMode::Rayon);
@ -295,10 +296,9 @@ impl<'a> PhysicsData<'a> {
read.char_states.maybe(), read.char_states.maybe(),
) )
.par_join() .par_join()
.filter(|(_, _, _, _, _, _, _, sticky, physics, _, _)| { .map(|(e, p, v, vd, m, c, _, sticky, ph, pr, c_s)| {
sticky.is_none() || (physics.on_wall.is_none() && !physics.on_ground) (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( .map_init(
|| { || {
prof_span!(guard, "physics e<>e rayon job"); prof_span!(guard, "physics e<>e rayon job");
@ -312,10 +312,13 @@ impl<'a> PhysicsData<'a> {
previous_cache, previous_cache,
mass, mass,
collider, collider,
sticky,
physics, physics,
projectile, projectile,
char_state_maybe, 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_collision_checks = 0;
let mut entity_entity_collisions = 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 // with a terrain-like entity, or if we are a
// terrain-like // terrain-like
// entity // 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 && !is_projectile
&& !matches!( && !matches!(
collider_other, collider_other,

View File

@ -1716,7 +1716,6 @@ fn handle_spawn_wiring(
// Obviously it is a WIP - use it for debug // Obviously it is a WIP - use it for debug
let mut pos = position(server, target, "target")?; let mut pos = position(server, target, "target")?;
pos.0.z += 1.0;
pos.0.x += 3.0; pos.0.x += 3.0;
let mut outputs1 = HashMap::new(); let mut outputs1 = HashMap::new();
@ -1744,7 +1743,8 @@ fn handle_spawn_wiring(
}], }],
inputs: HashMap::new(), inputs: HashMap::new(),
outputs: outputs1, outputs: outputs1,
}); })
.with(comp::Sticky);
let ent1 = builder1.build(); let ent1 = builder1.build();
pos.0.x += 3.0; pos.0.x += 3.0;