Trait legion::storage::UnknownComponentStorage
source · [−]pub trait UnknownComponentStorage: Downcast + Send + Sync {
Show 13 methods
fn increment_epoch(&mut self);
fn insert_archetype(
&mut self,
archetype: ArchetypeIndex,
index: Option<usize>
);
fn transfer_archetype(
&mut self,
src_archetype: ArchetypeIndex,
dst_archetype: ArchetypeIndex,
dst: &mut dyn UnknownComponentStorage
);
fn transfer_component(
&mut self,
src_archetype: ArchetypeIndex,
src_component: ComponentIndex,
dst_archetype: ArchetypeIndex,
dst: &mut dyn UnknownComponentStorage
);
fn move_component(
&mut self,
source: ArchetypeIndex,
index: ComponentIndex,
dst: ArchetypeIndex
);
fn swap_remove(&mut self, archetype: ArchetypeIndex, index: ComponentIndex);
fn pack(&mut self, epoch_threshold: Epoch) -> usize;
fn fragmentation(&self) -> f32;
fn element_vtable(&self) -> ComponentMeta;
fn get_raw(&self, archetype: ArchetypeIndex) -> Option<(*const u8, usize)>;
unsafe fn get_mut_raw(
&self,
archetype: ArchetypeIndex
) -> Option<(*mut u8, usize)>;
unsafe fn extend_memcopy_raw(
&mut self,
archetype: ArchetypeIndex,
ptr: *const u8,
len: usize
);
fn ensure_capacity(&mut self, archetype: ArchetypeIndex, space: usize);
}
Expand description
A storage location for component data slices. Each component storage may hold one slice for each archetype inserted into the storage. The type of component stored is not known statically.
Required methods
fn increment_epoch(&mut self)
fn increment_epoch(&mut self)
Notifies the storage of the start of a new epoch.
fn insert_archetype(&mut self, archetype: ArchetypeIndex, index: Option<usize>)
fn insert_archetype(&mut self, archetype: ArchetypeIndex, index: Option<usize>)
Inserts a new empty component slice for an archetype into this storage.
fn transfer_archetype(
&mut self,
src_archetype: ArchetypeIndex,
dst_archetype: ArchetypeIndex,
dst: &mut dyn UnknownComponentStorage
)
fn transfer_archetype(
&mut self,
src_archetype: ArchetypeIndex,
dst_archetype: ArchetypeIndex,
dst: &mut dyn UnknownComponentStorage
)
Moves an archetype’s component slice to a new storage.
fn transfer_component(
&mut self,
src_archetype: ArchetypeIndex,
src_component: ComponentIndex,
dst_archetype: ArchetypeIndex,
dst: &mut dyn UnknownComponentStorage
)
fn transfer_component(
&mut self,
src_archetype: ArchetypeIndex,
src_component: ComponentIndex,
dst_archetype: ArchetypeIndex,
dst: &mut dyn UnknownComponentStorage
)
Moves a component to a new storage.
fn move_component(
&mut self,
source: ArchetypeIndex,
index: ComponentIndex,
dst: ArchetypeIndex
)
fn move_component(
&mut self,
source: ArchetypeIndex,
index: ComponentIndex,
dst: ArchetypeIndex
)
Moves a component from one archetype to another.
fn swap_remove(&mut self, archetype: ArchetypeIndex, index: ComponentIndex)
fn swap_remove(&mut self, archetype: ArchetypeIndex, index: ComponentIndex)
Removes a component from an archetype slice, swapping it with the last component in the slice.
fn fragmentation(&self) -> f32
fn fragmentation(&self) -> f32
A heuristic estimating cache misses for an iteration through all components due to archetype fragmentation.
fn element_vtable(&self) -> ComponentMeta
fn element_vtable(&self) -> ComponentMeta
Returns the component metadata.
Returns a pointer to the given archetype’s component slice.
unsafe fn get_mut_raw(
&self,
archetype: ArchetypeIndex
) -> Option<(*mut u8, usize)>
unsafe fn get_mut_raw(
&self,
archetype: ArchetypeIndex
) -> Option<(*mut u8, usize)>
Returns a pointer to the given archetype’s component slice.
Safety
The caller is responsible for ensuring that they have exclusive access to the given archetype’s slice.
unsafe fn extend_memcopy_raw(
&mut self,
archetype: ArchetypeIndex,
ptr: *const u8,
len: usize
)
unsafe fn extend_memcopy_raw(
&mut self,
archetype: ArchetypeIndex,
ptr: *const u8,
len: usize
)
Writes new components into the given archetype’s component slice via a memcopy.
Safety
ptr
must point to a valid array of the correct component type of length at least as long as len
.
The data in this array will be memcopied into the world’s internal storage.
If the component type is not Copy
, then the caller must ensure that the memory
copied is not accessed until it is re-initialized. It is recommended to immediately
std::mem::forget
the source after calling extend_memcopy_raw
.
fn ensure_capacity(&mut self, archetype: ArchetypeIndex, space: usize)
fn ensure_capacity(&mut self, archetype: ArchetypeIndex, space: usize)
Ensures that the given spare capacity is available for component insertions. This is a performance hint and
should not be required before extend_memcopy
is called.
Implementations
sourceimpl dyn UnknownComponentStorage
impl dyn UnknownComponentStorage
sourcepub fn is<__T: UnknownComponentStorage>(&self) -> bool
pub fn is<__T: UnknownComponentStorage>(&self) -> bool
Returns true if the trait object wraps an object of type __T
.
sourcepub fn downcast<__T: UnknownComponentStorage>(
self: Box<Self>
) -> Result<Box<__T>, Box<Self>>
pub fn downcast<__T: UnknownComponentStorage>(
self: Box<Self>
) -> Result<Box<__T>, Box<Self>>
Returns a boxed object from a boxed trait object if the underlying object is of type
__T
. Returns the original boxed trait if it isn’t.
sourcepub fn downcast_rc<__T: UnknownComponentStorage>(
self: Rc<Self>
) -> Result<Rc<__T>, Rc<Self>>
pub fn downcast_rc<__T: UnknownComponentStorage>(
self: Rc<Self>
) -> Result<Rc<__T>, Rc<Self>>
Returns an Rc
-ed object from an Rc
-ed trait object if the underlying object is of
type __T
. Returns the original Rc
-ed trait if it isn’t.
sourcepub fn downcast_ref<__T: UnknownComponentStorage>(&self) -> Option<&__T>
pub fn downcast_ref<__T: UnknownComponentStorage>(&self) -> Option<&__T>
Returns a reference to the object within the trait object if it is of type __T
, or
None
if it isn’t.
sourcepub fn downcast_mut<__T: UnknownComponentStorage>(&mut self) -> Option<&mut __T>
pub fn downcast_mut<__T: UnknownComponentStorage>(&mut self) -> Option<&mut __T>
Returns a mutable reference to the object within the trait object if it is of type
__T
, or None
if it isn’t.