mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'socksonme/pushback_require_collider' into 'master'
Make the collider component be required for entity pushback See merge request veloren/veloren!2954
This commit is contained in:
commit
79afad626b
@ -2,8 +2,8 @@ use common::{
|
|||||||
comp::{
|
comp::{
|
||||||
body::ship::figuredata::{VoxelCollider, VOXEL_COLLIDER_MANIFEST},
|
body::ship::figuredata::{VoxelCollider, VOXEL_COLLIDER_MANIFEST},
|
||||||
fluid_dynamics::{Fluid, LiquidKind, Wings},
|
fluid_dynamics::{Fluid, LiquidKind, Wings},
|
||||||
BeamSegment, Body, CharacterState, Collider, Density, Mass, Mounting, Ori, PhysicsState,
|
Body, CharacterState, Collider, Density, Mass, Mounting, Ori, PhysicsState, Pos,
|
||||||
Pos, PosVelOriDefer, PreviousPhysCache, Projectile, Scale, Shockwave, Stats, Sticky, Vel,
|
PosVelOriDefer, PreviousPhysCache, Projectile, Scale, Stats, Sticky, Vel,
|
||||||
},
|
},
|
||||||
consts::{AIR_DENSITY, FRIC_GROUND, GRAVITY},
|
consts::{AIR_DENSITY, FRIC_GROUND, GRAVITY},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
@ -87,18 +87,13 @@ fn integrate_forces(
|
|||||||
vel
|
vel
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calc_z_limit(
|
fn calc_z_limit(char_state_maybe: Option<&CharacterState>, collider: &Collider) -> (f32, f32) {
|
||||||
char_state_maybe: Option<&CharacterState>,
|
|
||||||
collider: Option<&Collider>,
|
|
||||||
) -> (f32, f32) {
|
|
||||||
let modifier = if char_state_maybe.map_or(false, |c_s| c_s.is_dodge() || c_s.is_glide()) {
|
let modifier = if char_state_maybe.map_or(false, |c_s| c_s.is_dodge() || c_s.is_glide()) {
|
||||||
0.5
|
0.5
|
||||||
} else {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
};
|
};
|
||||||
collider
|
collider.get_z_limits(modifier)
|
||||||
.map(|c| c.get_z_limits(modifier))
|
|
||||||
.unwrap_or((-0.5 * modifier, 0.5 * modifier))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This system applies forces and calculates new positions and velocities.
|
/// This system applies forces and calculates new positions and velocities.
|
||||||
@ -118,8 +113,6 @@ pub struct PhysicsRead<'a> {
|
|||||||
colliders: ReadStorage<'a, Collider>,
|
colliders: ReadStorage<'a, Collider>,
|
||||||
mountings: ReadStorage<'a, Mounting>,
|
mountings: ReadStorage<'a, Mounting>,
|
||||||
projectiles: ReadStorage<'a, Projectile>,
|
projectiles: ReadStorage<'a, Projectile>,
|
||||||
beams: ReadStorage<'a, BeamSegment>,
|
|
||||||
shockwaves: ReadStorage<'a, Shockwave>,
|
|
||||||
char_states: ReadStorage<'a, CharacterState>,
|
char_states: ReadStorage<'a, CharacterState>,
|
||||||
bodies: ReadStorage<'a, Body>,
|
bodies: ReadStorage<'a, Body>,
|
||||||
character_states: ReadStorage<'a, CharacterState>,
|
character_states: ReadStorage<'a, CharacterState>,
|
||||||
@ -172,15 +165,14 @@ impl<'a> PhysicsData<'a> {
|
|||||||
// Add PreviousPhysCache for all relevant entities
|
// Add PreviousPhysCache for all relevant entities
|
||||||
for entity in (
|
for entity in (
|
||||||
&self.read.entities,
|
&self.read.entities,
|
||||||
|
&self.read.colliders,
|
||||||
&self.write.velocities,
|
&self.write.velocities,
|
||||||
&self.write.positions,
|
&self.write.positions,
|
||||||
!&self.write.previous_phys_cache,
|
!&self.write.previous_phys_cache,
|
||||||
!&self.read.mountings,
|
!&self.read.mountings,
|
||||||
!&self.read.beams,
|
|
||||||
!&self.read.shockwaves,
|
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
.map(|(e, _, _, _, _, _, _)| e)
|
.map(|(e, _, _, _, _, _)| e)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
{
|
{
|
||||||
let _ = self
|
let _ = self
|
||||||
@ -200,18 +192,16 @@ impl<'a> PhysicsData<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update PreviousPhysCache
|
// Update PreviousPhysCache
|
||||||
for (_, vel, position, ori, mut phys_cache, collider, scale, cs, _, _, _) in (
|
for (_, vel, position, ori, mut phys_cache, collider, scale, cs, _) in (
|
||||||
&self.read.entities,
|
&self.read.entities,
|
||||||
&self.write.velocities,
|
&self.write.velocities,
|
||||||
&self.write.positions,
|
&self.write.positions,
|
||||||
&self.write.orientations,
|
&self.write.orientations,
|
||||||
&mut self.write.previous_phys_cache,
|
&mut self.write.previous_phys_cache,
|
||||||
self.read.colliders.maybe(),
|
&self.read.colliders,
|
||||||
self.read.scales.maybe(),
|
self.read.scales.maybe(),
|
||||||
self.read.char_states.maybe(),
|
self.read.char_states.maybe(),
|
||||||
!&self.read.mountings,
|
!&self.read.mountings,
|
||||||
!&self.read.beams,
|
|
||||||
!&self.read.shockwaves,
|
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
@ -223,7 +213,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
|
|
||||||
phys_cache.velocity_dt = vel.0 * self.read.dt.0;
|
phys_cache.velocity_dt = vel.0 * self.read.dt.0;
|
||||||
let entity_center = position.0 + Vec3::new(0.0, 0.0, z_min + half_height);
|
let entity_center = position.0 + Vec3::new(0.0, 0.0, z_min + half_height);
|
||||||
let flat_radius = collider.map_or(0.5, Collider::bounding_radius) * scale;
|
let flat_radius = collider.bounding_radius() * scale;
|
||||||
let radius = (flat_radius.powi(2) + half_height.powi(2)).sqrt();
|
let radius = (flat_radius.powi(2) + half_height.powi(2)).sqrt();
|
||||||
|
|
||||||
// Move center to the middle between OLD and OLD+VEL_DT
|
// Move center to the middle between OLD and OLD+VEL_DT
|
||||||
@ -234,14 +224,14 @@ impl<'a> PhysicsData<'a> {
|
|||||||
phys_cache.scaled_radius = flat_radius;
|
phys_cache.scaled_radius = flat_radius;
|
||||||
|
|
||||||
let neighborhood_radius = match collider {
|
let neighborhood_radius = match collider {
|
||||||
Some(Collider::CapsulePrism { radius, .. }) => radius * scale,
|
Collider::CapsulePrism { radius, .. } => radius * scale,
|
||||||
Some(Collider::Voxel { .. } | Collider::Point) | None => flat_radius,
|
Collider::Voxel { .. } | Collider::Point => flat_radius,
|
||||||
};
|
};
|
||||||
phys_cache.neighborhood_radius = neighborhood_radius;
|
phys_cache.neighborhood_radius = neighborhood_radius;
|
||||||
|
|
||||||
let ori = ori.to_quat();
|
let ori = ori.to_quat();
|
||||||
let origins = match collider {
|
let origins = match collider {
|
||||||
Some(Collider::CapsulePrism { p0, p1, .. }) => {
|
Collider::CapsulePrism { p0, p1, .. } => {
|
||||||
let a = p1 - p0;
|
let a = p1 - p0;
|
||||||
let len = a.magnitude();
|
let len = a.magnitude();
|
||||||
// If origins are close enough, our capsule prism is cylinder
|
// If origins are close enough, our capsule prism is cylinder
|
||||||
@ -275,7 +265,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
Some((p0, p1))
|
Some((p0, p1))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(Collider::Voxel { .. } | Collider::Point) | None => None,
|
Collider::Voxel { .. } | Collider::Point => None,
|
||||||
};
|
};
|
||||||
phys_cache.origins = origins;
|
phys_cache.origins = origins;
|
||||||
phys_cache.ori = ori;
|
phys_cache.ori = ori;
|
||||||
@ -302,15 +292,14 @@ impl<'a> PhysicsData<'a> {
|
|||||||
let lg2_large_cell_size = 6;
|
let lg2_large_cell_size = 6;
|
||||||
let radius_cutoff = 8;
|
let radius_cutoff = 8;
|
||||||
let mut spatial_grid = SpatialGrid::new(lg2_cell_size, lg2_large_cell_size, radius_cutoff);
|
let mut spatial_grid = SpatialGrid::new(lg2_cell_size, lg2_large_cell_size, radius_cutoff);
|
||||||
for (entity, pos, phys_cache, _, _, _, _, _) in (
|
for (entity, pos, phys_cache, _, _, _, _) in (
|
||||||
&read.entities,
|
&read.entities,
|
||||||
&write.positions,
|
&write.positions,
|
||||||
&write.previous_phys_cache,
|
&write.previous_phys_cache,
|
||||||
write.velocities.mask(),
|
write.velocities.mask(),
|
||||||
!&read.projectiles, // Not needed because they are skipped in the inner loop below
|
!&read.projectiles, // Not needed because they are skipped in the inner loop below
|
||||||
!&read.mountings,
|
!&read.mountings,
|
||||||
!&read.beams,
|
read.colliders.mask(),
|
||||||
!&read.shockwaves,
|
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
@ -338,7 +327,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
&mut write.velocities,
|
&mut write.velocities,
|
||||||
previous_phys_cache,
|
previous_phys_cache,
|
||||||
&read.masses,
|
&read.masses,
|
||||||
read.colliders.maybe(),
|
&read.colliders,
|
||||||
!&read.mountings,
|
!&read.mountings,
|
||||||
read.stickies.maybe(),
|
read.stickies.maybe(),
|
||||||
&mut write.physics_states,
|
&mut write.physics_states,
|
||||||
@ -405,6 +394,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
let pos = positions.get(entity)?;
|
let pos = positions.get(entity)?;
|
||||||
let previous_cache = previous_phys_cache.get(entity)?;
|
let previous_cache = previous_phys_cache.get(entity)?;
|
||||||
let mass = read.masses.get(entity)?;
|
let mass = read.masses.get(entity)?;
|
||||||
|
let collider = read.colliders.get(entity)?;
|
||||||
|
|
||||||
Some((
|
Some((
|
||||||
entity,
|
entity,
|
||||||
@ -412,7 +402,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
pos,
|
pos,
|
||||||
previous_cache,
|
previous_cache,
|
||||||
mass,
|
mass,
|
||||||
read.colliders.get(entity),
|
collider,
|
||||||
read.char_states.get(entity),
|
read.char_states.get(entity),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@ -993,7 +983,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
let path_sphere = {
|
let path_sphere = {
|
||||||
// TODO: duplicated with maintain_pushback_cache,
|
// TODO: duplicated with maintain_pushback_cache,
|
||||||
// make a common function to call to compute all this info?
|
// make a common function to call to compute all this info?
|
||||||
let z_limits = calc_z_limit(character_state, Some(collider));
|
let z_limits = calc_z_limit(character_state, collider);
|
||||||
let z_limits = (z_limits.0 * scale, z_limits.1 * scale);
|
let z_limits = (z_limits.0 * scale, z_limits.1 * scale);
|
||||||
let half_height = (z_limits.1 - z_limits.0) / 2.0;
|
let half_height = (z_limits.1 - z_limits.0) / 2.0;
|
||||||
|
|
||||||
@ -1782,8 +1772,8 @@ fn resolve_e2e_collision(
|
|||||||
previous_cache_other: &PreviousPhysCache,
|
previous_cache_other: &PreviousPhysCache,
|
||||||
z_limits: (f32, f32),
|
z_limits: (f32, f32),
|
||||||
z_limits_other: (f32, f32),
|
z_limits_other: (f32, f32),
|
||||||
collider: Option<&Collider>,
|
collider: &Collider,
|
||||||
collider_other: Option<&Collider>,
|
collider_other: &Collider,
|
||||||
mass: Mass,
|
mass: Mass,
|
||||||
mass_other: Mass,
|
mass_other: Mass,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
@ -1855,8 +1845,8 @@ fn resolve_e2e_collision(
|
|||||||
&& (!is_sticky || is_mid_air)
|
&& (!is_sticky || is_mid_air)
|
||||||
&& diff.magnitude_squared() > 0.0
|
&& diff.magnitude_squared() > 0.0
|
||||||
&& !is_projectile
|
&& !is_projectile
|
||||||
&& !matches!(collider_other, Some(Collider::Voxel { .. }))
|
&& !matches!(collider_other, Collider::Voxel { .. })
|
||||||
&& !matches!(collider, Some(Collider::Voxel { .. }))
|
&& !matches!(collider, Collider::Voxel { .. })
|
||||||
{
|
{
|
||||||
const ELASTIC_FORCE_COEFFICIENT: f32 = 400.0;
|
const ELASTIC_FORCE_COEFFICIENT: f32 = 400.0;
|
||||||
let mass_coefficient = mass_other.0 / (mass.0 + mass_other.0);
|
let mass_coefficient = mass_other.0 / (mass.0 + mass_other.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user