pub trait UnknownComponentStorage:
Downcast
+ Send
+ Sync {
Show 13 methods
// Required 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 + 'static),
);
fn transfer_component(
&mut self,
src_archetype: ArchetypeIndex,
src_component: ComponentIndex,
dst_archetype: ArchetypeIndex,
dst: &mut (dyn UnknownComponentStorage + 'static),
);
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: u64) -> 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§
Sourcefn increment_epoch(&mut self)
fn increment_epoch(&mut self)
Notifies the storage of the start of a new epoch.
Sourcefn 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.
Sourcefn transfer_archetype(
&mut self,
src_archetype: ArchetypeIndex,
dst_archetype: ArchetypeIndex,
dst: &mut (dyn UnknownComponentStorage + 'static),
)
fn transfer_archetype( &mut self, src_archetype: ArchetypeIndex, dst_archetype: ArchetypeIndex, dst: &mut (dyn UnknownComponentStorage + 'static), )
Moves an archetype’s component slice to a new storage.
Sourcefn transfer_component(
&mut self,
src_archetype: ArchetypeIndex,
src_component: ComponentIndex,
dst_archetype: ArchetypeIndex,
dst: &mut (dyn UnknownComponentStorage + 'static),
)
fn transfer_component( &mut self, src_archetype: ArchetypeIndex, src_component: ComponentIndex, dst_archetype: ArchetypeIndex, dst: &mut (dyn UnknownComponentStorage + 'static), )
Moves a component to a new storage.
Sourcefn 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.
Sourcefn 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.
Sourcefn fragmentation(&self) -> f32
fn fragmentation(&self) -> f32
A heuristic estimating cache misses for an iteration through all components due to archetype fragmentation.
Sourcefn element_vtable(&self) -> ComponentMeta
fn element_vtable(&self) -> ComponentMeta
Returns the component metadata.
Sourcefn get_raw(&self, archetype: ArchetypeIndex) -> Option<(*const u8, usize)>
fn get_raw(&self, archetype: ArchetypeIndex) -> Option<(*const u8, usize)>
Returns a pointer to the given archetype’s component slice.
Sourceunsafe 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.
Sourceunsafe 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
.
Sourcefn 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§
Source§impl dyn UnknownComponentStorage
impl dyn UnknownComponentStorage
Sourcepub fn is<__T>(&self) -> boolwhere
__T: UnknownComponentStorage,
pub fn is<__T>(&self) -> boolwhere
__T: UnknownComponentStorage,
Returns true if the trait object wraps an object of type __T
.
Sourcepub fn downcast<__T>(
self: Box<dyn UnknownComponentStorage>,
) -> Result<Box<__T>, Box<dyn UnknownComponentStorage>>where
__T: UnknownComponentStorage,
pub fn downcast<__T>(
self: Box<dyn UnknownComponentStorage>,
) -> Result<Box<__T>, Box<dyn UnknownComponentStorage>>where
__T: UnknownComponentStorage,
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>(
self: Rc<dyn UnknownComponentStorage>,
) -> Result<Rc<__T>, Rc<dyn UnknownComponentStorage>>where
__T: UnknownComponentStorage,
pub fn downcast_rc<__T>(
self: Rc<dyn UnknownComponentStorage>,
) -> Result<Rc<__T>, Rc<dyn UnknownComponentStorage>>where
__T: UnknownComponentStorage,
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>(&self) -> Option<&__T>where
__T: UnknownComponentStorage,
pub fn downcast_ref<__T>(&self) -> Option<&__T>where
__T: UnknownComponentStorage,
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>(&mut self) -> Option<&mut __T>where
__T: UnknownComponentStorage,
pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where
__T: UnknownComponentStorage,
Returns a mutable reference to the object within the trait object if it is of type
__T
, or None
if it isn’t.