mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'aweinstock/fix-mounting-20210316' into 'master'
Fix mounting by making deferred {pos,vel} writes optional in physics. See merge request veloren/veloren!1918
This commit is contained in:
@ -26,8 +26,8 @@ impl Component for Vel {
|
|||||||
/// Used to defer writes to Pos/Vel in nested join loops
|
/// Used to defer writes to Pos/Vel in nested join loops
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct PosVelDefer {
|
pub struct PosVelDefer {
|
||||||
pub pos: Pos,
|
pub pos: Option<Pos>,
|
||||||
pub vel: Vel,
|
pub vel: Option<Vel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for PosVelDefer {
|
impl Component for PosVelDefer {
|
||||||
|
@ -471,9 +471,10 @@ impl<'a> PhysicsData<'a> {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|(entity, pos, vel)| {
|
.for_each(|(entity, pos, vel)| {
|
||||||
let _ = write
|
let _ = write.pos_vel_defers.insert(entity, PosVelDefer {
|
||||||
.pos_vel_defers
|
pos: Some(pos),
|
||||||
.insert(entity, PosVelDefer { pos, vel });
|
vel: Some(vel),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
drop(guard);
|
drop(guard);
|
||||||
|
|
||||||
@ -580,6 +581,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
let mut land_on_ground = None;
|
let mut land_on_ground = None;
|
||||||
// Defer the writes of positions and velocities to allow an inner loop over
|
// Defer the writes of positions and velocities to allow an inner loop over
|
||||||
// terrain-like entities
|
// terrain-like entities
|
||||||
|
let old_vel = *vel;
|
||||||
let mut vel = *vel;
|
let mut vel = *vel;
|
||||||
|
|
||||||
if sticky.is_some() && physics_state.on_surface().is_some() {
|
if sticky.is_some() && physics_state.on_surface().is_some() {
|
||||||
@ -877,10 +879,17 @@ impl<'a> PhysicsData<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*pos_vel_defer = PosVelDefer {
|
if tgt_pos != pos.0 {
|
||||||
pos: Pos(tgt_pos),
|
pos_vel_defer.pos = Some(Pos(tgt_pos));
|
||||||
vel,
|
} else {
|
||||||
};
|
pos_vel_defer.pos = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if vel != old_vel {
|
||||||
|
pos_vel_defer.vel = Some(vel);
|
||||||
|
} else {
|
||||||
|
pos_vel_defer.vel = None;
|
||||||
|
}
|
||||||
|
|
||||||
land_on_ground
|
land_on_ground
|
||||||
},
|
},
|
||||||
@ -901,12 +910,16 @@ impl<'a> PhysicsData<'a> {
|
|||||||
&read.entities,
|
&read.entities,
|
||||||
&mut write.positions,
|
&mut write.positions,
|
||||||
&mut write.velocities,
|
&mut write.velocities,
|
||||||
&write.pos_vel_defers,
|
&mut write.pos_vel_defers,
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
*pos = pos_vel_defer.pos;
|
if let Some(new_pos) = pos_vel_defer.pos.take() {
|
||||||
*vel = pos_vel_defer.vel;
|
*pos = new_pos;
|
||||||
|
}
|
||||||
|
if let Some(new_vel) = pos_vel_defer.vel.take() {
|
||||||
|
*vel = new_vel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
drop(guard);
|
drop(guard);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user