![]() |
Gaia-ECS v1.0.0
A simple and powerful entity component system
|
Fixed-shape group of chunks storing entities that share the same component layout. Owns chunk storage, component hashes, relation-pair indexing and inter-archetype graph edges. More...
#include <archetype.h>
Inheritance diagram for gaia::ecs::Archetype:Classes | |
| struct | Properties |
| Shape properties of this archetype. More... | |
Public Types | |
| using | LookupHash = core::direct_hash_key< uint64_t > |
| Direct hash type used for archetype lookups. | |
Public Member Functions | |
| Archetype (Archetype &&)=delete | |
| Archetype (const Archetype &)=delete | |
| Archetype & | operator= (Archetype &&)=delete |
| Archetype & | operator= (const Archetype &)=delete |
| void | save (ser::serializer &s) |
| Serializes the archetype: free-chunk index, list index, and each chunk. | |
| void | load (ser::serializer &s) |
| Deserializes the archetype, recreating missing chunks from the shape description. | |
| void | list_idx (uint32_t idx) |
| Sets the archetype index in the world list of active archetypes. | |
| uint32_t | list_idx () const |
| Archetype index in the world list of active archetypes. | |
| GAIA_NODISCARD bool | cmp_comps (const ArchetypeLookupChecker &other) const |
| Compares the lookup checker component spans in archetype order. | |
| QueryMask | queryMask () const |
| Query mask describing which simple queries may match this archetype. | |
| ArchetypeIdLookupKey::LookupHash | id_hash () const |
| Archetype id hash used for graph edge storage. | |
| void | set_hashes (LookupHash hashLookup) |
| Sets hashes for each component type and lookup. | |
| void | enable_entity (Chunk *pChunk, uint16_t row, bool enableEntity, EntityContainers &recs) |
| Enables or disables the entity on a given row in the chunk. | |
| void | del (Chunk *pChunk) |
| Removes a chunk from the list of chunks managed by their archetype and deletes its memory. | |
| GAIA_NODISCARD Chunk * | foc_free_chunk () |
| Tries to locate a chunk that has some space left for a new entity. If not found a new chunk is created. | |
| void | try_update_free_chunk_idx () |
| Tries to update the index of the first chunk that has space left for at least one entity. | |
| void | try_update_free_chunk_idx (Chunk &chunkThatRemovedEntity) |
| Tries to update the index of the first chunk that has space left for at least one entity. | |
| void | remove_entity_raw (Chunk &chunk, uint16_t row, EntityContainers &recs) |
| Removes an entity from the chunk. | |
| void | remove_entity (Chunk &chunk, uint16_t row, EntityContainers &recs) |
| Removes an entity from the chunk and updates the chunk versions. | |
| GAIA_NODISCARD const Properties & | props () const |
| Shape properties of this archetype. | |
| GAIA_NODISCARD const cnt::darray< Chunk * > & | chunks () const |
| Chunks managed by this archetype. | |
| GAIA_NODISCARD LookupHash | lookup_hash () const |
| Hash of the component terms used for archetype lookup. | |
| GAIA_NODISCARD EntitySpan | ids_view () const |
| Span over the component and entity identifiers defining the archetype shape. | |
| GAIA_NODISCARD ChunkDataOffsetSpan | comp_offs_view () const |
| Span over the per-term component data offsets. | |
| GAIA_NODISCARD uint32_t | pairs () const |
| Returns the number of pairs registered in the archetype. | |
| GAIA_NODISCARD uint32_t | pairs_is () const |
| Returns the number of Is pairs registered in the archetype. | |
| GAIA_NODISCARD uint32_t | pair_matches (Entity pair) const |
| Returns how many pair ids in this archetype match the provided wildcard-capable pair query. This stays archetype-local because variable matching repeatedly probes a single candidate archetype. | |
| GAIA_NODISCARD Entity | entity_from_pairs_as_idx (uint32_t idx) const |
| Resolves a relation-pair index to its pair entity. | |
| GAIA_NODISCARD std::span< const uint8_t > | pair_indices () const |
| Indices of all relation pairs within the ids array. | |
| GAIA_NODISCARD std::span< const uint8_t > | pair_rel_indices (Entity relation) const |
| Indices of pairs whose relation matches the given relation. | |
| GAIA_NODISCARD std::span< const uint8_t > | pair_tgt_indices (Entity target) const |
| Indices of pairs whose target matches the given target. | |
| GAIA_NODISCARD bool | has (Entity entity) const |
| Checks if an entity is a part of the archetype. | |
| void | observed_terms_inc () |
| Increments the number of terms observing this archetype. | |
| void | observed_terms_dec () |
| Decrements the number of terms observing this archetype. | |
| GAIA_NODISCARD bool | has_observed_terms () const |
| Whether any observer term currently observes this archetype. | |
| template<typename T > | |
| GAIA_NODISCARD bool | has () const |
| Checks if component T is present in the chunk. | |
| template<bool Enabled> | |
| Entity | get_flat_entity (size_t flatIdx) const |
| Given a flat index, returns an entity at that index. E.g., if there are 2 chunks, the first one with 10 entities and the second one with 5, flat index of 12 means the second entity inside the second chunk. | |
| template<bool Enabled> | |
| const void * | get_flat_comp_ptr (uint32_t compIdx, size_t flatIdx, Entity &outEntity) const |
| Given a flat index, returns pointer to component data at that index. E.g., if there are 2 chunks, the first one with 10 entities and the second one with 5, flat index of 12 means component data for the second entity inside the second chunk. | |
| template<bool Enabled> | |
| void | sort_entities_inter (size_t low, size_t high, TSortByFunc func) |
| Generic in-place quicksort across chunks. | |
| template<bool Enabled> | |
| void | sort_entities_inter (const ComponentCacheItem *pItem, uint32_t compIdx, size_t low, size_t high, TSortByFunc func) |
| Generic in-place quicksort across chunks. | |
| void | sort_entities (Entity entity, TSortByFunc func) |
| Sorts all entities in the archetypes according to the given function. | |
| void | build_graph_edges (Archetype *pArchetypeRight, Entity entity) |
| Builds a graph edge from this archetype to the right archetype. | |
| void | build_graph_edges_left (Archetype *pArchetypeLeft, Entity entity) |
| Records a cached "del" graph edge from entity entity to this archetype. | |
| void | del_graph_edges (Archetype *pArchetypeRight, Entity entity) |
| Removes the cached "add" edge for entity and propagates the delete to the right archetype. | |
| void | del_graph_edges_left (Archetype *pArchetypeLeft, Entity entity) |
| Removes the cached "del" edge for entity after the matching "add" edge is removed. | |
| void | del_graph_edge_right_local (Entity entity) |
| Deletes a cached local "add" edge formed by entity. Intended for stale edge cache recovery when the opposite archetype no longer exists. | |
| void | del_graph_edge_left_local (Entity entity) |
| Deletes a cached local "del" edge formed by entity. Intended for stale edge cache recovery when the opposite archetype no longer exists. | |
| GAIA_NODISCARD ArchetypeGraphEdge | find_edge_right (Entity entity) const |
| Checks if an archetype graph "add" edge with entity entity exists. | |
| GAIA_NODISCARD ArchetypeGraphEdge | find_edge_left (Entity entity) const |
| Checks if an archetype graph "del" edge with entity entity exists. | |
| GAIA_NODISCARD auto & | right_edges () |
| Mutable view over the archetype "add" graph edges. | |
| GAIA_NODISCARD const auto & | right_edges () const |
| Const view over the archetype "add" graph edges. | |
| GAIA_NODISCARD auto & | left_edges () |
| Mutable view over the archetype "del" graph edges. | |
| GAIA_NODISCARD const auto & | left_edges () const |
| Const view over the archetype "del" graph edges. | |
| GAIA_NODISCARD bool | empty () const |
| Checks is there are no chunk in the archetype. | |
| void | req_del () |
| Request deleting the archetype. | |
| GAIA_NODISCARD bool | is_req_del () const |
| Returns true if this archetype is requested to be deleted. | |
| void | set_max_lifespan (uint32_t lifespan) |
| Sets maximal lifespan of an archetype. | |
| GAIA_NODISCARD uint32_t | max_lifespan () const |
| Returns the maximal lifespan of the archetype. If zero, the archetype it kept indefinitely. | |
| GAIA_NODISCARD bool | dying () const |
| Checks is this chunk is dying. | |
| void | die () |
| Marks the chunk as dead. | |
| GAIA_NODISCARD bool | dead () const |
| Checks is this chunk is dying. | |
| void | start_dying () |
| Starts the process of dying. | |
| void | revive () |
| Makes the archetype alive again. | |
| GAIA_NODISCARD bool | progress_death () |
| Updates internal lifespan. | |
| GAIA_NODISCARD bool | ready_to_die () const |
| Tells whether archetype is ready to be deleted. | |
Public Member Functions inherited from gaia::ecs::ArchetypeBase | |
| GAIA_NODISCARD ArchetypeId | id () const |
| Archetype id used to address the archetype in the world list. | |
Static Public Member Functions | |
| static GAIA_NODISCARD Archetype * | create (const World &world, ArchetypeId archetypeId, uint32_t &worldVersion, EntitySpan ids) |
| Creates a new archetype from a component term span. | |
| static void | destroy (Archetype *pArchetype) |
| Destroys the archetype and frees its memory. | |
| static void | diag_entity (const World &world, Entity entity) |
| Logs a diagnostic line for one entity, pair, or component of the archetype. | |
| static void | diag_basic_info (const World &world, const Archetype &archetype) |
| Logs basic archetype diagnostics: sizes, chunk count, entity counts, and component ids. | |
| static void | diag_graph_info (const World &world, const Archetype &archetype) |
| Logs the archetype graph edge diagnostics. | |
| static void | diag_chunk_info (const Archetype &archetype) |
| Logs per-chunk diagnostics for all chunks of the archetype. | |
| static void | diag_entity_info (const World &world, const Archetype &archetype) |
| Logs entity diagnostics for each entity of the archetype. | |
| static void | diag (const World &world, const Archetype &archetype) |
| Performs diagnostics on a specific archetype. Prints basic info about it and the chunks it contains. | |
Static Public Attributes | |
| static constexpr uint16_t | ARCHETYPE_LIFESPAN_BITS = 7 |
| Number of bits representing archetype lifespan. | |
| static constexpr uint16_t | MAX_ARCHETYPE_LIFESPAN = (1 << ARCHETYPE_LIFESPAN_BITS) - 1 |
| Archetype lifespan must be at least as long as chunk lifespan. | |
Additional Inherited Members | |
Protected Attributes inherited from gaia::ecs::ArchetypeBase | |
| ArchetypeId | m_archetypeId = ArchetypeIdBad |
| Archetype ID - used to address the archetype directly in the world's list or archetypes. | |
Fixed-shape group of chunks storing entities that share the same component layout. Owns chunk storage, component hashes, relation-pair indexing and inter-archetype graph edges.
Builds a graph edge from this archetype to the right archetype.
| pArchetypeRight | Target archetype |
| entity | Entity to link |
|
inline |
Records a cached "del" graph edge from entity entity to this archetype.
| pArchetypeLeft | Owning archetype of entity. |
| entity | Entity forming the left edge. |
|
inline |
Chunks managed by this archetype.
|
inline |
Compares the lookup checker component spans in archetype order.
| other | Other checker to compare against. |
|
inline |
Span over the per-term component data offsets.
|
inline |
Checks is this chunk is dying.
|
inline |
Removes a chunk from the list of chunks managed by their archetype and deletes its memory.
| pChunk | Chunk to remove from the list of managed archetypes |
|
inline |
Deletes a cached local "del" edge formed by entity. Intended for stale edge cache recovery when the opposite archetype no longer exists.
| entity | Entity to remove |
|
inline |
Deletes a cached local "add" edge formed by entity. Intended for stale edge cache recovery when the opposite archetype no longer exists.
| entity | Entity to remove |
Removes the cached "add" edge for entity and propagates the delete to the right archetype.
| pArchetypeRight | Target archetype of the edge. |
| entity | Entity whose edge is removed. |
|
inline |
Removes the cached "del" edge for entity after the matching "add" edge is removed.
| pArchetypeLeft | Owning archetype of entity. |
| entity | Entity whose left edge is removed. |
|
inlinestatic |
Destroys the archetype and frees its memory.
| pArchetype | Archetype to destroy. |
|
inlinestatic |
Performs diagnostics on a specific archetype. Prints basic info about it and the chunks it contains.
| world | Parent world |
| archetype | Archetype to run diagnostics on |
|
inlinestatic |
Logs per-chunk diagnostics for all chunks of the archetype.
| archetype | Archetype whose chunks are described. |
|
inline |
Checks is this chunk is dying.
|
inline |
Checks is there are no chunk in the archetype.
|
inline |
|
inline |
Resolves a relation-pair index to its pair entity.
| idx | Index within the archetype pair array. |
|
inline |
|
inline |
|
inline |
Tries to locate a chunk that has some space left for a new entity. If not found a new chunk is created.
|
inline |
Given a flat index, returns pointer to component data at that index. E.g., if there are 2 chunks, the first one with 10 entities and the second one with 5, flat index of 12 means component data for the second entity inside the second chunk.
| compIdx | Component index we are searching for | |
| flatIdx | Flat index of entity inside the archetype | |
| [out] | outEntity | Entity belonging to the flatIdx |
|
inline |
Given a flat index, returns an entity at that index. E.g., if there are 2 chunks, the first one with 10 entities and the second one with 5, flat index of 12 means the second entity inside the second chunk.
| flatIdx | Flat index of entity inside the archetype |
|
inline |
Checks if component T is present in the chunk.
| T | Component or pair |
|
inline |
Checks if an entity is a part of the archetype.
| entity | Entity |
|
inline |
Whether any observer term currently observes this archetype.
|
inline |
Archetype id hash used for graph edge storage.
|
inline |
Span over the component and entity identifiers defining the archetype shape.
|
inline |
Returns true if this archetype is requested to be deleted.
|
inline |
Mutable view over the archetype "del" graph edges.
|
inline |
Const view over the archetype "del" graph edges.
|
inline |
|
inline |
Sets the archetype index in the world list of active archetypes.
| idx | List index to store. |
|
inline |
Deserializes the archetype, recreating missing chunks from the shape description.
| s | serializer to read from. |
|
inline |
Hash of the component terms used for archetype lookup.
|
inline |
Returns the maximal lifespan of the archetype. If zero, the archetype it kept indefinitely.
|
inline |
Indices of all relation pairs within the ids array.
|
inline |
Returns how many pair ids in this archetype match the provided wildcard-capable pair query. This stays archetype-local because variable matching repeatedly probes a single candidate archetype.
| pair | Wildcard-capable pair query. |
|
inline |
Indices of pairs whose relation matches the given relation.
| relation | Relation entity to match. |
|
inline |
Indices of pairs whose target matches the given target.
| target | Target entity to match. |
|
inline |
Returns the number of pairs registered in the archetype.
|
inline |
Returns the number of Is pairs registered in the archetype.
|
inline |
Updates internal lifespan.
|
inline |
Shape properties of this archetype.
|
inline |
Query mask describing which simple queries may match this archetype.
|
inline |
Tells whether archetype is ready to be deleted.
|
inline |
|
inline |
|
inline |
Mutable view over the archetype "add" graph edges.
|
inline |
Const view over the archetype "add" graph edges.
|
inline |
Serializes the archetype: free-chunk index, list index, and each chunk.
| s | serializer to write to. |
|
inline |
Sets hashes for each component type and lookup.
| hashLookup | Hash used for archetype lookup purposes |
|
inline |
Sets maximal lifespan of an archetype.
| lifespan | How many world updates an empty archetype is kept. If zero, the archetype it kept indefinitely. |
|
inline |
Sorts all entities in the archetypes according to the given function.
| entity | Entity to sort by |
| func | Function to sort by |
|
inline |
Tries to update the index of the first chunk that has space left for at least one entity.
|
inline |
Tries to update the index of the first chunk that has space left for at least one entity.
|
staticconstexpr |
Archetype lifespan must be at least as long as chunk lifespan.
Number of ticks before empty chunks are removed