diff --git a/crates/bvh-region/src/lib.rs b/crates/bvh-region/src/lib.rs index 05f256df..b0fff3f3 100644 --- a/crates/bvh-region/src/lib.rs +++ b/crates/bvh-region/src/lib.rs @@ -18,9 +18,9 @@ use glam::Vec3; const ELEMENTS_TO_ACTIVATE_LEAF: usize = 16; const VOLUME_TO_ACTIVATE_LEAF: f32 = 5.0; -pub trait GetAabb: Sync + Fn(&T) -> Aabb {} +pub trait GetAabb: Fn(&T) -> Aabb {} -impl GetAabb for F where F: Fn(&T) -> Aabb + Sync {} +impl GetAabb for F where F: Fn(&T) -> Aabb {} #[cfg(feature = "plot")] pub mod plot; @@ -121,7 +121,7 @@ fn thread_count_pow2() -> usize { impl Bvh { #[tracing::instrument(skip_all, fields(elements_len = elements.len()))] - pub fn build(mut elements: Vec, get_aabb: &impl GetAabb) -> Self { + pub fn build(mut elements: Vec, get_aabb: &(impl GetAabb + Sync)) -> Self { let max_threads = thread_count_pow2(); let len = elements.len(); @@ -251,7 +251,7 @@ impl Bvh { pub fn get_collisions<'a>( &'a self, target: Aabb, - get_aabb: &'a impl GetAabb, + get_aabb: impl GetAabb + 'a, ) -> impl Iterator + 'a { BvhIter::consume(self, target, get_aabb) } @@ -411,7 +411,7 @@ impl BvhNode { max_threads: usize, nodes_idx: usize, nodes: &mut [Self], - get_aabb: &impl GetAabb, + get_aabb: &(impl GetAabb + Sync), ) -> (i32, usize) where T: Send + Copy + Sync + Debug, @@ -519,7 +519,7 @@ impl<'a, T> BvhIter<'a, T> { fn consume( bvh: &'a Bvh, target: Aabb, - get_aabb: &'a impl GetAabb, + get_aabb: impl GetAabb + 'a, ) -> Box + 'a> { let root = bvh.root(); @@ -549,7 +549,7 @@ impl<'a, T> BvhIter<'a, T> { pub fn process( self, on: &'a BvhNode, - get_aabb: &'a impl GetAabb, + get_aabb: impl GetAabb, ) -> impl Iterator { gen move { let mut stack: ArrayVec<&'a BvhNode, 64> = ArrayVec::new(); diff --git a/crates/spatial/src/lib.rs b/crates/spatial/src/lib.rs index 4569f3d8..43e2458a 100644 --- a/crates/spatial/src/lib.rs +++ b/crates/spatial/src/lib.rs @@ -46,14 +46,14 @@ impl SpatialIndex { self.query = bvh_region::Bvh::build::(all_entities, &get_aabb); } - // pub fn get_collisions<'a>( - // &'a self, - // target: Aabb, - // world: &'a World, - // ) -> impl Iterator + 'a { - // let get_aabb = get_aabb_func(world); - // self.query.get_collisions(target, get_aabb).copied() - // } + pub fn get_collisions<'a>( + &'a self, + target: Aabb, + world: &'a World, + ) -> impl Iterator + 'a { + let get_aabb = get_aabb_func(world); + self.query.get_collisions(target, get_aabb).copied() + } /// Get the closest player to the given position. #[must_use] @@ -63,7 +63,7 @@ impl SpatialIndex { Some(world.entity_from_id(*target)) } } -// + /// If we want the entity to be spatially indexed, we need to add this component. #[derive(Component)] pub struct Spatial;