Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::ecs::Chunk Class Referencefinal

Fixed-capacity archetype storage unit holding entities and their component columns. More...

#include <chunk.h>

Public Types

using EntityArray = cnt::sarray_ext< Entity, ChunkHeader::MAX_COMPONENTS >
 Fixed-size array of entity identifiers held by the chunk.
 
using ComponentArray = cnt::sarray_ext< Component, ChunkHeader::MAX_COMPONENTS >
 Fixed-size array of component descriptors for the chunk columns.
 
using ComponentOffsetArray = cnt::sarray_ext< ChunkDataOffset, ChunkHeader::MAX_COMPONENTS >
 Fixed-size array of byte offsets into the chunk data area, one per column.
 

Public Member Functions

template<bool WorldVersionUpdateWanted>
GAIA_NODISCARD GAIA_FORCEINLINE auto comp_ptr_mut_gen (uint32_t compIdx, uint32_t row)
 Returns a read-write span of the component data. Also updates the world version for the component.
 
void finish_write (uint32_t compIdx, uint16_t from, uint16_t to)
 Finishes a raw write over a chunk range by updating versions, running set hooks once, and notifying OnSet observers after the callback completed.
 
 Chunk (const Chunk &chunk)=delete
 
 Chunk (Chunk &&chunk)=delete
 
Chunkoperator= (const Chunk &chunk)=delete
 
Chunkoperator= (Chunk &&chunk)=delete
 
void save (ser::serializer &s) const
 Serializes chunk contents: entity counts, lifespan state, entity ids and component data.
 
void load (ser::serializer &s)
 Deserializes chunk contents, restoring entity ids and component data.
 
void remove_last_entity ()
 Remove the last entity from a chunk. If as a result the chunk becomes empty it is scheduled for deletion.
 
void update_versions ()
 Updates the version numbers for this chunk.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view (uint16_t from, uint16_t to) const
 Returns a read-only entity or component view.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view () const
 Returns a read-only entity or component view.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view_raw (const void *ptr, uint32_t size) const
 Returns a read-only view over raw bytes as typed data.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view_mut (uint16_t from, uint16_t to)
 Returns a mutable entity or component view.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view_mut ()
 Returns a mutable entity or component view.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view_mut_raw (void *ptr, uint32_t size) const
 Returns a mutable view over raw bytes as typed data.
 
template<typename T >
GAIA_NODISCARD decltype(auto) sview_mut (uint16_t from, uint16_t to)
 Returns a mutable component view. Doesn't update the world version when the access is acquired.
 
template<typename T >
GAIA_NODISCARD decltype(auto) sview_mut_raw (void *ptr, uint32_t size) const
 Returns a mutable view over raw bytes without query-version updates.
 
template<typename T >
GAIA_NODISCARD decltype(auto) sview_mut ()
 Returns a mutable entity or component view without query-version updates.
 
template<typename T >
GAIA_FORCEINLINE void modify ()
 Marks the component T as modified. Best used with sview to manually trigger an update at user's whim. If TriggerSetHooks is true, also triggers the component's set hooks.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view_auto (uint16_t from, uint16_t to)
 Returns either a mutable or immutable entity/component view based on the requested type. Value and const types are considered immutable. Anything else is mutable.
 
template<typename T >
GAIA_NODISCARD decltype(auto) view_auto ()
 Returns an automatically-typed mutable view over the chunk.
 
template<typename T >
GAIA_NODISCARD decltype(auto) sview_auto (uint16_t from, uint16_t to)
 Returns either a mutable or immutable entity/component view based on the requested type. Value and const types are considered immutable. Anything else is mutable. Doesn't update the world version when read-write access is acquired.
 
template<typename T >
GAIA_NODISCARD decltype(auto) sview_auto ()
 Returns an automatically-typed mutable view without query-version updates.
 
GAIA_NODISCARD EntitySpan entity_view () const
 Span over the entities stored in this chunk.
 
GAIA_NODISCARD Worldworld ()
 Owning world mutable reference.
 
GAIA_NODISCARD const Worldworld () const
 Owning world const reference.
 
GAIA_NODISCARD EntitySpan ids_view () const
 Span over the component and entity identifiers held by this chunk.
 
GAIA_NODISCARD std::span< const ComponentRecord > comp_rec_view () const
 Span over the component records describing each chunk column.
 
GAIA_NODISCARD uint8_t * comp_ptr_mut (uint32_t compIdx)
 Mutable pointer to the start of a component column.
 
GAIA_NODISCARD uint8_t * comp_ptr_mut (uint32_t compIdx, uint32_t offset)
 Mutable pointer to a component element within a column.
 
GAIA_NODISCARD const uint8_t * comp_ptr (uint32_t compIdx) const
 Const pointer to the start of a component column.
 
GAIA_NODISCARD const uint8_t * comp_ptr (uint32_t compIdx, uint32_t offset) const
 Const pointer to a component element within a column.
 
GAIA_NODISCARD uint16_t add_entity (Entity entity)
 Make.
 
void move_entity_data (Entity entity, uint16_t row, EntityContainers &recs)
 Moves all data associated with entity into the chunk so that it is stored at the row row.
 
void remove_entity_inter (uint16_t row, EntityContainers &recs)
 Tries to remove the entity at row. Removal is done via swapping with last entity in chunk. Upon removal, all associated data is also removed. If the entity at the given row already is the last chunk entity, it is removed directly.
 
void remove_entity (uint16_t row, EntityContainers &recs)
 Tries to remove the entity at row row. Removal is done via swapping with last entity in chunk. Upon removal, all associated data is also removed. If the entity at the given row already is the last chunk entity, it is removed directly.
 
void swap_chunk_entities (uint16_t rowA, uint16_t rowB, EntityContainers &recs)
 Tries to swap the entity at row rowA with the one at the row rowB. When swapping, all data associated with the two entities is swapped as well. If rowA equals rowB no swapping is performed.
 
void enable_entity (uint16_t row, bool enableEntity, EntityContainers &recs)
 Enables or disables the entity on a given row in the chunk.
 
bool enabled (uint16_t row) const
 Checks if the entity is enabled.
 
uint8_t & data (uint32_t offset)
 Returns a mutable pointer to chunk data.
 
const uint8_t & data (uint32_t offset) const
 Returns an immutable pointer to chunk data.
 
void call_ctor (uint32_t entIdx, uint32_t compIdx, const ComponentCacheItem &item)
 Invokes the registered constructor for one component instance.
 
void call_gen_ctors (uint32_t entIdx, uint32_t entCnt)
 Invokes registered constructors for all generic columns at a row range.
 
void call_all_dtors ()
 Invokes registered destructors for all custom component instances before release.
 
GAIA_NODISCARD bool has (Entity entity) const
 Checks if a component/entity entity is present in the chunk.
 
template<typename T >
GAIA_NODISCARD bool has () const
 Checks if component T is present in the chunk.
 
template<typename T >
decltype(auto) set (uint16_t row)
 Sets the value of the unique component T on row in the chunk.
 
template<typename T >
decltype(auto) set_idx (uint16_t row, uint32_t compIdx)
 Sets the value of a generic component using a pre-resolved component column.
 
template<typename T >
decltype(auto) set_idx (uint32_t compIdx)
 Sets the value of a unique component using a pre-resolved component column.
 
template<typename T >
decltype(auto) set (uint16_t row, Entity type)
 Sets the value of a generic entity type at the position row in the chunk.
 
template<typename T >
decltype(auto) sset (uint16_t row)
 Sets the value of the unique component T on row in the chunk.
 
template<typename T >
decltype(auto) sset_idx (uint16_t row, uint32_t compIdx)
 Sets the value of a generic component using a pre-resolved component column.
 
template<typename T >
decltype(auto) sset_idx (uint32_t compIdx)
 Sets the value of a unique component using a pre-resolved component column.
 
template<typename T >
decltype(auto) sset (uint16_t row, Entity type)
 Sets the value of a generic entity type at the position row in the chunk.
 
template<typename T >
GAIA_NODISCARD decltype(auto) get (uint16_t row) const
 Returns the value stored in the generic component T on row in the chunk.
 
template<typename T >
GAIA_NODISCARD decltype(auto) get_idx (uint16_t row, uint32_t compIdx) const
 Returns the value stored in the generic component T using a pre-resolved component column.
 
template<typename T >
GAIA_NODISCARD decltype(auto) get (uint16_t row, Entity type) const
 Returns the value stored in the generic component type on row in the chunk.
 
template<typename T >
GAIA_NODISCARD decltype(auto) get () const
 Returns the value stored in the unique component T.
 
template<typename T >
GAIA_NODISCARD decltype(auto) get_idx (uint32_t compIdx) const
 Returns the value stored in the unique component T using a pre-resolved component column.
 
template<typename T >
GAIA_NODISCARD Entity comp_entity () const
 Component entity for the chunk archetype contents.
 
GAIA_NODISCARD uint32_t comp_idx (Entity entity) const
 Returns the internal index of a component based on the provided entity.
 
GAIA_NODISCARD uint32_t comp_idx (Entity entity, uint32_t offset) const
 Returns the internal index of a component based on the provided entity.
 
void set_idx (uint32_t value)
 Sets the index of this chunk in its archetype's storage.
 
GAIA_NODISCARD uint32_t idx () const
 Returns the index of this chunk in its archetype's storage.
 
GAIA_NODISCARD bool has_enabled_entities () const
 Checks is this chunk has any enabled entities.
 
GAIA_NODISCARD bool has_disabled_entities () const
 Checks is this chunk has any disabled entities.
 
GAIA_NODISCARD bool dying () const
 Checks is this chunk is dying.
 
GAIA_NODISCARD bool queued_for_deletion () const
 Returns true when the chunk is currently queued for deferred deletion.
 
GAIA_NODISCARD uint32_t delete_queue_index () const
 Returns the index inside World's deferred chunk-delete queue.
 
void delete_queue_index (uint32_t idx)
 Stores the index inside World's deferred chunk-delete queue.
 
void clear_delete_queue_index ()
 Clears the deferred chunk-delete queue index.
 
void die ()
 Marks the chunk as dead (ready to delete)
 
GAIA_NODISCARD bool dead () const
 Checks is this chunk is dead (ready to delete)
 
void start_dying ()
 Starts the process of dying (not yet ready to delete, can be revived)
 
void revive ()
 Makes a dying chunk alive again.
 
bool progress_death ()
 Updates internal lifespan.
 
GAIA_NODISCARD bool full () const
 Checks is the full capacity of the has has been reached.
 
GAIA_NODISCARD bool is_semi () const
 Checks is the chunk is semi-full.
 
GAIA_NODISCARD uint16_t size () const
 Returns the total number of entities in the chunk (both enabled and disabled)
 
GAIA_NODISCARD bool empty () const
 Checks is there are any entities in the chunk.
 
GAIA_NODISCARD uint16_t size_enabled () const
 Return the number of entities in the chunk which are enabled.
 
GAIA_NODISCARD uint16_t size_disabled () const
 Return the number of entities in the chunk which are enabled.
 
GAIA_NODISCARD uint16_t capacity () const
 Returns the number of entities in the chunk.
 
GAIA_NODISCARD uint8_t size_generic () const
 Returns the total number of generic entities/components in the chunk.
 
GAIA_NODISCARD bool changed (uint32_t requiredVersion) const
 Returns true if the provided version is newer than the one stored internally. Use when checking if there was a movement in data in the world. E.g. if an entity was added, removed or moved in its archetype.
 
GAIA_NODISCARD bool changed (uint32_t requiredVersion, uint32_t compIdx) const
 Returns true if the provided version is newer than the one stored internally.
 
GAIA_NODISCARD bool entity_order_changed (uint32_t requiredVersion) const
 Returns true if entity order changed since requiredVersion. This is narrower than changed(requiredVersion): unrelated component writes do not affect it.
 
GAIA_FORCEINLINE void update_world_version (uint32_t compIdx)
 Update the version of a component at the index.
 
GAIA_FORCEINLINE void update_entity_order_version ()
 Updates the entity-order version after rows were added, removed, or reordered.
 
GAIA_FORCEINLINE void update_world_version ()
 Update the version of all components.
 
GAIA_FORCEINLINE void update_world_version_init ()
 Update the version of all components on chunk init.
 
void diag () const
 Logs a diagnostic line describing the chunk capacity and lifespan state.
 

Static Public Member Functions

static constexpr uint16_t chunk_header_size ()
 Size in bytes of the chunk header area reserved before entity and component data.
 
static constexpr uint16_t chunk_total_bytes (uint16_t dataSize)
 Total chunk allocation size for a given usable data size.
 
static constexpr uint16_t chunk_data_bytes (uint16_t totalSize)
 Usable data area size for a given total chunk allocation size.
 
static uintptr_t chunk_data_area_offset ()
 Returns the relative offset of m_data in Chunk.
 
static Chunkcreate (const World &wld, const ComponentCache &cc, uint32_t chunkIndex, uint16_t capacity, uint8_t cntEntities, uint8_t genEntities, uint16_t dataBytes, uint32_t &worldVersion, const ChunkDataOffsets &offsets, const Entity *ids, const ComponentCacheItem *const *pItems, const ChunkDataOffset *compOffs)
 Allocates memory for a new chunk.
 
static void free (Chunk *pChunk)
 Releases all memory allocated by pChunk.
 
static void copy_entity_data (Entity srcEntity, Entity dstEntity, EntityContainers &recs)
 Copies all data associated with srcEntity into dstEntity.
 
static void copy_entity_data_n_same_chunk (Chunk *pSrcChunk, uint32_t srcRow, Chunk *pDstChunk, uint32_t dstRow, uint32_t dstCount)
 Copies all data associated with srcRow into dstCount consecutive rows in the same-archetype chunk.
 
static void copy_foreign_entity_data_n (Chunk *pSrcChunk, uint32_t srcRow, Chunk *pDstChunk, uint32_t dstRow, uint32_t dstCount)
 Copies all data associated with srcRow into dstCount consecutive rows in a foreign chunk.
 
static void copy_foreign_entity_data (Chunk *pSrcChunk, uint32_t srcRow, Chunk *pDstChunk, uint32_t dstRow)
 Copies all data associated with entity into the chunk so that it is stored at the row row.
 
static void move_foreign_entity_data (Chunk *pSrcChunk, uint32_t srcRow, Chunk *pDstChunk, uint32_t dstRow)
 Moves all data associated with entity into the chunk so that it is stored at the row row.
 
static void swap_chunk_entities (World &world, Entity entityA, Entity entityB)
 Tries to swap entityA with entityB. When swapping, all data associated with the two entities is swapped as well. If entityA and entityB are the same entity no swapping is performed.
 

Detailed Description

Fixed-capacity archetype storage unit holding entities and their component columns.

Member Function Documentation

◆ add_entity()

GAIA_NODISCARD uint16_t gaia::ecs::Chunk::add_entity ( Entity  entity)
inline

Make.

Parameters
entitya part of the chunk at the version of the world.
Returns
Row of entity within the chunk.

◆ call_ctor()

void gaia::ecs::Chunk::call_ctor ( uint32_t  entIdx,
uint32_t  compIdx,
const ComponentCacheItem &  item 
)
inline

Invokes the registered constructor for one component instance.

Parameters
entIdxEntity row to construct.
compIdxComponent column index.
itemComponent cache item carrying the constructor.

◆ call_gen_ctors()

void gaia::ecs::Chunk::call_gen_ctors ( uint32_t  entIdx,
uint32_t  entCnt 
)
inline

Invokes registered constructors for all generic columns at a row range.

Parameters
entIdxFirst entity row to construct.
entCntNumber of entity rows to construct.

◆ capacity()

GAIA_NODISCARD uint16_t gaia::ecs::Chunk::capacity ( ) const
inline

Returns the number of entities in the chunk.

Returns
Maximum number of entities the chunk can hold.

◆ changed() [1/2]

GAIA_NODISCARD bool gaia::ecs::Chunk::changed ( uint32_t  requiredVersion) const
inline

Returns true if the provided version is newer than the one stored internally. Use when checking if there was a movement in data in the world. E.g. if an entity was added, removed or moved in its archetype.

Parameters
requiredVersionVersion to compare against.
Returns
True when the stored chunk version is newer.

◆ changed() [2/2]

GAIA_NODISCARD bool gaia::ecs::Chunk::changed ( uint32_t  requiredVersion,
uint32_t  compIdx 
) const
inline

Returns true if the provided version is newer than the one stored internally.

Parameters
requiredVersionVersion to compare against.
compIdxComponent column index.
Returns
True when the stored component version is newer.

◆ chunk_data_area_offset()

static uintptr_t gaia::ecs::Chunk::chunk_data_area_offset ( )
inlinestatic

Returns the relative offset of m_data in Chunk.

Returns
Byte offset of the chunk data area relative to the Chunk start.

◆ chunk_data_bytes()

static constexpr uint16_t gaia::ecs::Chunk::chunk_data_bytes ( uint16_t  totalSize)
inlinestaticconstexpr

Usable data area size for a given total chunk allocation size.

Parameters
totalSizeTotal allocation size in bytes.
Returns
Data area size in bytes.

◆ chunk_header_size()

static constexpr uint16_t gaia::ecs::Chunk::chunk_header_size ( )
inlinestaticconstexpr

Size in bytes of the chunk header area reserved before entity and component data.

Returns
Header size in bytes.

◆ chunk_total_bytes()

static constexpr uint16_t gaia::ecs::Chunk::chunk_total_bytes ( uint16_t  dataSize)
inlinestaticconstexpr

Total chunk allocation size for a given usable data size.

Parameters
dataSizeUsable data area size in bytes.
Returns
Header plus data size in bytes.

◆ comp_entity()

template<typename T >
GAIA_NODISCARD Entity gaia::ecs::Chunk::comp_entity ( ) const
inline

Component entity for the chunk archetype contents.

Template Parameters
TComponent or pair.
Returns
Component identifier of the archetype term.

◆ comp_idx() [1/2]

GAIA_NODISCARD uint32_t gaia::ecs::Chunk::comp_idx ( Entity  entity) const
inline

Returns the internal index of a component based on the provided entity.

Parameters
entityComponent
Returns
Component index if the component was found. -1 otherwise.
Warning
The component id must be present in the array.

◆ comp_idx() [2/2]

GAIA_NODISCARD uint32_t gaia::ecs::Chunk::comp_idx ( Entity  entity,
uint32_t  offset 
) const
inline

Returns the internal index of a component based on the provided entity.

Parameters
entityComponent
offsetComponent offset
Returns
Component index if the component was found. -1 otherwise.
Warning
The component id must be present in the array.

◆ comp_ptr() [1/2]

GAIA_NODISCARD const uint8_t * gaia::ecs::Chunk::comp_ptr ( uint32_t  compIdx) const
inline

Const pointer to the start of a component column.

Parameters
compIdxComponent column index.
Returns
Pointer to the column data start.

◆ comp_ptr() [2/2]

GAIA_NODISCARD const uint8_t * gaia::ecs::Chunk::comp_ptr ( uint32_t  compIdx,
uint32_t  offset 
) const
inline

Const pointer to a component element within a column.

Parameters
compIdxComponent column index.
offsetEntity row offset.
Returns
Pointer to the element at offset.

◆ comp_ptr_mut() [1/2]

GAIA_NODISCARD uint8_t * gaia::ecs::Chunk::comp_ptr_mut ( uint32_t  compIdx)
inline

Mutable pointer to the start of a component column.

Parameters
compIdxComponent column index.
Returns
Pointer to the column data start.

◆ comp_ptr_mut() [2/2]

GAIA_NODISCARD uint8_t * gaia::ecs::Chunk::comp_ptr_mut ( uint32_t  compIdx,
uint32_t  offset 
)
inline

Mutable pointer to a component element within a column.

Parameters
compIdxComponent column index.
offsetEntity row offset.
Returns
Pointer to the element at offset.

◆ comp_ptr_mut_gen()

template<bool WorldVersionUpdateWanted>
GAIA_NODISCARD GAIA_FORCEINLINE auto gaia::ecs::Chunk::comp_ptr_mut_gen ( uint32_t  compIdx,
uint32_t  row 
)
inline

Returns a read-write span of the component data. Also updates the world version for the component.

Warning
It is expected the component with compIdx is present. Undefined behavior otherwise.
Parameters
compIdxComponent index
rowRow of entity in the chunk
Template Parameters
WorldVersionUpdateWantedIf true, the world version is updated as a result of the write access
Returns
Pointer to component data.

◆ comp_rec_view()

GAIA_NODISCARD std::span< const ComponentRecord > gaia::ecs::Chunk::comp_rec_view ( ) const
inline

Span over the component records describing each chunk column.

Returns
Component record span.

◆ copy_entity_data()

static void gaia::ecs::Chunk::copy_entity_data ( Entity  srcEntity,
Entity  dstEntity,
EntityContainers &  recs 
)
inlinestatic

Copies all data associated with srcEntity into dstEntity.

Parameters
srcEntitySource entity
dstEntityDestination entity
recsEntity containers

◆ copy_entity_data_n_same_chunk()

static void gaia::ecs::Chunk::copy_entity_data_n_same_chunk ( Chunk pSrcChunk,
uint32_t  srcRow,
Chunk pDstChunk,
uint32_t  dstRow,
uint32_t  dstCount 
)
inlinestatic

Copies all data associated with srcRow into dstCount consecutive rows in the same-archetype chunk.

Parameters
pSrcChunkSource chunk
srcRowRow in source chunk
pDstChunkDestination chunk
dstRowFirst destination row in destination chunk
dstCountNumber of destination rows to copy into

◆ copy_foreign_entity_data()

static void gaia::ecs::Chunk::copy_foreign_entity_data ( Chunk pSrcChunk,
uint32_t  srcRow,
Chunk pDstChunk,
uint32_t  dstRow 
)
inlinestatic

Copies all data associated with entity into the chunk so that it is stored at the row row.

Parameters
pSrcChunkSource chunk
srcRowRow in source chunk
pDstChunkDestination chunk
dstRowRow in destination chunk

◆ copy_foreign_entity_data_n()

static void gaia::ecs::Chunk::copy_foreign_entity_data_n ( Chunk pSrcChunk,
uint32_t  srcRow,
Chunk pDstChunk,
uint32_t  dstRow,
uint32_t  dstCount 
)
inlinestatic

Copies all data associated with srcRow into dstCount consecutive rows in a foreign chunk.

Parameters
pSrcChunkSource chunk
srcRowRow in source chunk
pDstChunkDestination chunk
dstRowFirst destination row in destination chunk
dstCountNumber of destination rows to copy into

◆ create()

static Chunk * gaia::ecs::Chunk::create ( const World wld,
const ComponentCache &  cc,
uint32_t  chunkIndex,
uint16_t  capacity,
uint8_t  cntEntities,
uint8_t  genEntities,
uint16_t  dataBytes,
uint32_t &  worldVersion,
const ChunkDataOffsets &  offsets,
const Entity ids,
const ComponentCacheItem *const *  pItems,
const ChunkDataOffset *  compOffs 
)
inlinestatic

Allocates memory for a new chunk.

Returns
Newly allocated chunk

◆ data() [1/2]

uint8_t & gaia::ecs::Chunk::data ( uint32_t  offset)
inline

Returns a mutable pointer to chunk data.

Parameters
offsetOffset into chunk data
Returns
Pointer to chunk data.

◆ data() [2/2]

const uint8_t & gaia::ecs::Chunk::data ( uint32_t  offset) const
inline

Returns an immutable pointer to chunk data.

Parameters
offsetOffset into chunk data
Returns
Pointer to chunk data.

◆ dead()

GAIA_NODISCARD bool gaia::ecs::Chunk::dead ( ) const
inline

Checks is this chunk is dead (ready to delete)

Returns
True when the chunk is dead and ready to be deleted.

◆ delete_queue_index()

GAIA_NODISCARD uint32_t gaia::ecs::Chunk::delete_queue_index ( ) const
inline

Returns the index inside World's deferred chunk-delete queue.

Returns
Deferred-delete queue index, BadIndex when not queued.

◆ dying()

GAIA_NODISCARD bool gaia::ecs::Chunk::dying ( ) const
inline

Checks is this chunk is dying.

Returns
True when the chunk is in its dying lifespan countdown.

◆ empty()

GAIA_NODISCARD bool gaia::ecs::Chunk::empty ( ) const
inline

Checks is there are any entities in the chunk.

Returns
True when the chunk holds no entities.

◆ enable_entity()

void gaia::ecs::Chunk::enable_entity ( uint16_t  row,
bool  enableEntity,
EntityContainers &  recs 
)
inline

Enables or disables the entity on a given row in the chunk.

Parameters
rowRow of the entity within chunk
enableEntityEnables or disables the entity
recsEntity container records

◆ enabled()

bool gaia::ecs::Chunk::enabled ( uint16_t  row) const
inline

Checks if the entity is enabled.

Parameters
rowRow of the entity within chunk
Returns
True if entity is enabled. False otherwise.

◆ entity_order_changed()

GAIA_NODISCARD bool gaia::ecs::Chunk::entity_order_changed ( uint32_t  requiredVersion) const
inline

Returns true if entity order changed since requiredVersion. This is narrower than changed(requiredVersion): unrelated component writes do not affect it.

Parameters
requiredVersionVersion to compare against.
Returns
True when the entity order changed at or after requiredVersion.

◆ entity_view()

GAIA_NODISCARD EntitySpan gaia::ecs::Chunk::entity_view ( ) const
inline

Span over the entities stored in this chunk.

Returns
Entity span covering all stored entities.

◆ free()

static void gaia::ecs::Chunk::free ( Chunk pChunk)
inlinestatic

Releases all memory allocated by pChunk.

Parameters
pChunkChunk which we want to destroy

◆ full()

GAIA_NODISCARD bool gaia::ecs::Chunk::full ( ) const
inline

Checks is the full capacity of the has has been reached.

Returns
True when the chunk capacity is exhausted.

◆ get() [1/3]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::get ( ) const
inline

Returns the value stored in the unique component T.

Template Parameters
TComponent or pair
Warning
It is expected the unique component T is present. Undefined behavior otherwise.
Returns
Value stored in the component.

◆ get() [2/3]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::get ( uint16_t  row) const
inline

Returns the value stored in the generic component T on row in the chunk.

Template Parameters
TComponent or pair
Parameters
rowRow of entity in the chunk
Warning
It is expected the row is valid. Undefined behavior otherwise.
It is expected the component T is present. Undefined behavior otherwise.
Returns
Value stored in the component.

◆ get() [3/3]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::get ( uint16_t  row,
Entity  type 
) const
inline

Returns the value stored in the generic component type on row in the chunk.

Template Parameters
TComponent or pair
Parameters
rowRow of entity in the chunk
typeComponent/entity/pair
Warning
It is expected the component is present. Undefined behavior otherwise.
Returns
Value stored in the component.

◆ get_idx() [1/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::get_idx ( uint16_t  row,
uint32_t  compIdx 
) const
inline

Returns the value stored in the generic component T using a pre-resolved component column.

Template Parameters
TComponent or pair
Parameters
rowRow of entity in the chunk
compIdxPre-resolved component column index
Returns
Value stored in the component.

◆ get_idx() [2/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::get_idx ( uint32_t  compIdx) const
inline

Returns the value stored in the unique component T using a pre-resolved component column.

Template Parameters
TComponent or pair
Parameters
compIdxPre-resolved component column index
Returns
Value stored in the component.

◆ has() [1/2]

template<typename T >
GAIA_NODISCARD bool gaia::ecs::Chunk::has ( ) const
inline

Checks if component T is present in the chunk.

Template Parameters
TComponent or pair
Returns
True if the component is present. False otherwise.

◆ has() [2/2]

GAIA_NODISCARD bool gaia::ecs::Chunk::has ( Entity  entity) const
inline

Checks if a component/entity entity is present in the chunk.

Parameters
entityEntity
Returns
True if found. False otherwise.

◆ has_disabled_entities()

GAIA_NODISCARD bool gaia::ecs::Chunk::has_disabled_entities ( ) const
inline

Checks is this chunk has any disabled entities.

Returns
True when at least one entity is disabled.

◆ has_enabled_entities()

GAIA_NODISCARD bool gaia::ecs::Chunk::has_enabled_entities ( ) const
inline

Checks is this chunk has any enabled entities.

Returns
True when at least one entity is enabled.

◆ ids_view()

GAIA_NODISCARD EntitySpan gaia::ecs::Chunk::ids_view ( ) const
inline

Span over the component and entity identifiers held by this chunk.

Returns
Identifier span.

◆ idx()

GAIA_NODISCARD uint32_t gaia::ecs::Chunk::idx ( ) const
inline

Returns the index of this chunk in its archetype's storage.

Returns
Index of this chunk in its archetype's storage.

◆ is_semi()

GAIA_NODISCARD bool gaia::ecs::Chunk::is_semi ( ) const
inline

Checks is the chunk is semi-full.

Returns
True when the chunk is below the semi-full threshold.

◆ load()

void gaia::ecs::Chunk::load ( ser::serializer s)
inline

Deserializes chunk contents, restoring entity ids and component data.

Parameters
sserializer to read from.

◆ move_entity_data()

void gaia::ecs::Chunk::move_entity_data ( Entity  entity,
uint16_t  row,
EntityContainers &  recs 
)
inline

Moves all data associated with entity into the chunk so that it is stored at the row row.

Parameters
entityEntity to move
rowEntity's row within its chunk
recsEntity containers

◆ move_foreign_entity_data()

static void gaia::ecs::Chunk::move_foreign_entity_data ( Chunk pSrcChunk,
uint32_t  srcRow,
Chunk pDstChunk,
uint32_t  dstRow 
)
inlinestatic

Moves all data associated with entity into the chunk so that it is stored at the row row.

Parameters
pSrcChunkSource chunk
srcRowRow in source chunk
pDstChunkDestination chunk
dstRowRow in destination chunk

◆ progress_death()

bool gaia::ecs::Chunk::progress_death ( )
inline

Updates internal lifespan.

Returns
True if there is some lifespan rowA, false otherwise.

◆ queued_for_deletion()

GAIA_NODISCARD bool gaia::ecs::Chunk::queued_for_deletion ( ) const
inline

Returns true when the chunk is currently queued for deferred deletion.

Returns
True when the chunk is queued for deferred deletion.

◆ remove_entity()

void gaia::ecs::Chunk::remove_entity ( uint16_t  row,
EntityContainers &  recs 
)
inline

Tries to remove the entity at row row. Removal is done via swapping with last entity in chunk. Upon removal, all associated data is also removed. If the entity at the given row already is the last chunk entity, it is removed directly.

Parameters
rowRow within a chunk
recsEntity containers

◆ remove_entity_inter()

void gaia::ecs::Chunk::remove_entity_inter ( uint16_t  row,
EntityContainers &  recs 
)
inline

Tries to remove the entity at row. Removal is done via swapping with last entity in chunk. Upon removal, all associated data is also removed. If the entity at the given row already is the last chunk entity, it is removed directly.

Parameters
rowRow within a chunk
recsEntity containers

◆ save()

void gaia::ecs::Chunk::save ( ser::serializer s) const
inline

Serializes chunk contents: entity counts, lifespan state, entity ids and component data.

Parameters
sserializer to write to.

◆ set() [1/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::set ( uint16_t  row)
inline

Sets the value of the unique component T on row in the chunk.

Template Parameters
TComponent or pair
Parameters
rowRow of entity in the chunk
Warning
It is expected the component T is present. Undefined behavior otherwise.
Returns
Mutable reference to the component value.

◆ set() [2/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::set ( uint16_t  row,
Entity  type 
)
inline

Sets the value of a generic entity type at the position row in the chunk.

Parameters
rowRow of entity in the chunk
typeComponent/entity/pair
Warning
It is expected the component T is present. Undefined behavior otherwise.
Returns
Mutable reference to the component value.

◆ set_idx() [1/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::set_idx ( uint16_t  row,
uint32_t  compIdx 
)
inline

Sets the value of a generic component using a pre-resolved component column.

Template Parameters
TComponent or pair
Parameters
rowRow of entity in the chunk
compIdxPre-resolved component column index
Returns
Mutable reference to the component value.

◆ set_idx() [2/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::set_idx ( uint32_t  compIdx)
inline

Sets the value of a unique component using a pre-resolved component column.

Template Parameters
TComponent or pair
Parameters
compIdxPre-resolved component column index
Returns
Mutable reference to the component value.

◆ size()

GAIA_NODISCARD uint16_t gaia::ecs::Chunk::size ( ) const
inline

Returns the total number of entities in the chunk (both enabled and disabled)

Returns
Total number of entities, enabled and disabled.

◆ size_disabled()

GAIA_NODISCARD uint16_t gaia::ecs::Chunk::size_disabled ( ) const
inline

Return the number of entities in the chunk which are enabled.

Returns
Number of disabled entities.

◆ size_enabled()

GAIA_NODISCARD uint16_t gaia::ecs::Chunk::size_enabled ( ) const
inline

Return the number of entities in the chunk which are enabled.

Returns
Number of enabled entities.

◆ size_generic()

GAIA_NODISCARD uint8_t gaia::ecs::Chunk::size_generic ( ) const
inline

Returns the total number of generic entities/components in the chunk.

Returns
Number of generic entity or component columns.

◆ sset() [1/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::sset ( uint16_t  row)
inline

Sets the value of the unique component T on row in the chunk.

Template Parameters
TComponent or pair
Parameters
rowRow of entity in the chunk
Warning
It is expected the component T is present. Undefined behavior otherwise.
World version is not updated so Query filters will not be able to catch this change.
Returns
Mutable reference to the component value.

◆ sset() [2/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::sset ( uint16_t  row,
Entity  type 
)
inline

Sets the value of a generic entity type at the position row in the chunk.

Template Parameters
TComponent or pair
Parameters
rowRow of entity in the chunk
typeComponent/entity/pair
Warning
It is expected the component T is present. Undefined behavior otherwise.
World version is not updated so Query filters will not be able to catch this change.
Returns
Mutable reference to the component value.

◆ sset_idx() [1/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::sset_idx ( uint16_t  row,
uint32_t  compIdx 
)
inline

Sets the value of a generic component using a pre-resolved component column.

Warning
World version is not updated so Query filters will not be able to catch this change.
Returns
Mutable reference to the component value.

◆ sset_idx() [2/2]

template<typename T >
decltype(auto) gaia::ecs::Chunk::sset_idx ( uint32_t  compIdx)
inline

Sets the value of a unique component using a pre-resolved component column.

Warning
World version is not updated so Query filters will not be able to catch this change.
Returns
Mutable reference to the component value.

◆ sview_auto() [1/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::sview_auto ( )
inline

Returns an automatically-typed mutable view without query-version updates.

Template Parameters
TComponent or Entity.
Returns
Automatically-typed mutable view without query-version updates.

◆ sview_auto() [2/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::sview_auto ( uint16_t  from,
uint16_t  to 
)
inline

Returns either a mutable or immutable entity/component view based on the requested type. Value and const types are considered immutable. Anything else is mutable. Doesn't update the world version when read-write access is acquired.

Warning
If T is a component it is expected to be present. Undefined behavior otherwise.
Template Parameters
TComponent or Entity
Parameters
fromFirst valid entity row
toLast valid entity row
Returns
Entity or component view

◆ sview_mut() [1/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::sview_mut ( )
inline

Returns a mutable entity or component view without query-version updates.

Template Parameters
TComponent or Entity.
Returns
Mutable view without query-version updates.

◆ sview_mut() [2/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::sview_mut ( uint16_t  from,
uint16_t  to 
)
inline

Returns a mutable component view. Doesn't update the world version when the access is acquired.

Warning
It is expected the component T is present. Undefined behavior otherwise.
Template Parameters
TComponent
Parameters
fromFirst valid entity row
toLast valid entity row
Returns
Component view with read-write access

◆ sview_mut_raw()

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::sview_mut_raw ( void *  ptr,
uint32_t  size 
) const
inline

Returns a mutable view over raw bytes without query-version updates.

Template Parameters
TComponent or Entity.
Parameters
ptrRaw data start.
sizeRaw data size in bytes.
Returns
Mutable view over the raw bytes.

◆ swap_chunk_entities() [1/2]

void gaia::ecs::Chunk::swap_chunk_entities ( uint16_t  rowA,
uint16_t  rowB,
EntityContainers &  recs 
)
inline

Tries to swap the entity at row rowA with the one at the row rowB. When swapping, all data associated with the two entities is swapped as well. If rowA equals rowB no swapping is performed.

Parameters
rowARow of the entityA within chunk
rowBRow of the entityB within chunk
[out]recsEntity container records
Warning
"rowA" must he smaller or equal to "rowB"

◆ swap_chunk_entities() [2/2]

static void gaia::ecs::Chunk::swap_chunk_entities ( World world,
Entity  entityA,
Entity  entityB 
)
inlinestatic

Tries to swap entityA with entityB. When swapping, all data associated with the two entities is swapped as well. If entityA and entityB are the same entity no swapping is performed.

Parameters
worldParent world
entityAFirst entity
entityBSecond entity

◆ update_world_version()

GAIA_FORCEINLINE void gaia::ecs::Chunk::update_world_version ( uint32_t  compIdx)
inline

Update the version of a component at the index.

Parameters
compIdx

◆ view() [1/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view ( ) const
inline

Returns a read-only entity or component view.

Template Parameters
TComponent or Entity.
Returns
Read-only view over all chunk entities or the component column.

◆ view() [2/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view ( uint16_t  from,
uint16_t  to 
) const
inline

Returns a read-only entity or component view.

Warning
If T is a component it is expected it is present. Undefined behavior otherwise.
Template Parameters
TComponent or Entity
Parameters
fromFirst valid entity row
toLast valid entity row
Returns
Entity of component view with read-only access

◆ view_auto() [1/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view_auto ( )
inline

Returns an automatically-typed mutable view over the chunk.

Template Parameters
TComponent or Entity.
Returns
Automatically-typed mutable view over the chunk.

◆ view_auto() [2/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view_auto ( uint16_t  from,
uint16_t  to 
)
inline

Returns either a mutable or immutable entity/component view based on the requested type. Value and const types are considered immutable. Anything else is mutable.

Warning
If T is a component it is expected to be present. Undefined behavior otherwise.
Template Parameters
TComponent or Entity
Parameters
fromFirst valid entity row
toLast valid entity row
Returns
Entity or component view

◆ view_mut() [1/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view_mut ( )
inline

Returns a mutable entity or component view.

Template Parameters
TComponent or Entity.
Returns
Mutable view over all chunk entities or the component column.

◆ view_mut() [2/2]

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view_mut ( uint16_t  from,
uint16_t  to 
)
inline

Returns a mutable entity or component view.

Warning
If T is a component it is expected it is present. Undefined behavior otherwise.
Template Parameters
TComponent or Entity
Parameters
fromFirst valid entity row
toLast valid entity row
Returns
Entity or component view with read-write access

◆ view_mut_raw()

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view_mut_raw ( void *  ptr,
uint32_t  size 
) const
inline

Returns a mutable view over raw bytes as typed data.

Template Parameters
TComponent or Entity.
Parameters
ptrRaw data start.
sizeRaw data size in bytes.
Returns
Mutable view over the raw bytes.

◆ view_raw()

template<typename T >
GAIA_NODISCARD decltype(auto) gaia::ecs::Chunk::view_raw ( const void *  ptr,
uint32_t  size 
) const
inline

Returns a read-only view over raw bytes as typed data.

Template Parameters
TComponent or Entity.
Parameters
ptrRaw data start.
sizeRaw data size in bytes.
Returns
Read-only view over the raw bytes.

◆ world() [1/2]

GAIA_NODISCARD World & gaia::ecs::Chunk::world ( )
inline

Owning world mutable reference.

Returns
Owning world.

◆ world() [2/2]

GAIA_NODISCARD const World & gaia::ecs::Chunk::world ( ) const
inline

Owning world const reference.

Returns
Owning world.

The documentation for this class was generated from the following file: