Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::ecs::Archetype Class Referencefinal
+ Inheritance diagram for gaia::ecs::Archetype:

Classes

struct  Properties
 

Public Types

using LookupHash = core::direct_hash_key< uint64_t >
 

Public Member Functions

 Archetype (Archetype &&)=delete
 
 Archetype (const Archetype &)=delete
 
Archetypeoperator= (Archetype &&)=delete
 
Archetypeoperator= (const Archetype &)=delete
 
void save (ser::ISerializer &s)
 
void load (ser::ISerializer &s)
 
void list_idx (uint32_t idx)
 
uint32_t list_idx () const
 
GAIA_NODISCARD bool cmp_comps (const ArchetypeLookupChecker &other) const
 
QueryMask queryMask () const
 
ArchetypeIdLookupKey::LookupHash id_hash () const
 
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 Chunkfoc_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 Propertiesprops () const
 
GAIA_NODISCARD const cnt::darray< Chunk * > & chunks () const
 
GAIA_NODISCARD LookupHash lookup_hash () const
 
GAIA_NODISCARD EntitySpan ids_view () const
 
GAIA_NODISCARD ComponentSpan comps_view () const
 
GAIA_NODISCARD ChunkDataOffsetSpan comp_offs_view () const
 
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 Entity entity_from_pairs_as_idx (uint32_t idx) const
 
GAIA_NODISCARD bool has (Entity entity) const
 Checks if an entity is a part of the archetype.
 
template<typename T >
GAIA_NODISCARD bool has () const
 Checks if component.
 
template<bool Enabled>
Entity getValue (size_t flatIndex) const
 Given a flat index, return a reference to the value.
 
template<bool Enabled>
const void * getValue (uint32_t compIdx, size_t flatIndex, Entity &outEntity) const
 Given a flat index, return a reference to the value.
 
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)
 
void del_graph_edges (Archetype *pArchetypeRight, Entity entity)
 
void del_graph_edges_left (Archetype *pArchetypeLeft, Entity entity)
 
GAIA_NODISCARD ArchetypeGraphEdge find_edge_right (Entity entity) const
 Checks if an archetype graph "add" edge with entity.
 
GAIA_NODISCARD ArchetypeGraphEdge find_edge_left (Entity entity) const
 Checks if an archetype graph "del" edge with entity.
 
GAIA_NODISCARD auto & right_edges ()
 
GAIA_NODISCARD const auto & right_edges () const
 
GAIA_NODISCARD auto & left_edges ()
 
GAIA_NODISCARD const auto & left_edges () const
 
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
 

Static Public Member Functions

static GAIA_NODISCARD Archetypecreate (const World &world, ArchetypeId archetypeId, uint32_t &worldVersion, EntitySpan ids)
 
static void destroy (Archetype *pArchetype)
 
static void diag_entity (const World &world, Entity entity)
 
static void diag_basic_info (const World &world, const Archetype &archetype)
 
static void diag_graph_info (const World &world, const Archetype &archetype)
 
static void diag_chunk_info (const Archetype &archetype)
 
static void diag_entity_info (const World &world, const Archetype &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.
 

Member Function Documentation

◆ build_graph_edges()

void gaia::ecs::Archetype::build_graph_edges ( Archetype pArchetypeRight,
Entity  entity 
)
inline

Builds a graph edge from this archetype to the right archetype.

Parameters
pArchetypeRightTarget archetype
entityEntity to link

◆ del()

void gaia::ecs::Archetype::del ( Chunk pChunk)
inline

Removes a chunk from the list of chunks managed by their archetype and deletes its memory.

Parameters
pChunkChunk to remove from the list of managed archetypes

◆ diag()

static void gaia::ecs::Archetype::diag ( const World world,
const Archetype archetype 
)
inlinestatic

Performs diagnostics on a specific archetype. Prints basic info about it and the chunks it contains.

Parameters
worldParent world
archetypeArchetype to run diagnostics on

◆ enable_entity()

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

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

Parameters
pChunkChunk the entity belongs to
rowRow of the entity
enableEntityEnables the entity
recsEntity containers

◆ find_edge_left()

GAIA_NODISCARD ArchetypeGraphEdge gaia::ecs::Archetype::find_edge_left ( Entity  entity) const
inline

Checks if an archetype graph "del" edge with entity.

Parameters
entityexists.
Returns
Archetype id of the target archetype if the edge is found. ArchetypeIdBad otherwise.

◆ find_edge_right()

GAIA_NODISCARD ArchetypeGraphEdge gaia::ecs::Archetype::find_edge_right ( Entity  entity) const
inline

Checks if an archetype graph "add" edge with entity.

Parameters
entityexists.
Returns
Archetype id of the target archetype if the edge is found. ArchetypeIdBad otherwise.

◆ foc_free_chunk()

GAIA_NODISCARD Chunk * gaia::ecs::Archetype::foc_free_chunk ( )
inline

Tries to locate a chunk that has some space left for a new entity. If not found a new chunk is created.

Warning
Always used in tandem with try_update_free_chunk_idx() or remove_entity()

◆ has() [1/2]

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

Checks if component.

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

◆ has() [2/2]

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

Checks if an entity is a part of the archetype.

Parameters
entityEntity
Returns
True if found. False otherwise.

◆ pairs()

GAIA_NODISCARD uint32_t gaia::ecs::Archetype::pairs ( ) const
inline

Returns the number of pairs registered in the archetype.

Returns
Number of pairs

◆ pairs_is()

GAIA_NODISCARD uint32_t gaia::ecs::Archetype::pairs_is ( ) const
inline

Returns the number of Is pairs registered in the archetype.

Returns
Number of Is pairs

◆ progress_death()

GAIA_NODISCARD bool gaia::ecs::Archetype::progress_death ( )
inline

Updates internal lifespan.

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

◆ remove_entity()

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

Removes an entity from the chunk and updates the chunk versions.

Parameters
chunkChunk to remove the entity from
rowRow of the entity
recsEntity containers

◆ remove_entity_raw()

void gaia::ecs::Archetype::remove_entity_raw ( Chunk chunk,
uint16_t  row,
EntityContainers recs 
)
inline

Removes an entity from the chunk.

Parameters
chunkChunk to remove the entity from
rowRow of the entity
recsEntity containers

◆ set_hashes()

void gaia::ecs::Archetype::set_hashes ( LookupHash  hashLookup)
inline

Sets hashes for each component type and lookup.

Parameters
hashLookupHash used for archetype lookup purposes

◆ set_max_lifespan()

void gaia::ecs::Archetype::set_max_lifespan ( uint32_t  lifespan)
inline

Sets maximal lifespan of an archetype.

Parameters
lifespanHow many world updates an empty archetype is kept. If zero, the archetype it kept indefinitely.

◆ sort_entities()

void gaia::ecs::Archetype::sort_entities ( Entity  entity,
TSortByFunc  func 
)
inline

Sorts all entities in the archetypes according to the given function.

Parameters
entityEntity to sort by
funcFunction to sort by

◆ try_update_free_chunk_idx() [1/2]

void gaia::ecs::Archetype::try_update_free_chunk_idx ( )
inline

Tries to update the index of the first chunk that has space left for at least one entity.

Warning
Always use in tandem with foc_free_chunk()

◆ try_update_free_chunk_idx() [2/2]

void gaia::ecs::Archetype::try_update_free_chunk_idx ( Chunk chunkThatRemovedEntity)
inline

Tries to update the index of the first chunk that has space left for at least one entity.

Warning
Always use in tandem with foc_free_chunk() and remove_entity()

Member Data Documentation

◆ MAX_ARCHETYPE_LIFESPAN

constexpr uint16_t gaia::ecs::Archetype::MAX_ARCHETYPE_LIFESPAN = (1 << ARCHETYPE_LIFESPAN_BITS) - 1
staticconstexpr

Archetype lifespan must be at least as long as chunk lifespan.

Number of ticks before empty chunks are removed


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