![]() |
Gaia-ECS v1.0.0
A simple and powerful entity component system
|
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 | |
| Chunk & | operator= (const Chunk &chunk)=delete |
| Chunk & | operator= (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 World & | world () |
| Owning world mutable reference. | |
| GAIA_NODISCARD const World & | world () 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 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) |
| 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. | |
Fixed-capacity archetype storage unit holding entities and their component columns.
|
inline |
Make.
| entity | a part of the chunk at the version of the world. |
|
inline |
|
inline |
Invokes registered constructors for all generic columns at a row range.
| entIdx | First entity row to construct. |
| entCnt | Number of entity rows to construct. |
|
inline |
Returns the number of entities in the chunk.
|
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.
| requiredVersion | Version to compare against. |
|
inline |
Returns true if the provided version is newer than the one stored internally.
| requiredVersion | Version to compare against. |
| compIdx | Component column index. |
|
inlinestatic |
|
inlinestaticconstexpr |
Usable data area size for a given total chunk allocation size.
| totalSize | Total allocation size in bytes. |
|
inlinestaticconstexpr |
Size in bytes of the chunk header area reserved before entity and component data.
|
inlinestaticconstexpr |
Total chunk allocation size for a given usable data size.
| dataSize | Usable data area size in bytes. |
|
inline |
|
inline |
|
inline |
|
inline |
Const pointer to the start of a component column.
| compIdx | Component column index. |
|
inline |
|
inline |
Mutable pointer to the start of a component column.
| compIdx | Component column index. |
|
inline |
|
inline |
Returns a read-write span of the component data. Also updates the world version for the component.
| compIdx | Component index |
| row | Row of entity in the chunk |
| WorldVersionUpdateWanted | If true, the world version is updated as a result of the write access |
|
inline |
Span over the component records describing each chunk column.
|
inlinestatic |
Copies all data associated with srcEntity into dstEntity.
| srcEntity | Source entity |
| dstEntity | Destination entity |
| recs | Entity containers |
|
inlinestatic |
Copies all data associated with srcRow into dstCount consecutive rows in the same-archetype chunk.
| pSrcChunk | Source chunk |
| srcRow | Row in source chunk |
| pDstChunk | Destination chunk |
| dstRow | First destination row in destination chunk |
| dstCount | Number of destination rows to copy into |
|
inlinestatic |
Copies all data associated with entity into the chunk so that it is stored at the row row.
| pSrcChunk | Source chunk |
| srcRow | Row in source chunk |
| pDstChunk | Destination chunk |
| dstRow | Row in destination chunk |
|
inlinestatic |
Copies all data associated with srcRow into dstCount consecutive rows in a foreign chunk.
| pSrcChunk | Source chunk |
| srcRow | Row in source chunk |
| pDstChunk | Destination chunk |
| dstRow | First destination row in destination chunk |
| dstCount | Number of destination rows to copy into |
|
inlinestatic |
Allocates memory for a new chunk.
|
inline |
Returns a mutable pointer to chunk data.
| offset | Offset into chunk data |
|
inline |
Returns an immutable pointer to chunk data.
| offset | Offset into chunk data |
|
inline |
Checks is this chunk is dead (ready to delete)
|
inline |
Returns the index inside World's deferred chunk-delete queue.
|
inline |
Checks is this chunk is dying.
|
inline |
Checks is there are any entities in the chunk.
|
inline |
Enables or disables the entity on a given row in the chunk.
| row | Row of the entity within chunk |
| enableEntity | Enables or disables the entity |
| recs | Entity container records |
|
inline |
Checks if the entity is enabled.
| row | Row of the entity within chunk |
|
inline |
Returns true if entity order changed since requiredVersion. This is narrower than changed(requiredVersion): unrelated component writes do not affect it.
| requiredVersion | Version to compare against. |
|
inline |
Span over the entities stored in this chunk.
|
inlinestatic |
Releases all memory allocated by pChunk.
| pChunk | Chunk which we want to destroy |
|
inline |
Checks is the full capacity of the has has been reached.
|
inline |
Returns the value stored in the unique component T.
| T | Component or pair |
|
inline |
Returns the value stored in the generic component T on row in the chunk.
| T | Component or pair |
| row | Row of entity in the chunk |
|
inline |
Returns the value stored in the generic component type on row in the chunk.
| T | Component or pair |
| row | Row of entity in the chunk |
| type | Component/entity/pair |
|
inline |
Returns the value stored in the generic component T using a pre-resolved component column.
| T | Component or pair |
| row | Row of entity in the chunk |
| compIdx | Pre-resolved component column index |
|
inline |
Returns the value stored in the unique component T using a pre-resolved component column.
| T | Component or pair |
| compIdx | Pre-resolved component column index |
|
inline |
Checks if component T is present in the chunk.
| T | Component or pair |
|
inline |
Checks if a component/entity entity is present in the chunk.
| entity | Entity |
|
inline |
Checks is this chunk has any disabled entities.
|
inline |
Checks is this chunk has any enabled entities.
|
inline |
Span over the component and entity identifiers held by this chunk.
|
inline |
Returns the index of this chunk in its archetype's storage.
|
inline |
Checks is the chunk is semi-full.
|
inline |
Deserializes chunk contents, restoring entity ids and component data.
| s | serializer to read from. |
|
inline |
|
inlinestatic |
Moves all data associated with entity into the chunk so that it is stored at the row row.
| pSrcChunk | Source chunk |
| srcRow | Row in source chunk |
| pDstChunk | Destination chunk |
| dstRow | Row in destination chunk |
|
inline |
Updates internal lifespan.
|
inline |
Returns true when the chunk is currently queued for deferred deletion.
|
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.
| row | Row within a chunk |
| recs | Entity containers |
|
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.
| row | Row within a chunk |
| recs | Entity containers |
|
inline |
Serializes chunk contents: entity counts, lifespan state, entity ids and component data.
| s | serializer to write to. |
|
inline |
Sets the value of the unique component T on row in the chunk.
| T | Component or pair |
| row | Row of entity in the chunk |
|
inline |
Sets the value of a generic entity type at the position row in the chunk.
| row | Row of entity in the chunk |
| type | Component/entity/pair |
|
inline |
Sets the value of a generic component using a pre-resolved component column.
| T | Component or pair |
| row | Row of entity in the chunk |
| compIdx | Pre-resolved component column index |
|
inline |
Sets the value of a unique component using a pre-resolved component column.
| T | Component or pair |
| compIdx | Pre-resolved component column index |
|
inline |
Returns the total number of entities in the chunk (both enabled and disabled)
|
inline |
Return the number of entities in the chunk which are enabled.
|
inline |
Return the number of entities in the chunk which are enabled.
|
inline |
Returns the total number of generic entities/components in the chunk.
|
inline |
Sets the value of the unique component T on row in the chunk.
| T | Component or pair |
| row | Row of entity in the chunk |
|
inline |
Sets the value of a generic entity type at the position row in the chunk.
| T | Component or pair |
| row | Row of entity in the chunk |
| type | Component/entity/pair |
|
inline |
Sets the value of a generic component using a pre-resolved component column.
|
inline |
Sets the value of a unique component using a pre-resolved component column.
|
inline |
|
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.
| from | First valid entity row |
| to | Last valid entity row |
|
inline |
|
inline |
Returns a mutable component view. Doesn't update the world version when the access is acquired.
| T | Component |
| from | First valid entity row |
| to | Last valid entity row |
|
inline |
|
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.
| rowA | Row of the entityA within chunk | |
| rowB | Row of the entityB within chunk | |
| [out] | recs | Entity container records |
|
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.
| world | Parent world |
| entityA | First entity |
| entityB | Second entity |
|
inline |
Update the version of a component at the index.
| compIdx |
|
inline |
|
inline |
|
inline |
|
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.
| from | First valid entity row |
| to | Last valid entity row |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Owning world mutable reference.
|
inline |
Owning world const reference.