Addressed review issues, added cloning docs to BodySpec::Manifests

This commit is contained in:
Joshua Barretto 2021-11-13 17:20:23 +00:00
parent 0f56ebe82b
commit c0bf9503bd
5 changed files with 22 additions and 28 deletions

View File

@ -3657,6 +3657,7 @@ LillyPads: Some((
), ),
], ],
wind_sway: 0.6, wind_sway: 0.6,
)),
Bomb: Some(( Bomb: Some((
variations: [ variations: [
( (

View File

@ -224,15 +224,8 @@ 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 {
<<<<<<< HEAD
Collider::CapsulePrism { radius, .. } => radius * scale, Collider::CapsulePrism { radius, .. } => radius * scale,
Collider::Voxel { .. } | Collider::Point => flat_radius, Collider::Voxel { .. } | Collider::Volume(_) | Collider::Point => flat_radius,
=======
Some(Collider::CapsulePrism { radius, .. }) => radius * scale,
Some(Collider::Voxel { .. } | Collider::Volume(_) | Collider::Point) | None => {
flat_radius
},
>>>>>>> 51f014dd3 (Arbitrary volume airships)
}; };
phys_cache.neighborhood_radius = neighborhood_radius; phys_cache.neighborhood_radius = neighborhood_radius;
@ -272,11 +265,7 @@ impl<'a> PhysicsData<'a> {
Some((p0, p1)) Some((p0, p1))
} }
}, },
<<<<<<< HEAD Collider::Voxel { .. } | Collider::Volume(_) | Collider::Point => None,
Collider::Voxel { .. } | Collider::Point => None,
=======
Some(Collider::Voxel { .. } | Collider::Volume(_) | Collider::Point) | None => None,
>>>>>>> 51f014dd3 (Arbitrary volume airships)
}; };
phys_cache.origins = origins; phys_cache.origins = origins;
phys_cache.ori = ori; phys_cache.ori = ori;
@ -519,6 +508,9 @@ impl<'a> PhysicsData<'a> {
ref read, ref read,
ref write, ref write,
} = self; } = self;
let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read();
// NOTE: i32 places certain constraints on how far out collision works // NOTE: i32 places certain constraints on how far out collision works
// NOTE: uses the radius of the entity and their current position rather than // NOTE: uses the radius of the entity and their current position rather than
// the radius of their bounding sphere for the current frame of movement // the radius of their bounding sphere for the current frame of movement
@ -538,7 +530,6 @@ impl<'a> PhysicsData<'a> {
) )
.join() .join()
{ {
let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read();
let vol = match collider { let vol = match collider {
Collider::Voxel { id } => voxel_colliders_manifest.colliders.get(&*id), Collider::Voxel { id } => voxel_colliders_manifest.colliders.get(&*id),
Collider::Volume(vol) => Some(&**vol), Collider::Volume(vol) => Some(&**vol),
@ -1016,6 +1007,8 @@ impl<'a> PhysicsData<'a> {
let query_center = path_sphere.center.xy(); let query_center = path_sphere.center.xy();
let query_radius = path_sphere.radius; let query_radius = path_sphere.radius;
let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read();
voxel_collider_spatial_grid voxel_collider_spatial_grid
.in_circle_aabr(query_center, query_radius) .in_circle_aabr(query_center, query_radius)
.filter_map(|entity| { .filter_map(|entity| {
@ -1042,7 +1035,6 @@ impl<'a> PhysicsData<'a> {
return; return;
} }
let voxel_colliders_manifest = VOXEL_COLLIDER_MANIFEST.read();
let voxel_collider = match collider_other { let voxel_collider = match collider_other {
Collider::Voxel { id } => { Collider::Voxel { id } => {
voxel_colliders_manifest.colliders.get(id) voxel_colliders_manifest.colliders.get(id)
@ -1859,8 +1851,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
&& !collider_other.map_or(false, |c| c.is_voxel()) && !collider_other.is_voxel()
&& !collider.map_or(false, |c| c.is_voxel()) && !collider.is_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);

View File

@ -893,7 +893,7 @@ pub fn handle_bonk(server: &mut Server, pos: Vec3<f32>, owner: Option<Uid>, targ
{ {
drop(terrain); drop(terrain);
drop(block_change); drop(block_change);
let mut entity = server server
.state .state
.create_object(Default::default(), match block.get_sprite() { .create_object(Default::default(), match block.get_sprite() {
// Create different containers depending on the original sprite // Create different containers depending on the original sprite
@ -904,14 +904,12 @@ pub fn handle_bonk(server: &mut Server, pos: Vec3<f32>, owner: Option<Uid>, targ
_ => comp::object::Body::Pouch, _ => comp::object::Body::Pouch,
}) })
.with(comp::Pos(pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0))) .with(comp::Pos(pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0)))
.with(item); .with(item)
.maybe_with(match block.get_sprite() {
entity = match block.get_sprite() { Some(SpriteKind::Bomb) => Some(comp::Object::Bomb { owner }),
Some(SpriteKind::Bomb) => entity.with(comp::Object::Bomb { owner }), _ => None,
_ => entity, })
}; .build();
entity.build();
} }
}; };
} }

View File

@ -87,6 +87,8 @@ fn recolor_grey(rgb: Rgb<u8>, color: Rgb<u8>) -> Rgb<u8> {
/// A set of reloadable specifications for a Body. /// A set of reloadable specifications for a Body.
pub trait BodySpec: Sized { pub trait BodySpec: Sized {
type Spec; type Spec;
/// Cloned on each cache invalidation. If this type is expensive to clone,
/// place it behind an [`Arc`].
type Manifests: Send + Sync + Clone; type Manifests: Send + Sync + Clone;
type Extra: Send + Sync; type Extra: Send + Sync;

View File

@ -4822,8 +4822,9 @@ impl FigureMgr {
&slow_jobs, &slow_jobs,
) )
} else { } else {
println!("Cannot determine model"); // No way to determine model (this is okay, we might just not have received
// No way to determine model // the `Collider` for the entity yet. Wait until the
// next tick.
break; break;
}; };