pub(super) struct TileGrid {
tiles: AHashMap<IVec2, AHashSet<Entity>>,
}
Expand description
Rectangular (2D) grid of sets of Bevy ECS entities.
Only non-empty sets are kept (a hash map mapping 2D tile coordinates to Entity sets is used under the hood). Each set contains entities whose absolute AABB intersects with the tile.
Fields§
§tiles: AHashMap<IVec2, AHashSet<Entity>>
Implementations§
source§impl TileGrid
impl TileGrid
sourcepub(super) fn remove(&mut self, entity: Entity, aabb: &Aabb)
pub(super) fn remove(&mut self, entity: Entity, aabb: &Aabb)
Removes an entity from the grid.
§Arguments
-
entity
- entity to be removed from the grid. -
aabb
- world-space bounding box of the entity. The bounding box has to be equal to the last bounding box used for insertion or update for the entity.
§Panics
Might panic if the entity is not stored in the grid or if the last used update / insertion AABB differs from the one passed as an argument.
sourcepub(super) fn update(
&mut self,
entity: Entity,
old_aabb: &Aabb,
new_aabb: &Aabb
)
pub(super) fn update( &mut self, entity: Entity, old_aabb: &Aabb, new_aabb: &Aabb )
Update bounding box of an entity.
§Arguments
-
entity
- entity to be updated. -
old_aabb
- bounding box used during insertion or last update of the entity. -
new_aabb
- new world-space bounding box.
§Panics
Might panic if the entity is not present in the grid or if old_aabb
differs from the last used update / insert AABB.
sourcepub(super) fn get_tile_entities(
&self,
tile_coords: IVec2
) -> Option<&AHashSet<Entity>>
pub(super) fn get_tile_entities( &self, tile_coords: IVec2 ) -> Option<&AHashSet<Entity>>
Returns entities intersecting a tile.
Returns None
if there are no entities intersecting the tile. Empty
set is never returned.
§Arguments
tile_coords
- coordinates of the tile.
fn insert_to_tile(&mut self, entity: Entity, tile_coords: IVec2)
fn remove_from_tile(&mut self, entity: Entity, tile_coords: IVec2)
Auto Trait Implementations§
impl Freeze for TileGrid
impl RefUnwindSafe for TileGrid
impl Send for TileGrid
impl Sync for TileGrid
impl Unpin for TileGrid
impl UnwindSafe for TileGrid
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.