pub struct RegionMap {
regions: IndexMap<Vec2<i32>, Region, DefaultHashBuilder>,
tracked_entities: BitSet,
entity_to_region: Vec<Vec2<i32>>,
entities_to_move: Vec<(usize, u32, Vec3<i32>)>,
entities_to_remove: Vec<(usize, u32)>,
tick: u64,
}
Expand description
A region system that tracks where entities are.
Note, this structure is primarily intended for tracking which entities need to be synchronized to which clients (and as part of that what entities are already synchronized). If an entity is marked to not be synchronized to other clients it may not appear here.
Fields§
§regions: IndexMap<Vec2<i32>, Region, DefaultHashBuilder>
§tracked_entities: BitSet
If an entity isn’t here it needs to be added to a region.
entity_to_region: Vec<Vec2<i32>>
If an entity is in tracked_entities
this will contain the key of the
region containing that entity.
Indexed by entity ID.
Ideally, this would be the index of the region but then we would need to update this whenever removing regions
entities_to_move: Vec<(usize, u32, Vec3<i32>)>
§entities_to_remove: Vec<(usize, u32)>
§tick: u64
Implementations§
Source§impl RegionMap
impl RegionMap
pub fn new() -> Self
pub fn tick( &mut self, pos: ReadStorage<'_, Pos>, vel: ReadStorage<'_, Vel>, presence: ReadStorage<'_, Presence>, entities: Entities<'_>, )
Sourcepub fn entity_deleted(&mut self, entity: Entity) -> Option<Vec2<i32>>
pub fn entity_deleted(&mut self, entity: Entity) -> Option<Vec2<i32>>
Must be called immediately after succesfully deleting an entity from the ecs (i.e. when deleting the entity did not generate a WrongGeneration error).
Returns the region key if this entity was tracked in a region.
Sourcefn add_entity(&mut self, id: u32, pos: Vec3<i32>, from: Option<Vec2<i32>>)
fn add_entity(&mut self, id: u32, pos: Vec3<i32>, from: Option<Vec2<i32>>)
Returns index of the region that the entity is added to.
fn pos_key<P: Into<Vec2<i32>>>(pos: P) -> Vec2<i32>
pub fn key_pos(key: Vec2<i32>) -> Vec2<i32>
Sourcepub fn in_region_map(&self, entity: Entity) -> bool
pub fn in_region_map(&self, entity: Entity) -> bool
Checks if this entity is located in the RegionMap
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RegionMap
impl RefUnwindSafe for RegionMap
impl Send for RegionMap
impl Sync for RegionMap
impl Unpin for RegionMap
impl UnwindSafe for RegionMap
Blanket Implementations§
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> 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<T> Pointable for T
impl<T> Pointable for T
Source§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
§fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.