Gaia-ECS v0.9.3
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::ecs::QueryInfo Class Reference

Classes

struct  CleanUpTmpArchetypeMatches
 

Public Types

enum class  MatchArchetypeQueryRet : uint8_t { Fail , Ok , Skip }
 Query matching result.
 
enum class  InvalidationKind : uint8_t { Result , Seed , All }
 

Public Member Functions

void add_ref ()
 
void dec_ref ()
 
uint32_t refs () const
 
void init (World *world)
 
void reset ()
 
void invalidate (InvalidationKind kind=InvalidationKind::All)
 
void invalidate_seed ()
 
void invalidate_result ()
 
void invalidate_sort ()
 Marks the cached sorted slices dirty without invalidating query membership.
 
void compile (const EntityToArchetypeMap &entityToArchetypeMap, std::span< const Archetype * > allArchetypes)
 Compile the query terms into a form we can easily process.
 
void recompile ()
 Recompile the query.
 
GAIA_NODISCARD QueryCtx::CachePolicy cache_policy () const
 
GAIA_NODISCARD bool has_grouped_payload () const
 
GAIA_NODISCARD bool has_sorted_payload () const
 
GAIA_NODISCARD uint32_t reverse_index_revision () const
 
GAIA_NODISCARD bool can_update_with_new_archetype () const
 
GAIA_NODISCARD bool can_use_direct_create_archetype_match () const
 Returns whether create-time matching should bypass the temporary one-archetype VM path.
 
GAIA_NODISCARD bool direct_create_archetype_match_uses_is () const
 Returns whether direct create-time matching needs Is-aware id checks.
 
GAIA_NODISCARD bool operator== (const QueryCtx &other) const
 
GAIA_NODISCARD bool operator!= (const QueryCtx &other) const
 
template<typename ArchetypeLookup >
void match (const ArchetypeLookup &entityToArchetypeMap, std::span< const Archetype * > allArchetypes, ArchetypeId archetypeLastId, const cnt::sarray< Entity, MaxVarCnt > &runtimeVarBindings, uint8_t runtimeVarBindingMask)
 Tries to match the query against archetypes in entityToArchetypeMap. This is necessary so we do not iterate all chunks over and over again when running queries.
 
bool match_one (const Archetype &archetype, EntitySpan targetEntities, const cnt::sarray< Entity, MaxVarCnt > &runtimeVarBindings, uint8_t runtimeVarBindingMask)
 Tries to match the query against the provided archetype. This is necessary so we do not iterate all chunks over and over again when running queries.
 
void ensure_matches (const EntityToArchetypeMap &entityToArchetypeMap, std::span< const Archetype * > allArchetypes, ArchetypeId archetypeLastId, const cnt::sarray< Entity, MaxVarCnt > &runtimeVarBindings, uint8_t runtimeVarBindingMask)
 
void ensure_matches_transient (const EntityToArchetypeMap &entityToArchetypeMap, std::span< const Archetype * > allArchetypes, const cnt::sarray< Entity, MaxVarCnt > &runtimeVarBindings, uint8_t runtimeVarBindingMask)
 
bool ensure_matches_one (const Archetype &archetype, EntitySpan targetEntities, const cnt::sarray< Entity, MaxVarCnt > &runtimeVarBindings, uint8_t runtimeVarBindingMask)
 
bool ensure_matches_one_transient (const Archetype &archetype, EntitySpan targetEntities, const cnt::sarray< Entity, MaxVarCnt > &runtimeVarBindings, uint8_t runtimeVarBindingMask)
 
bool register_archetype (const Archetype &archetype, Entity matchedSelector=EntityBad, bool assumeNew=false)
 
void calculate_sort_data ()
 Calculates the sort data for the archetypes in the cache. This allows us to iterate entites in the order they are sorted across all archetypes.
 
void sort_entities ()
 
void sort_cache_groups ()
 
void swap_archetype_cache_entry (uint32_t left, uint32_t right)
 
void ensure_comp_indices ()
 
GAIA_NODISCARD bool has_inherited_data_payload () const
 
void ensure_inherited_data ()
 
void ensure_group_data ()
 
void ensure_depth_order_hierarchy_barrier_cache_inter ()
 
ArchetypeCompIndices create_comp_indices (const Archetype *pArchetype)
 
void create_inherited_data (const Archetype *pArchetype)
 
void add_archetype_to_cache_no_grouping (const Archetype *pArchetype, bool trackMembershipChange, bool assumeAbsent=false)
 
void add_archetype_to_seed_cache (const Archetype *pArchetype, bool assumeAbsent=false)
 
void add_new_archetype_to_immediate_caches (const Archetype *pArchetype, bool trackMembershipChange)
 Adds a newly matched archetype to both immediate caches while reusing one computed index mapping.
 
void add_archetype_to_cache_w_grouping (const Archetype *pArchetype, bool trackMembershipChange, bool assumeAbsent=false)
 
void add_archetype_to_cache (const Archetype *pArchetype, bool trackMembershipChange, bool assumeAbsent=false)
 
void add_archetype_to_transient_cache (const Archetype *pArchetype)
 
GAIA_NODISCARD const GroupData * selected_group_data (GroupId runtimeGroupId) const
 Returns cached group bounds for the currently selected group filter. The cached range is invalidated whenever group layout changes or the selected group id changes.
 
GAIA_NODISCARD bool has_same_result_membership_as_seed_cache () const
 
void sync_result_cache_from_seed_cache ()
 
bool del_archetype_from_cache (const Archetype *pArchetype)
 
bool del_archetype_from_seed_cache (const Archetype *pArchetype)
 
GAIA_NODISCARD Worldworld ()
 
GAIA_NODISCARD const Worldworld () const
 
GAIA_NODISCARD QuerySerBufferser_buffer ()
 
void ser_buffer_reset ()
 
GAIA_NODISCARD QueryCtxctx ()
 
GAIA_NODISCARD const QueryCtxctx () const
 
GAIA_NODISCARD util::str bytecode () const
 
GAIA_NODISCARD uint32_t op_count () const
 
GAIA_NODISCARD uint64_t op_signature () const
 
GAIA_NODISCARD bool has_filters () const
 
GAIA_NODISCARD bool has_entity_filter_terms () const
 Returns true when direct non-fragmenting terms must be rechecked per entity.
 
GAIA_NODISCARD QueryCtx::DirectTargetEvalKind direct_target_eval_kind () const
 
GAIA_NODISCARD Entity direct_target_eval_id () const
 
GAIA_NODISCARD bool matches_prefab_entities () const
 Returns true when prefab-tagged entities should participate in query results.
 
template<typename... T>
GAIA_NODISCARD bool has_any () const
 
template<typename... T>
GAIA_NODISCARD bool has_or () const
 
template<typename... T>
GAIA_NODISCARD bool has_all () const
 
template<typename... T>
GAIA_NODISCARD bool has_no () const
 
void remove (Archetype *pArchetype)
 Removes an archetype from cache.
 
std::span< const uint8_t > indices_mapping_view (uint32_t archetypeIdx) const
 Returns a view of indices mapping for component entities in a given archetype.
 
InheritedTermDataView inherited_data_view (uint32_t archetypeIdx) const
 
InheritedTermDataView inherited_data_view (const Archetype *pArchetype) const
 
void ensure_depth_order_hierarchy_barrier_cache ()
 
std::span< const uint8_t > try_indices_mapping_view (const Archetype *pArchetype) const
 Returns a cached indices mapping view for an exact archetype match, or an empty span when absent.
 
InheritedTermDataView try_inherited_data_view (const Archetype *pArchetype) const
 
GAIA_NODISCARD GroupId group_id (uint32_t archetypeIdx) const
 
GAIA_NODISCARD bool barrier_passes (uint32_t archetypeIdx) const
 
GAIA_NODISCARD CArchetypeDArray::iterator begin ()
 
GAIA_NODISCARD CArchetypeDArray::const_iterator begin () const
 
GAIA_NODISCARD CArchetypeDArray::const_iterator cbegin () const
 
GAIA_NODISCARD CArchetypeDArray::iterator end ()
 
GAIA_NODISCARD CArchetypeDArray::const_iterator end () const
 
GAIA_NODISCARD CArchetypeDArray::const_iterator cend () const
 
GAIA_NODISCARD std::span< const Archetype * > cache_archetype_view () const
 
GAIA_NODISCARD std::span< const SortData > cache_sort_view () const
 
GAIA_NODISCARD std::span< const GroupData > group_data_view () const
 

Static Public Member Functions

static GAIA_NODISCARD QueryInfo create (QueryId id, QueryCtx &&ctx, const EntityToArchetypeMap &entityToArchetypeMap, std::span< const Archetype * > allArchetypes)
 
static GAIA_NODISCARD QueryInfo create (uint32_t idx, uint32_t gen, void *pCtx)
 
static GAIA_NODISCARD QueryHandle handle (const QueryInfo &info)
 

Public Attributes

uint32_t idx = 0
 Allocated items: index in the query slot list. Deleted items: index of the next deleted item in the slot list.
 
uint32_t gen = 0
 Generation ID of the query slot.
 

Member Enumeration Documentation

◆ InvalidationKind

enum class gaia::ecs::QueryInfo::InvalidationKind : uint8_t
strong
Enumerator
Result 

Only the final result cache is stale. Structural seed matches remain valid and can be reused.

Seed 

Structural seed matches are stale. This also implies the final result cache must be rebuilt.

All 

Full invalidation of all query cache state.

Member Function Documentation

◆ match()

template<typename ArchetypeLookup >
void gaia::ecs::QueryInfo::match ( const ArchetypeLookup &  entityToArchetypeMap,
std::span< const Archetype * >  allArchetypes,
ArchetypeId  archetypeLastId,
const cnt::sarray< Entity, MaxVarCnt > &  runtimeVarBindings,
uint8_t  runtimeVarBindingMask 
)
inline

Tries to match the query against archetypes in entityToArchetypeMap. This is necessary so we do not iterate all chunks over and over again when running queries.

Parameters
entityToArchetypeMapLookup of archetypes by queried id
allArchetypesList of all archetypes
archetypeLastIdLast recorded archetype id
Warning
Not thread safe. No two threads can call this at the same time.

◆ match_one()

bool gaia::ecs::QueryInfo::match_one ( const Archetype archetype,
EntitySpan  targetEntities,
const cnt::sarray< Entity, MaxVarCnt > &  runtimeVarBindings,
uint8_t  runtimeVarBindingMask 
)
inline

Tries to match the query against the provided archetype. This is necessary so we do not iterate all chunks over and over again when running queries.

Parameters
archetypeArchtype to match
targetEntitiesEntities related to the matched archetype
Warning
Not thread safe. No two threads can call this at the same time.

◆ remove()

void gaia::ecs::QueryInfo::remove ( Archetype pArchetype)
inline

Removes an archetype from cache.

Parameters
pArchetypeArchetype to remove

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