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

Builds, caches, and executes a Gaia-ECS query. More...

#include <query.h>

Classes

struct  IterModeAcceptAll
 Tag selecting unconstrained row iteration for prepared query iteration. More...
 
struct  IterModeDisabledOnly
 Tag selecting disabled-only row constraints for prepared query iteration. More...
 
struct  IterModeEnabled
 Tag selecting enabled-only row constraints for prepared query iteration. More...
 
class  OrderByTravView
 Lightweight view that executes a query in deterministic relation traversal order. More...
 
class  ParallelScope
 Records OnSet notifications and sorted-query invalidations produced by a parallel region instead of applying them from worker threads, then applies them on the coordinator thread once the region joins. Observers therefore always run on the thread that started the query, in work-item order, exactly like the serial path. Sorted-query invalidation flips a shared SortEntities dirty bit that is not safe to touch from a worker thread. The observer channel is active only when GAIA_OBSERVERS_ENABLED; the sorted-query channel always defers. More...
 
class  ParallelSlot
 Binds a parallel work-item range to its shared deferred-notification slot for the lifetime of the scope. Work items are distributed in disjoint ranges, so the first item of a range identifies a queue no other thread writes to. Both the observer (OnSet) and sorted-query-invalidation deferral channels read this same slot, so a single binding serves both. More...
 
struct  QueryCacheRange
 Cache range selected by the query's optional group id filter. More...
 
struct  QueryPlan
 Prepared query execution metadata shared by typed callbacks and public Iter callbacks. More...
 

Public Types

enum class  ExecPayloadKind : uint8_t { Plain , Grouped , NonTrivial }
 Runtime payload layout required by generic chunk-batch execution. More...
 
enum class  QueryPlanMode : uint8_t {
  Empty , General , EntitySeed , DirectDense ,
  MappedDense , SparseDense , Sorted , Traversal
}
 Prepared query runner mode shared by typed callbacks and public Iter callbacks. More...
 
enum  QueryPlanFlags : uint8_t {
  QueryPlanFlag_None = 0 , QueryPlanFlag_Filtered = 1 << 0 , QueryPlanFlag_EntityFilter = 1 << 1 , QueryPlanFlag_InheritedPayload = 1 << 2 ,
  QueryPlanFlag_Grouped = 1 << 3 , QueryPlanFlag_Sorted = 1 << 4 , QueryPlanFlag_BarrierCache = 1 << 5
}
 Orthogonal flags attached to a prepared query plan. More...
 

Public Member Functions

QueryInfofetch ()
 Fetches the QueryInfo object. Creates or refreshes the backing QueryInfo if needed.
 
void match_all (QueryInfo &queryInfo)
 Matches the query against all relevant archetypes.
 
GAIA_NODISCARD bool match_one (QueryInfo &queryInfo, const Archetype &archetype, EntitySpan targetEntities)
 Matches the query against a single archetype.
 
GAIA_NODISCARD bool matches_any (QueryInfo &queryInfo, const Archetype &archetype, EntitySpan targetEntities)
 Returns whether any supplied target entity matches the query on archetype.
 
GAIA_NODISCARD QueryCachePolicy cache_policy ()
 Returns the effective cache policy chosen for the query.
 
QueryImplcache_src_trav (uint16_t maxItems)
 Enables traversed-source snapshot reuse and caps the cached source closure size. This only matters for queries using traversed sources (for example src(...).trav()). For queries without source traversal the value is normalized away, so it does not affect shared cache identity. Use this only when traversed source closures stay small and stable enough for snapshot reuse to be cheaper than rebuilding them on demand.
 
GAIA_NODISCARD uint16_t cache_src_trav () const
 Returns the traversed-source snapshot cap. 0 disables explicit traversed-source snapshot caching.
 
QueryImplkind (QueryCacheKind cacheKind)
 Sets the hard cache-kind requirement for the query.
 
QueryImplscope (QueryCacheScope cacheScope)
 Sets the cache scope used by cached queries.
 
QueryImplmatch_prefab ()
 Makes the query include prefab entities in matches.
 
GAIA_NODISCARD QueryCacheScope scope () const
 Returns the currently requested cache scope.
 
GAIA_NODISCARD QueryCacheKind kind () const
 Returns the currently requested cache kind.
 
GAIA_NODISCARD QueryKindRes kind_error ()
 Returns the validation result for the current query shape and requested kind.
 
GAIA_NODISCARD const char * kind_error_str ()
 Returns a human-readable description of the current kind validation result.
 
GAIA_NODISCARD bool valid ()
 Returns whether the current query shape satisfies the requested kind.
 
GAIA_NODISCARD bool can_process_archetype (const QueryInfo &queryInfo, const Archetype &archetype) const
 Returns whether an archetype is eligible for query execution.
 
GAIA_NODISCARD bool can_process_archetype_inter (const QueryInfo &queryInfo, const Archetype &archetype, Constraints constraints, int8_t barrierPasses=-1) const
 Checks whether a matched archetype can be processed for the current row constraints.
 
GAIA_NODISCARD QueryPlan prepare_query_plan (const QueryInfo &queryInfo, Constraints constraints) const
 Selects the prepared execution plan for public iterator callbacks.
 
template<bool HasFilters, bool HasGroups, typename Func >
void run_query_on_chunks_runtime_direct_plain_impl (QueryInfo &queryInfo, const QueryPlan &plan, Constraints constraints, Func &func)
 Runs a public Iter callback over cached chunks without creating chunk batches.
 
template<QueryExecType ExecType, typename Func >
void each_runtime_inter (Func func, Constraints constraints=Constraints::EnabledOnly)
 Runs a public iterator callback through the fastest supported runtime path.
 
void each_runtime_erased (QueryExecType execType, void *pFunc, void(*invoke)(void *, Iter &), Constraints constraints)
 Runs a type-erased public iterator callback through generic query execution.
 
void each_runtime_erased (QueryInfo &queryInfo, const QueryPlan &plan, QueryExecType execType, void *pFunc, void(*invoke)(void *, Iter &), Constraints constraints)
 Runs a type-erased public iterator callback using an already prepared query cache and plan.
 
void each_direct_inter (QueryInfo &queryInfo, Constraints constraints, void *pFunc, const TypedQueryExecState &state, void(*runDirectChunk)(QueryImpl &, Iter &, void *, const TypedQueryExecState &), bool needsInheritedArgIds, void(*invokeInherited)(World &, Entity, const Entity *, void *))
 Runs an erased typed callback over entities selected by a direct sparse or target-term seed.
 
 QueryImpl (World &world, QueryCache &queryCache, ArchetypeId &nextArchetypeId, uint32_t &worldVersion, const EntityToArchetypeMap &entityToArchetypeMap, const EntityToArchetypeVersionMap &entityToArchetypeMapVersions, const ArchetypeDArray &allArchetypes)
 Creates a query bound to a world's query and archetype state.
 
GAIA_NODISCARD QueryId id () const
 Returns the cache handle id of this query.
 
GAIA_NODISCARD uint32_t gen () const
 Returns the cache handle generation of this query.
 
void reset ()
 Release any data allocated by the query.
 
void destroy ()
 Destroys the current cached query state and local scratch data.
 
GAIA_NODISCARD bool is_cached () const
 Returns whether the query is stored in the query cache.
 
QueryImpladd (const char *str,...)
 Creates a query from a null-terminated expression string.
 
QueryImpladd (QueryInput item)
 Adds a prebuilt query input item.
 
QueryImplis (Entity entity, const QueryTermOptions &options=QueryTermOptions{})
 Adds a semantic Is(entity) requirement.
 
QueryImplin (Entity entity, QueryTermOptions options=QueryTermOptions{})
 Adds an inherited in(entity) requirement.
 
QueryImplall (Entity entity, const QueryTermOptions &options=QueryTermOptions{})
 Adds a required entity or pair term.
 
template<typename T >
QueryImplall (const QueryTermOptions &options)
 Adds a required typed term.
 
template<typename T >
QueryImplall ()
 Adds a required typed term.
 
QueryImplany (Entity entity, const QueryTermOptions &options=QueryTermOptions{})
 Adds an optional entity or pair term.
 
template<typename T >
QueryImplany (const QueryTermOptions &options)
 Adds an optional typed term.
 
template<typename T >
QueryImplany ()
 Adds an optional typed term.
 
QueryImplor_ (Entity entity, const QueryTermOptions &options=QueryTermOptions{})
 OR terms (at least one has to match). A single OR term is canonicalized to ALL during query normalization.
 
template<typename T >
QueryImplor_ (const QueryTermOptions &options)
 Adds an OR typed term.
 
template<typename T >
QueryImplor_ ()
 Adds an OR typed term.
 
QueryImplno (Entity entity, const QueryTermOptions &options=QueryTermOptions{})
 Adds an excluded entity or pair term.
 
template<typename T >
QueryImplno (const QueryTermOptions &options)
 Adds an excluded typed term.
 
template<typename T >
QueryImplno ()
 Adds an excluded typed term.
 
QueryImplvar_name (Entity varEntity, util::str_view name)
 Assigns a human-readable name to a query variable entity (Var0..Var7). The name can be used later by set_var(name, value).
 
QueryImplvar_name (Entity varEntity, const char *name)
 Assigns a human-readable name to a query variable entity (Var0..Var7).
 
QueryImplset_var (Entity varEntity, Entity value)
 Binds a query variable (Var0..Var7) to a concrete entity value. Bound values are applied at runtime before query evaluation.
 
QueryImplset_var (util::str_view name, Entity value)
 Binds a named query variable to a concrete entity value.
 
QueryImplset_var (const char *name, Entity value)
 Binds a named query variable to a concrete entity value.
 
QueryImplclear_var (Entity varEntity)
 Clears binding for a single query variable (Var0..Var7). The variable becomes unbound for the next query evaluation.
 
QueryImplclear_vars ()
 Clears all runtime variable bindings.
 
QueryImplchanged (Entity entity)
 Marks a runtime component or pair for changed() filtering.
 
template<typename T >
QueryImplchanged ()
 Marks a typed term for changed() filtering.
 
QueryImplsort_by (Entity entity, TSortByFunc func)
 Sorts the query by the specified entity and function.
 
template<typename T >
QueryImplsort_by (TSortByFunc func)
 Sorts the query by the specified component and function.
 
template<typename Rel , typename Tgt >
QueryImplsort_by (TSortByFunc func)
 Sorts the query by the specified pair and function.
 
GAIA_NODISCARD OrderByTravView order_by (Entity relation, TravOrder order)
 Iterates matching entities in an explicit relation traversal order.
 
template<typename Rel >
GAIA_NODISCARD OrderByTravView order_by (TravOrder order)
 Iterates matching entities in an explicit typed relation traversal order.
 
QueryImpldepth_order (Entity relation=ChildOf)
 Orders cached query entries by fragmenting relation depth so iteration runs breadth-first top-down. Intended only for fragmenting relations such as ChildOf or DependsOn where the target participates in archetype identity. Unlike order_by(relation, TravOrder), this affects the cached query iteration order itself and can therefore prune fragmenting disabled subtrees at the archetype level. For non-fragmenting relations such as Parent, use order_by(...) instead.
 
template<typename Rel >
QueryImpldepth_order ()
 Orders cached query entries by fragmenting relation depth so iteration runs breadth-first top-down.
 
QueryImplgroup_by (Entity entity, TGroupByFunc func=group_by_func_default)
 Organizes matching archetypes into groups according to the grouping function and entity. Does not order iteration by group id. Use group_id(...) to filter one group. Use depth_order(...) or sort_by(...) when iteration order matters.
 
template<typename T >
QueryImplgroup_by (TGroupByFunc func=group_by_func_default)
 Organizes matching archetypes into groups according to the grouping function. Does not order iteration by group id. Use group_id(...) to filter one group. Use depth_order(...) or sort_by(...) when iteration order matters.
 
template<typename Rel , typename Tgt >
QueryImplgroup_by (TGroupByFunc func=group_by_func_default)
 Organizes matching archetypes into groups according to the grouping function. Does not order iteration by group id. Use group_id(...) to filter one group. Use depth_order(...) or sort_by(...) when iteration order matters.
 
QueryImplgroup_dep (Entity relation)
 Declares an explicit relation dependency for grouped cache invalidation. Useful for custom group_by callbacks that depend on hierarchy or relation topology.
 
template<typename Rel >
QueryImplgroup_dep ()
 Declares an explicit relation dependency for grouped cache invalidation. Useful for custom group_by callbacks that depend on hierarchy or relation topology.
 
QueryImplgroup_id (GroupId groupId)
 Selects the group to iterate over.
 
QueryImplgroup_id (Entity entity)
 Selects the group to iterate over.
 
template<typename T >
QueryImplgroup_id ()
 Selects the group to iterate over.
 
template<typename Container >
void groups (Container &out, bool sortGroups)
 Collects active non-zero group ids for a grouped query. The ids can be fed back to group_id(...) to process each group without knowing group ids ahead of time.
 
template<typename Func >
GAIA_NODISCARD SchedJob job (Func func, QueryExecType execType)
 Adds a query execution job without submitting it.
 
template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void each (Func func)
 Iterates query matches using the default execution mode.
 
template<typename Func , std::enable_if_t<!detail::is_query_iter_callback_v< Func >, int > = 0>
void each (Func func)
 Iterates query matches with a typed component callback using the default execution mode.
 
template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void each (Func func, QueryExecType execType)
 Iterates query matches using the selected execution mode.
 
template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void each (Func func, Constraints constraints)
 Iterates query matches with an iterator callback under the selected row constraints.
 
template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void each (Func func, QueryExecType execType, Constraints constraints)
 Iterates query matches with an iterator callback using the selected execution mode and row constraints.
 
template<typename Func , std::enable_if_t<!detail::is_query_iter_callback_v< Func >, int > = 0>
void each (Func func, QueryExecType execType)
 Iterates query matches with a typed component callback using the selected execution mode.
 
template<typename Func >
void each_iter (Iter &it, Func func)
 Runs a typed callback against an already prepared iterator. This is used by higher-level adapters that normalize execution to Iter& first and then materialize typed arguments on top of the iterator.
 
template<typename Func >
void each_arch (Func func, Constraints constraints=Constraints::EnabledOnly)
 Iterates matching archetypes instead of individual entities.
 
bool empty (Constraints constraints=Constraints::EnabledOnly)
 Returns true or false depending on whether there are any entities matching the query.
 
uint32_t count (Constraints constraints=Constraints::EnabledOnly)
 Calculates the number of entities matching the query.
 
void each_entity_enabled (void *pCtx, void(*func)(void *, Entity))
 Iterates matching enabled entities through a non-template erased callback.
 
template<typename Container >
void arr (Container &outArray, Constraints constraints=Constraints::EnabledOnly)
 Appends all components or entities matching the query to the output array.
 
GAIA_NODISCARD std::span< const Entityordered_entities_walk (QueryInfo &queryInfo, Entity relation, TravOrder order, Constraints constraints=Constraints::EnabledOnly)
 Builds and caches relation traversal order for the current query result.
 
template<typename Func , std::enable_if_t< detail::is_query_walk_core_callback_v< Func >, int > = 0>
void each_walk (Func func, Entity relation, TravOrder order=TravOrder::Down, Constraints constraints=Constraints::EnabledOnly)
 Iterates entities matching the query in a requested relation traversal order. For relation R this treats Pair(R, X) on entity E as "E points at X". Traversal changes only visit order. Nodes with the same parent are ordered by entity id.
 
template<typename Func , std::enable_if_t<!detail::is_query_walk_core_callback_v< Func >, int > = 0>
void each_walk (Func func, Entity relation, TravOrder order=TravOrder::Down, Constraints constraints=Constraints::EnabledOnly)
 Iterates matching entities in relation order with a typed component callback.
 
void diag ()
 Run diagnostics.
 
GAIA_NODISCARD util::str bytecode ()
 Returns a textual dump of the generated query VM bytecode.
 
void diag_bytecode ()
 Prints a textual dump of the generated query VM bytecode.
 
Query context

Stores raw, user-owned data on this query and exposes it to iterator-style callbacks.

See also
Iter::ctx() const
SystemBuilder::ctx(void*)
QueryImplctx (void *pCtx)
 Sets the user-owned context pointer visible through Iter::ctx() during iterator callbacks. Changing the pointer does not affect query identity, query matching, shared-cache lookup, or cached query storage. Identical shared-cache query shapes may therefore keep different context pointers.
 
GAIA_NODISCARD void * ctx () const
 Returns the user-owned context pointer attached to this query.
 
Scheduling declarations

Scheduling metadata used when coordinating query execution.

QueryImplmain_thread (bool required=true)
 Marks whether this query must run on the main thread/serial path.
 
GAIA_NODISCARD bool main_thread_required () const
 Returns whether this query must run on the main thread/serial path.
 
Query access declarations

Explicit access metadata for data used outside positive query terms.

QueryImplreads (Entity entity)
 Declares an additional id read by this query callback.
 
template<typename T >
QueryImplreads ()
 Declares an additional component or pair type read by this query callback.
 
QueryImplwrites (Entity entity)
 Declares an additional id written by this query callback.
 
template<typename T >
QueryImplwrites ()
 Declares an additional component or pair type written by this query callback.
 
GAIA_NODISCARD std::span< const Entitycustom_reads () const
 Returns explicitly declared read ids that are not query terms.
 
GAIA_NODISCARD std::span< const Entitycustom_writes () const
 Returns explicitly declared write ids that are not query terms.
 
GAIA_NODISCARD QueryAccess access (Entity entity)
 Returns the effective read/write access for an id.
 
GAIA_NODISCARD bool conflicts_with (QueryImpl &other)
 Returns whether this query conflicts with another query's effective access declarations.
 
GAIA_NODISCARD bool can_run_parallel (QueryImpl &other)
 Returns whether this query can run concurrently with another query based on declared scheduling metadata.
 

Static Public Member Functions

static GAIA_NODISCARD bool match_filters (const Chunk &chunk, const QueryInfo &queryInfo, uint32_t changedWorldVersion, std::span< const uint8_t > compIndices)
 Returns whether a chunk passes the query's changed filters.
 
static GAIA_NODISCARD bool match_filters (const Chunk &chunk, const QueryInfo &queryInfo, uint32_t changedWorldVersion)
 Returns whether a chunk passes the query's changed filters.
 
static GAIA_NODISCARD bool has_depth_order_hierarchy_enabled_barrier (const QueryInfo &queryInfo)
 Checks whether depth-order grouping can prune disabled hierarchy subtrees.
 
static GAIA_NODISCARD bool needs_depth_order_hierarchy_barrier_cache (const QueryInfo &queryInfo, Constraints constraints)
 Checks whether the current row constraints require the depth-order hierarchy barrier cache.
 
static void chunk_effective_range (Chunk *pChunk, Constraints constraints, bool needsBarrierCache, bool barrierPasses, uint16_t &from, uint16_t &to) noexcept
 Calculates the row range of a chunk after applying row constraints and depth-order barrier state.
 
static GAIA_NODISCARD bool depth_order_hierarchy_barrier_prunes (const QueryInfo &queryInfo)
 Checks whether cached depth-order barrier results can prune any matched archetype.
 
static GAIA_NODISCARD bool survives_cascade_hierarchy_enabled_barrier (const QueryInfo &queryInfo, const Archetype &archetype)
 Fast enabled-subtree gate for cached depth_order(...) queries over fragmenting hierarchy relations. ChildOf is the native built-in example, but the rule is semantic: the relation must support depth_order(...) and also form a fragmenting hierarchy chain. For such relations, all rows in the archetype share the same direct parent target. That lets us prune the entire archetype when its parent chain crosses a disabled entity. Non-fragmenting hierarchy relations such as Parent cannot use this archetype-level check and must stay on the per-entity traversal path instead.
 
static GAIA_NODISCARD ExecPayloadKind exec_payload_kind (const QueryInfo &queryInfo, Constraints constraints)
 Classifies the generic batch payload needed for a matched query under row constraints.
 
template<typename TMode >
static GAIA_NODISCARD constexpr Constraints iter_mode_constraints ()
 Maps an iteration-mode tag to the runtime row constraints used by iterators.
 
template<typename Func , typename TMode >
static void run_query_func (World *pWorld, Func func, ChunkBatch &batch)
 Executes an iterator callback for one prepared chunk batch.
 
template<typename Func >
static void run_query_arch_func (World *pWorld, Func func, ChunkBatch &batch, Constraints constraints)
 Executes an archetype-level iterator callback for one prepared chunk batch. The iterator is initialized with archetype metadata but no chunk rows.
 
template<typename Func , typename TMode >
static void run_query_func (World *pWorld, Func func, std::span< ChunkBatch > batches)
 Executes an iterator callback over a contiguous list of prepared chunk batches.
 
template<typename Func , typename TIter >
static void invoke_runtime_iter (void *pFunc, TIter &it)
 Invokes a type-erased public iterator callback.
 
static GAIA_NODISCARD bool is_non_fragmenting_direct_term (const World &world, const QueryTerm &term)
 Returns whether a direct term is backed by non-fragmenting storage and must be evaluated per entity.
 
static GAIA_NODISCARD bool uses_semantic_is_matching (const QueryTerm &term)
 Returns whether a term uses semantic Is matching rather than direct storage matching.
 
static GAIA_NODISCARD bool uses_in_is_matching (const QueryTerm &term)
 Returns whether a term uses strict semantic Is matching that excludes the base entity itself.
 
static GAIA_NODISCARD bool uses_non_direct_is_matching (const QueryTerm &term)
 Returns whether a term uses any semantic Is matching rather than direct storage matching.
 
static GAIA_NODISCARD bool uses_potential_inherited_id_matching (const QueryTerm &term)
 Returns whether a term could use inherited-id matching based on query shape alone. This intentionally ignores mutable world metadata such as current OnInstantiate policy.
 
static GAIA_NODISCARD bool uses_inherited_id_matching (const World &world, const QueryTerm &term)
 Returns whether a term uses semantic inherited-id matching rather than direct storage matching.
 

Static Public Attributes

static bool SilenceInvalidCacheKindAssertions = false
 Suppresses assertions when an invalid cache-kind combination is queried for diagnostics.
 

Friends

class SystemBuilder
 

Detailed Description

Builds, caches, and executes a Gaia-ECS query.

Member Enumeration Documentation

◆ ExecPayloadKind

enum class gaia::ecs::detail::QueryImpl::ExecPayloadKind : uint8_t
strong

Runtime payload layout required by generic chunk-batch execution.

Enumerator
Plain 

Plain batches without group ids, inherited data, sorted slices, or barrier metadata.

Grouped 

Batches carry group ids but do not require sorted slices or inherited/barrier metadata.

NonTrivial 

Batches require non-trivial side payload such as sorted slices, inherited data, or barriers.

◆ QueryPlanFlags

Orthogonal flags attached to a prepared query plan.

Flags describe properties that can apply to multiple runner modes. Keep them separate from QueryPlanMode so filtered and unfiltered variants do not multiply execution-mode values.

Enumerator
QueryPlanFlag_None 

No additional query-plan properties are present.

QueryPlanFlag_Filtered 

The query has per-chunk filters such as changed terms.

QueryPlanFlag_EntityFilter 

The query has entity-filter terms that require per-entity rechecks.

QueryPlanFlag_InheritedPayload 

The query carries inherited component data into iterator payloads.

QueryPlanFlag_Grouped 

The query uses grouped payload/ranges or grouped cache ordering.

QueryPlanFlag_Sorted 

The plan may need sorted cache slices. Runners use them only with non-trivial payload.

QueryPlanFlag_BarrierCache 

The plan must use the depth-order hierarchy barrier cache when checking archetype/row ranges.

◆ QueryPlanMode

enum class gaia::ecs::detail::QueryImpl::QueryPlanMode : uint8_t
strong

Prepared query runner mode shared by typed callbacks and public Iter callbacks.

The mode is selected after the query cache has been matched. It describes the runner family independently from orthogonal query properties such as filters. Public C++ templates are expected to remain thin adapters on top of this prepared execution metadata.

Enumerator
Empty 

The selected group/range has no matching archetypes, so execution can return immediately.

General 

Use the generic query execution path because no specialized runner is valid.

EntitySeed 

Direct entity-seed evaluation over explicitly selected entities.

DirectDense 

Direct cached archetype/chunk iteration with query-term indices matching storage layout.

MappedDense 

Typed dense cached archetype/chunk iteration using mapped component access. Public Iter callbacks use DirectDense with iterator component-index mapping instead.

SparseDense 

Typed cached chunk iteration with compile-time sparse payload access.

Sorted 

Sorted payload execution that must preserve cache-provided chunk order.

Traversal 

Traversal or inherited payload execution that requires the mapped generic path.

Constructor & Destructor Documentation

◆ QueryImpl()

gaia::ecs::detail::QueryImpl::QueryImpl ( World world,
QueryCache &  queryCache,
ArchetypeId &  nextArchetypeId,
uint32_t &  worldVersion,
const EntityToArchetypeMap &  entityToArchetypeMap,
const EntityToArchetypeVersionMap &  entityToArchetypeMapVersions,
const ArchetypeDArray &  allArchetypes 
)
inline

Creates a query bound to a world's query and archetype state.

Parameters
worldWorld that owns the query.
queryCacheCache used to store prepared query data.
nextArchetypeIdHighest archetype identifier allocated by the world.
worldVersionCurrent world version used by changed filters.
entityToArchetypeMapEntity-to-archetype lookup used during matching.
entityToArchetypeMapVersionsVersions associated with entity-to-archetype mappings.
allArchetypesWorld archetypes available for query matching.

Member Function Documentation

◆ access()

GAIA_NODISCARD QueryAccess gaia::ecs::detail::QueryImpl::access ( Entity  entity)
inline

Returns the effective read/write access for an id.

Effective access combines positive query terms and explicit reads()/writes() declarations. Pair query terms do not imply data access. Use explicit reads(Entity) or writes(Entity) when a pair id is a custom scheduling key.

Parameters
entityComponent/entity id to inspect.
Returns
Effective access mode for the id.

◆ add() [1/2]

QueryImpl & gaia::ecs::detail::QueryImpl::add ( const char *  str,
  ... 
)
inline

Creates a query from a null-terminated expression string.

Expression is a string between separators. Spaces are trimmed automatically.

Supported modifiers: "," - separates expressions "||" - query::or_(OR chain with at least two OR terms) "?" - query::any (optional) "!" - query::none "&" - read-write access "%e" - entity value "(rel,tgt)" - relationship pair, a wildcard character in either rel or tgt is translated into All "$name" - query variable ($this is reserved) "Id(src)" - source lookup (src can be a variable, e.g. Planet($planet), or $this for default source)

Example: struct Position {...}; struct Velocity {...}; struct RigidBody {...}; struct Fuel {...}; auto player = w.add(); w.query().add("&Position, !Velocity, ?RigidBody, (Fuel,*), %e", player.value()); Translates into: w.query() .all<Position&>() .no<Velocity>() .any<RigidBody>() .all(Pair(w.add<Fuel>().entity, All)>() .all(Player);

Adds one or more query terms described by a string expression. Component names are resolved immediately while the expression is parsed and the resulting component ids are baked into the query terms. Later scope, path or alias changes do not rewrite an already parsed query. Names in str are resolved while add(...) parses the expression and the resulting ids are baked into the query. Active component scope and lookup-path state affect parsing only at that moment and do not rewrite the query later.

Parameters
strNull-terminated string with the query expression.
...Optional varargs consumed by e substitutions inside str.
Returns
Reference to this query.

◆ add() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::add ( QueryInput  item)
inline

Adds a prebuilt query input item.

Parameters
itemQuery term or filter description.
Returns
Self reference.

◆ all() [1/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::all ( )

Adds a required typed term.

Template Parameters
TComponent or pair type.
Returns
Self reference.

◆ all() [2/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::all ( const QueryTermOptions options)

Adds a required typed term.

Template Parameters
TComponent or pair type.
Parameters
optionsTerm options.
Returns
Self reference.

◆ all() [3/3]

QueryImpl & gaia::ecs::detail::QueryImpl::all ( Entity  entity,
const QueryTermOptions options = QueryTermOptions{} 
)
inline

Adds a required entity or pair term.

Parameters
entityRequired entity or pair id.
optionsTerm options.
Returns
Self reference.

◆ any() [1/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::any ( )

Adds an optional typed term.

Template Parameters
TComponent or pair type.
Returns
Self reference.

◆ any() [2/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::any ( const QueryTermOptions options)

Adds an optional typed term.

Template Parameters
TComponent or pair type.
Parameters
optionsTerm options.
Returns
Self reference.

◆ any() [3/3]

QueryImpl & gaia::ecs::detail::QueryImpl::any ( Entity  entity,
const QueryTermOptions options = QueryTermOptions{} 
)
inline

Adds an optional entity or pair term.

Parameters
entityOptional entity or pair id.
optionsTerm options.
Returns
Self reference.

◆ arr()

template<typename Container >
void gaia::ecs::detail::QueryImpl::arr ( Container &  outArray,
Constraints  constraints = Constraints::EnabledOnly 
)

Appends all components or entities matching the query to the output array.

Template Parameters
ContainerContainer type
Parameters
[out]outArrayContainer storing entities or components
constraintsQueryImpl constraints

◆ bytecode()

GAIA_NODISCARD util::str gaia::ecs::detail::QueryImpl::bytecode ( )
inline

Returns a textual dump of the generated query VM bytecode.

Returns
Bytecode dump.

◆ cache_policy()

GAIA_NODISCARD QueryCachePolicy gaia::ecs::detail::QueryImpl::cache_policy ( )
inline

Returns the effective cache policy chosen for the query.

Returns
Effective cache policy.

◆ cache_src_trav() [1/2]

GAIA_NODISCARD uint16_t gaia::ecs::detail::QueryImpl::cache_src_trav ( ) const
inline

Returns the traversed-source snapshot cap. 0 disables explicit traversed-source snapshot caching.

Returns
Traversed-source snapshot cap.

◆ cache_src_trav() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::cache_src_trav ( uint16_t  maxItems)
inline

Enables traversed-source snapshot reuse and caps the cached source closure size. This only matters for queries using traversed sources (for example src(...).trav()). For queries without source traversal the value is normalized away, so it does not affect shared cache identity. Use this only when traversed source closures stay small and stable enough for snapshot reuse to be cheaper than rebuilding them on demand.

Parameters
maxItemsMaximum number of traversed source entities retained in a snapshot. Zero disables explicit reuse.
Returns
Self reference.

◆ can_process_archetype()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::can_process_archetype ( const QueryInfo queryInfo,
const Archetype archetype 
) const
inline

Returns whether an archetype is eligible for query execution.

Parameters
queryInfoPrepared query metadata controlling prefab matching.
archetypeCandidate archetype.
Returns
True when the archetype is live and satisfies the query's prefab policy.

◆ can_process_archetype_inter()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::can_process_archetype_inter ( const QueryInfo queryInfo,
const Archetype archetype,
Constraints  constraints,
int8_t  barrierPasses = -1 
) const
inline

Checks whether a matched archetype can be processed for the current row constraints.

Parameters
queryInfoPrepared query cache and execution metadata.
archetypeMatched archetype to test.
constraintsEntity-row subset exposed to the callback.
barrierPassesCached barrier result, or -1 to compute the enabled hierarchy gate directly.
Returns
True when the archetype is eligible for callback execution.

◆ can_run_parallel()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::can_run_parallel ( QueryImpl other)
inline

Returns whether this query can run concurrently with another query based on declared scheduling metadata.

Parameters
otherQuery to compare against.
Returns
True when neither query requires the main thread and conflicts_with(other) is false.

◆ changed() [1/2]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::changed ( )

Marks a typed term for changed() filtering.

Template Parameters
TComponent or pair type.
Returns
Self reference.

◆ changed() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::changed ( Entity  entity)
inline

Marks a runtime component or pair for changed() filtering.

Parameters
entityComponent or pair id to monitor.
Returns
Self reference.

◆ chunk_effective_range()

static void gaia::ecs::detail::QueryImpl::chunk_effective_range ( Chunk pChunk,
Constraints  constraints,
bool  needsBarrierCache,
bool  barrierPasses,
uint16_t &  from,
uint16_t &  to 
)
inlinestaticnoexcept

Calculates the row range of a chunk after applying row constraints and depth-order barrier state.

Parameters
pChunkChunk to inspect.
constraintsEntity-row subset exposed to the callback.
needsBarrierCacheTrue when barrier state participates in row selection.
barrierPassesCached barrier result for the archetype containing the chunk.
fromReceives the first row to process.
toReceives the one-past-the-end row to process.

◆ clear_var()

QueryImpl & gaia::ecs::detail::QueryImpl::clear_var ( Entity  varEntity)
inline

Clears binding for a single query variable (Var0..Var7). The variable becomes unbound for the next query evaluation.

Parameters
varEntityQuery variable entity (Var0..Var7).
Returns
Self reference.

◆ clear_vars()

QueryImpl & gaia::ecs::detail::QueryImpl::clear_vars ( )
inline

Clears all runtime variable bindings.

Returns
Self reference.

◆ conflicts_with()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::conflicts_with ( QueryImpl other)
inline

Returns whether this query conflicts with another query's effective access declarations.

Two queries conflict when both access the same id and at least one side writes it. This check uses component access declared by positive query terms plus custom reads()/writes() declarations. It does not account for world structural mutation or arbitrary side effects.

Parameters
otherQuery to compare against.
Returns
True if the two queries should not run concurrently based on declared access.

◆ count()

uint32_t gaia::ecs::detail::QueryImpl::count ( Constraints  constraints = Constraints::EnabledOnly)
inline

Calculates the number of entities matching the query.

Warning
Only use if you only care about the number of entities matching the query. The result is not cached and repeated calls to the function might be slow.If you already called arr(), use the size provided by the array.Use empty() instead of calling count() == 0.
Note
For changed() queries this is a non-consuming probe. It does not advance the query's changed-reporting state. Iteration APIs such as each()/arr() do consume it.
Returns
The number of matching entities
Parameters
constraintsEntity-row subset included in the count.

◆ ctx() [1/2]

GAIA_NODISCARD void * gaia::ecs::detail::QueryImpl::ctx ( ) const
inline

Returns the user-owned context pointer attached to this query.

Returns
Context pointer, or null when none is attached.

◆ ctx() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::ctx ( void *  pCtx)
inline

Sets the user-owned context pointer visible through Iter::ctx() during iterator callbacks. Changing the pointer does not affect query identity, query matching, shared-cache lookup, or cached query storage. Identical shared-cache query shapes may therefore keep different context pointers.

Note
Gaia-ECS stores only the pointer. The caller owns allocation, lifetime, destruction, and any synchronization needed when a parallel query callback reads or writes the pointed-to data.
Parameters
pCtxContext pointer. May be null.
Returns
Self reference.

◆ custom_reads()

GAIA_NODISCARD std::span< const Entity > gaia::ecs::detail::QueryImpl::custom_reads ( ) const
inline

Returns explicitly declared read ids that are not query terms.

Returns
Read-only span over custom read declarations.

◆ custom_writes()

GAIA_NODISCARD std::span< const Entity > gaia::ecs::detail::QueryImpl::custom_writes ( ) const
inline

Returns explicitly declared write ids that are not query terms.

Returns
Read-only span over custom write declarations.

◆ depth_order() [1/2]

template<typename Rel >
QueryImpl & gaia::ecs::detail::QueryImpl::depth_order ( )

Orders cached query entries by fragmenting relation depth so iteration runs breadth-first top-down.

Template Parameters
RelFragmenting hierarchy relation, typically ChildOf.
Returns
Reference to this query builder.

◆ depth_order() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::depth_order ( Entity  relation = ChildOf)
inline

Orders cached query entries by fragmenting relation depth so iteration runs breadth-first top-down. Intended only for fragmenting relations such as ChildOf or DependsOn where the target participates in archetype identity. Unlike order_by(relation, TravOrder), this affects the cached query iteration order itself and can therefore prune fragmenting disabled subtrees at the archetype level. For non-fragmenting relations such as Parent, use order_by(...) instead.

Parameters
relationFragmenting hierarchy relation.
Returns
Reference to this query builder.

◆ depth_order_hierarchy_barrier_prunes()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::depth_order_hierarchy_barrier_prunes ( const QueryInfo queryInfo)
inlinestatic

Checks whether cached depth-order barrier results can prune any matched archetype.

Parameters
queryInfoPrepared query cache and execution metadata.
Returns
True when depth-order hierarchy barriers are active and the cache can prune rows.

◆ each() [1/6]

template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each ( Func  func)
inline

Iterates query matches using the default execution mode.

Template Parameters
FuncIterator callback type invocable with Iter&.
Parameters
funcCallable invoked for each match.
See also
Iter::ctx() const

◆ each() [2/6]

template<typename Func , std::enable_if_t<!detail::is_query_iter_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each ( Func  func)

Iterates query matches with a typed component callback using the default execution mode.

Template Parameters
FuncTyped callback whose arguments identify the requested query components.
Parameters
funcCallable invoked for each matching entity.

◆ each() [3/6]

template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each ( Func  func,
Constraints  constraints 
)
inline

Iterates query matches with an iterator callback under the selected row constraints.

Template Parameters
FuncIterator callback type invocable with Iter&.
Parameters
funcCallable invoked for each match.
constraintsEntity-row subset exposed to the callback.

◆ each() [4/6]

template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each ( Func  func,
QueryExecType  execType 
)
inline

Iterates query matches using the selected execution mode.

Template Parameters
FuncIterator callback type invocable with Iter&.
Parameters
funcCallable invoked for each match.
execTypeExecution mode.
See also
Iter::ctx() const

◆ each() [5/6]

template<typename Func , std::enable_if_t<!detail::is_query_iter_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each ( Func  func,
QueryExecType  execType 
)

Iterates query matches with a typed component callback using the selected execution mode.

Template Parameters
FuncTyped callback whose arguments identify the requested query components.
Parameters
funcCallable invoked for each matching entity.
execTypeExecution mode.

◆ each() [6/6]

template<typename Func , std::enable_if_t< detail::is_query_iter_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each ( Func  func,
QueryExecType  execType,
Constraints  constraints 
)
inline

Iterates query matches with an iterator callback using the selected execution mode and row constraints.

Template Parameters
FuncIterator callback type invocable with Iter&.
Parameters
funcCallable invoked for each match.
execTypeExecution mode.
constraintsEntity-row subset exposed to the callback.

◆ each_arch()

template<typename Func >
void gaia::ecs::detail::QueryImpl::each_arch ( Func  func,
Constraints  constraints = Constraints::EnabledOnly 
)
inline

Iterates matching archetypes instead of individual entities.

Template Parameters
FuncIterator callback type invocable with Iter&.
Parameters
funcCallable invoked for each matching archetype iterator.
constraintsIteration constraints applied before invoking func.
See also
Iter::ctx() const

◆ each_direct_inter()

void gaia::ecs::detail::QueryImpl::each_direct_inter ( QueryInfo queryInfo,
Constraints  constraints,
void *  pFunc,
const TypedQueryExecState &  state,
void(*)(QueryImpl &, Iter &, void *, const TypedQueryExecState &)  runDirectChunk,
bool  needsInheritedArgIds,
void(*)(World &, Entity, const Entity *, void *)  invokeInherited 
)

Runs an erased typed callback over entities selected by a direct sparse or target-term seed.

Parameters
queryInfoPrepared query cache and term metadata.
constraintsConstraints applied while selecting direct entities and constructing iterator views.
pFuncOpaque storage for the typed callback object.
statePrepared typed-argument bindings and write metadata.
runDirectChunkExecutes pFunc for a prepared direct chunk or entity iterator.
needsInheritedArgIdsWhether inherited arguments require per-entity id resolution.
invokeInheritedExecutes pFunc with inherited argument ids resolved for one entity.
Note
Writable execution snapshots seed entities before invoking callbacks so structural changes cannot invalidate traversal.

◆ each_entity_enabled()

void gaia::ecs::detail::QueryImpl::each_entity_enabled ( void *  pCtx,
void(*)(void *, Entity func 
)
inline

Iterates matching enabled entities through a non-template erased callback.

Parameters
pCtxUser callback context.
funcCallback invoked for each matching entity.

◆ each_iter()

template<typename Func >
void gaia::ecs::detail::QueryImpl::each_iter ( Iter it,
Func  func 
)

Runs a typed callback against an already prepared iterator. This is used by higher-level adapters that normalize execution to Iter& first and then materialize typed arguments on top of the iterator.

Template Parameters
FuncCallback type.
Parameters
itIterator positioned on the current chunk range.
funcCallback to invoke.

◆ each_runtime_erased() [1/2]

void gaia::ecs::detail::QueryImpl::each_runtime_erased ( QueryExecType  execType,
void *  pFunc,
void(*)(void *, Iter &)  invoke,
Constraints  constraints 
)
inline

Runs a type-erased public iterator callback through generic query execution.

Parameters
execTypeQuery execution mode requested by the public API.
pFuncPointer to the stored callback object.
invokeType-erased callback invoker.
constraintsEntity-row subset exposed to the callback.

◆ each_runtime_erased() [2/2]

void gaia::ecs::detail::QueryImpl::each_runtime_erased ( QueryInfo queryInfo,
const QueryPlan plan,
QueryExecType  execType,
void *  pFunc,
void(*)(void *, Iter &)  invoke,
Constraints  constraints 
)
inline

Runs a type-erased public iterator callback using an already prepared query cache and plan.

Parameters
queryInfoPrepared query cache and execution metadata.
planPrepared query execution metadata.
execTypeQuery execution mode requested by the public API.
pFuncPointer to the stored callback object.
invokeType-erased callback invoker.
constraintsEntity-row subset exposed to the callback.

◆ each_runtime_inter()

template<QueryExecType ExecType, typename Func >
void gaia::ecs::detail::QueryImpl::each_runtime_inter ( Func  func,
Constraints  constraints = Constraints::EnabledOnly 
)
inline

Runs a public iterator callback through the fastest supported runtime path.

Template Parameters
ExecTypeQuery execution mode requested by the public API.
FuncPublic iterator callback type.
Parameters
funcCallback invoked for each iterator step.
constraintsEntity-row subset exposed to the callback.

◆ each_walk() [1/2]

template<typename Func , std::enable_if_t< detail::is_query_walk_core_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each_walk ( Func  func,
Entity  relation,
TravOrder  order = TravOrder::Down,
Constraints  constraints = Constraints::EnabledOnly 
)
inline

Iterates entities matching the query in a requested relation traversal order. For relation R this treats Pair(R, X) on entity E as "E points at X". Traversal changes only visit order. Nodes with the same parent are ordered by entity id.

Template Parameters
FuncCallback type. May accept Iter& or an entity value.
Parameters
funcCallable invoked for each ordered entity.
relationRelation used to order matched entities.
orderTraversal order to apply.
constraintsQueryImpl constraints
See also
ordered_entities_walk(QueryInfo&, Entity, TravOrder, Constraints)

◆ each_walk() [2/2]

template<typename Func , std::enable_if_t<!detail::is_query_walk_core_callback_v< Func >, int > = 0>
void gaia::ecs::detail::QueryImpl::each_walk ( Func  func,
Entity  relation,
TravOrder  order = TravOrder::Down,
Constraints  constraints = Constraints::EnabledOnly 
)

Iterates matching entities in relation order with a typed component callback.

Template Parameters
FuncTyped callback whose arguments identify the requested query components.
Parameters
funcCallable invoked for each ordered matching entity.
relationRelation used to order matched entities.
orderTraversal order to apply.
constraintsEntity-row subset exposed to the callback.

◆ empty()

bool gaia::ecs::detail::QueryImpl::empty ( Constraints  constraints = Constraints::EnabledOnly)
inline

Returns true or false depending on whether there are any entities matching the query.

Warning
Only use if you only care if there are any entities matching the query. The result is not cached and repeated calls to the function might be slow. If you already called arr(), checking if it is empty is preferred. Use empty() instead of calling count()==0.
Note
For changed() queries this is a non-consuming probe. It does not advance the query's changed-reporting state. Iteration APIs such as each()/arr() do consume it.
Returns
True if there are any entities matching the query. False otherwise.
Parameters
constraintsEntity-row subset included in the probe.

◆ exec_payload_kind()

static GAIA_NODISCARD ExecPayloadKind gaia::ecs::detail::QueryImpl::exec_payload_kind ( const QueryInfo queryInfo,
Constraints  constraints 
)
inlinestatic

Classifies the generic batch payload needed for a matched query under row constraints.

Parameters
queryInfoPrepared query cache and execution metadata.
constraintsEntity-row subset exposed to the callback.
Returns
Payload layout required by generic chunk-batch runners.

◆ fetch()

QueryInfo & gaia::ecs::detail::QueryImpl::fetch ( )
inline

Fetches the QueryInfo object. Creates or refreshes the backing QueryInfo if needed.

Returns
QueryInfo object.

◆ gen()

GAIA_NODISCARD uint32_t gaia::ecs::detail::QueryImpl::gen ( ) const
inline

Returns the cache handle generation of this query.

Returns
Query generation, or QueryIdBad for uncached queries.

◆ group_by() [1/3]

QueryImpl & gaia::ecs::detail::QueryImpl::group_by ( Entity  entity,
TGroupByFunc  func = group_by_func_default 
)
inline

Organizes matching archetypes into groups according to the grouping function and entity. Does not order iteration by group id. Use group_id(...) to filter one group. Use depth_order(...) or sort_by(...) when iteration order matters.

Parameters
entityThe entity to group by.
funcThe function to use for grouping. Returns a GroupId to group the entities by.
Returns
Reference to this query builder.

◆ group_by() [2/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::group_by ( TGroupByFunc  func = group_by_func_default)

Organizes matching archetypes into groups according to the grouping function. Does not order iteration by group id. Use group_id(...) to filter one group. Use depth_order(...) or sort_by(...) when iteration order matters.

Template Parameters
TComponent to group by. It is registered if it hasn't been registered yet.
Parameters
funcThe function to use for grouping. Returns a GroupId to group the entities by.
Returns
Reference to this query builder.

◆ group_by() [3/3]

template<typename Rel , typename Tgt >
QueryImpl & gaia::ecs::detail::QueryImpl::group_by ( TGroupByFunc  func = group_by_func_default)

Organizes matching archetypes into groups according to the grouping function. Does not order iteration by group id. Use group_id(...) to filter one group. Use depth_order(...) or sort_by(...) when iteration order matters.

Template Parameters
RelThe relation to group by. It is registered if it hasn't been registered yet.
TgtThe target to group by. It is registered if it hasn't been registered yet.
Parameters
funcThe function to use for grouping. Returns a GroupId to group the entities by.
Returns
Reference to this query builder.

◆ group_dep() [1/2]

template<typename Rel >
QueryImpl & gaia::ecs::detail::QueryImpl::group_dep ( )

Declares an explicit relation dependency for grouped cache invalidation. Useful for custom group_by callbacks that depend on hierarchy or relation topology.

Template Parameters
RelRelation the group depends on.
Returns
Self reference.

◆ group_dep() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::group_dep ( Entity  relation)
inline

Declares an explicit relation dependency for grouped cache invalidation. Useful for custom group_by callbacks that depend on hierarchy or relation topology.

Parameters
relationRelation the group depends on.
Returns
Self reference.

◆ group_id() [1/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::group_id ( )

Selects the group to iterate over.

Template Parameters
TComponent to treat as a group to iterate over. It is registered if it hasn't been registered yet.
Returns
Self reference.

◆ group_id() [2/3]

QueryImpl & gaia::ecs::detail::QueryImpl::group_id ( Entity  entity)
inline

Selects the group to iterate over.

Parameters
entityThe entity to treat as a group to iterate over.
Returns
Self reference.

◆ group_id() [3/3]

QueryImpl & gaia::ecs::detail::QueryImpl::group_id ( GroupId  groupId)
inline

Selects the group to iterate over.

Parameters
groupIdThe group to iterate over.
Returns
Self reference.

◆ groups()

template<typename Container >
void gaia::ecs::detail::QueryImpl::groups ( Container &  out,
bool  sortGroups 
)
inline

Collects active non-zero group ids for a grouped query. The ids can be fed back to group_id(...) to process each group without knowing group ids ahead of time.

Template Parameters
ContainerContainer with GroupId elements.
Parameters
outOutput array overwritten with unique group ids.
sortGroupsTrue to sort grouped cache ranges by group id before collecting ids.

◆ has_depth_order_hierarchy_enabled_barrier()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::has_depth_order_hierarchy_enabled_barrier ( const QueryInfo queryInfo)
inlinestatic

Checks whether depth-order grouping can prune disabled hierarchy subtrees.

Parameters
queryInfoPrepared query cache and execution metadata.
Returns
True when the query groups by depth order on a relation whose hierarchy can prune disabled subtrees.

◆ id()

GAIA_NODISCARD QueryId gaia::ecs::detail::QueryImpl::id ( ) const
inline

Returns the cache handle id of this query.

Returns
Query id, or QueryIdBad for uncached queries.

◆ in()

QueryImpl & gaia::ecs::detail::QueryImpl::in ( Entity  entity,
QueryTermOptions  options = QueryTermOptions{} 
)
inline

Adds an inherited in(entity) requirement.

Parameters
entityTarget entity matched through inherited Is traversal.
optionsTerm options.
Returns
Self reference.

◆ invoke_runtime_iter()

template<typename Func , typename TIter >
static void gaia::ecs::detail::QueryImpl::invoke_runtime_iter ( void *  pFunc,
TIter &  it 
)
inlinestatic

Invokes a type-erased public iterator callback.

Template Parameters
FuncStored callback type.
TIterIterator type passed to the callback.
Parameters
pFuncPointer to the stored callback object.
itIterator passed to the callback.

◆ is()

QueryImpl & gaia::ecs::detail::QueryImpl::is ( Entity  entity,
const QueryTermOptions options = QueryTermOptions{} 
)
inline

Adds a semantic Is(entity) requirement.

Parameters
entityTarget entity matched through the Is relation.
optionsTerm options.
Returns
Self reference.

◆ is_cached()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::is_cached ( ) const
inline

Returns whether the query is stored in the query cache.

Returns
True if the query is stored in the query cache. False otherwise.

◆ is_non_fragmenting_direct_term()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::is_non_fragmenting_direct_term ( const World world,
const QueryTerm term 
)
inlinestatic

Returns whether a direct term is backed by non-fragmenting storage and must be evaluated per entity.

Parameters
worldWorld
termQuery term
Returns
True if the term is backed by non-fragmenting storage. False otherwise.

◆ iter_mode_constraints()

template<typename TMode >
static GAIA_NODISCARD constexpr Constraints gaia::ecs::detail::QueryImpl::iter_mode_constraints ( )
inlinestaticconstexpr

Maps an iteration-mode tag to the runtime row constraints used by iterators.

Template Parameters
TModeOne of the IterMode* tag types.
Returns
Entity-row constraints represented by the tag.

◆ job()

template<typename Func >
GAIA_NODISCARD SchedJob gaia::ecs::detail::QueryImpl::job ( Func  func,
QueryExecType  execType 
)
inline

Adds a query execution job without submitting it.

The returned SchedJob is backed by the world's ECS scheduler descriptor rather than a gaia::mt::JobHandle, so external schedulers can provide their own token, submission, dependency, wait, and cleanup behavior. The job owns only the callback copy and scheduler token. The query and world must outlive the job.

Template Parameters
FuncQuery callback type accepted by each().
Parameters
funcCallback invoked when the added job runs.
execTypeQuery execution mode used inside the job.
Returns
Move-only scheduler job wrapper for the added query execution.
Warning
Structural mutations that invalidate this query while the job is pending are not safe.
See also
SchedJob
each(Func, QueryExecType)

◆ kind() [1/2]

GAIA_NODISCARD QueryCacheKind gaia::ecs::detail::QueryImpl::kind ( ) const
inline

Returns the currently requested cache kind.

Returns
Cache-kind restriction used by this query.

◆ kind() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::kind ( QueryCacheKind  cacheKind)
inline

Sets the hard cache-kind requirement for the query.

Parameters
cacheKindRequested cache-kind restriction.
Returns
Self reference.

◆ kind_error()

GAIA_NODISCARD QueryKindRes gaia::ecs::detail::QueryImpl::kind_error ( )
inline

Returns the validation result for the current query shape and requested kind.

Returns
Validation result for the query's kind requirement.

◆ kind_error_str()

GAIA_NODISCARD const char * gaia::ecs::detail::QueryImpl::kind_error_str ( )
inline

Returns a human-readable description of the current kind validation result.

Returns
Validation message for the current kind requirement.

◆ main_thread()

QueryImpl & gaia::ecs::detail::QueryImpl::main_thread ( bool  required = true)
inline

Marks whether this query must run on the main thread/serial path.

Use this for callbacks with side effects that are not captured by component read/write declarations, such as external APIs that are main-thread-only. This flag is scheduling metadata only and does not affect query matching, hashing, shared-cache identity, or cache invalidation.

Parameters
requiredTrue when the query requires the main thread/serial path.
Returns
Self reference.

◆ main_thread_required()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::main_thread_required ( ) const
inline

Returns whether this query must run on the main thread/serial path.

Returns
True when main_thread(true) was set.

◆ match_all()

void gaia::ecs::detail::QueryImpl::match_all ( QueryInfo queryInfo)
inline

Matches the query against all relevant archetypes.

Parameters
queryInfoQuery info

◆ match_filters() [1/2]

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::match_filters ( const Chunk chunk,
const QueryInfo queryInfo,
uint32_t  changedWorldVersion 
)
inlinestatic

Returns whether a chunk passes the query's changed filters.

Parameters
chunkChunk being evaluated.
queryInfoQuery metadata containing changed-filter terms.
changedWorldVersionWorld version captured by the previous query pass.
Returns
True when a tracked component or the chunk's entity order changed since the supplied version.

◆ match_filters() [2/2]

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::match_filters ( const Chunk chunk,
const QueryInfo queryInfo,
uint32_t  changedWorldVersion,
std::span< const uint8_t >  compIndices 
)
inlinestatic

Returns whether a chunk passes the query's changed filters.

Parameters
chunkChunk being evaluated.
queryInfoQuery metadata containing changed-filter terms.
changedWorldVersionWorld version captured by the previous query pass.
compIndicesPer-archetype mapping from query term index to chunk component column.
Returns
True when a tracked component or the chunk's entity order changed since the supplied version.

◆ match_one()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::match_one ( QueryInfo queryInfo,
const Archetype archetype,
EntitySpan  targetEntities 
)
inline

Matches the query against a single archetype.

Parameters
queryInfoQuery info
archetypeArchetype
targetEntitiesOptional target-entity filter
Returns
True if the archetype matches. False otherwise.

◆ match_prefab()

QueryImpl & gaia::ecs::detail::QueryImpl::match_prefab ( )
inline

Makes the query include prefab entities in matches.

Returns
Self reference.

◆ matches_any()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::matches_any ( QueryInfo queryInfo,
const Archetype archetype,
EntitySpan  targetEntities 
)
inline

Returns whether any supplied target entity matches the query on archetype.

Parameters
queryInfoQuery info
archetypeArchetype
targetEntitiesCandidate target entities
Returns
True if any target entity matches. False otherwise.

◆ needs_depth_order_hierarchy_barrier_cache()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::needs_depth_order_hierarchy_barrier_cache ( const QueryInfo queryInfo,
Constraints  constraints 
)
inlinestatic

Checks whether the current row constraints require the depth-order hierarchy barrier cache.

Parameters
queryInfoPrepared query cache and execution metadata.
constraintsEntity-row subset exposed to the callback.
Returns
True when enabled/disabled row iteration needs cached barrier results.

◆ no() [1/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::no ( )

Adds an excluded typed term.

Template Parameters
TComponent or pair type.
Returns
Self reference.

◆ no() [2/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::no ( const QueryTermOptions options)

Adds an excluded typed term.

Template Parameters
TComponent or pair type.
Parameters
optionsTerm options.
Returns
Self reference.

◆ no() [3/3]

QueryImpl & gaia::ecs::detail::QueryImpl::no ( Entity  entity,
const QueryTermOptions options = QueryTermOptions{} 
)
inline

Adds an excluded entity or pair term.

Parameters
entityEntity or pair id that must not match.
optionsTerm options.
Returns
Self reference.

◆ or_() [1/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::or_ ( )

Adds an OR typed term.

Template Parameters
TComponent or pair type.
Returns
Self reference.

◆ or_() [2/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::or_ ( const QueryTermOptions options)

Adds an OR typed term.

Template Parameters
TComponent or pair type.
Parameters
optionsTerm options.
Returns
Self reference.

◆ or_() [3/3]

QueryImpl & gaia::ecs::detail::QueryImpl::or_ ( Entity  entity,
const QueryTermOptions options = QueryTermOptions{} 
)
inline

OR terms (at least one has to match). A single OR term is canonicalized to ALL during query normalization.

Parameters
entityEntity or pair id.
optionsTerm options.
Returns
Self reference.

◆ order_by() [1/2]

GAIA_NODISCARD OrderByTravView gaia::ecs::detail::QueryImpl::order_by ( Entity  relation,
TravOrder  order 
)
inline

Iterates matching entities in an explicit relation traversal order.

Pair(relation, X) on entity E means E points at X. Down visits X before E. Up visits E before X. Reverse variants produce the exact reverse of their base order. Siblings are tie-broken by entity id, so the order is deterministic. The traversal changes only visit order. It does not change which entities match the query. This path resolves order per entity and works for fragmenting relations such as ChildOf and non-fragmenting relations such as Parent. It may be slower than normal chunk iteration.

Parameters
relationRelation used to order the matched entities.
orderTraversal order to apply.
Returns
Lightweight view exposing each(...).
See also
depth_order(Entity)
group_by(Entity, TGroupByFunc)
sort_by(Entity, TSortByFunc)

◆ order_by() [2/2]

template<typename Rel >
GAIA_NODISCARD OrderByTravView gaia::ecs::detail::QueryImpl::order_by ( TravOrder  order)

Iterates matching entities in an explicit typed relation traversal order.

Template Parameters
RelRelation type. It is registered if it hasn't been registered yet.
Parameters
orderTraversal order to apply.
Returns
Lightweight view exposing each(...).
See also
order_by(Entity, TravOrder)

◆ ordered_entities_walk()

GAIA_NODISCARD std::span< const Entity > gaia::ecs::detail::QueryImpl::ordered_entities_walk ( QueryInfo queryInfo,
Entity  relation,
TravOrder  order,
Constraints  constraints = Constraints::EnabledOnly 
)
inline

Builds and caches relation traversal order for the current query result.

Parameters
queryInfoQuery info
relationDependency relation used for traversal.
orderTraversal order to apply.
constraintsMatch constraints applied before ordering.
Returns
Ordered view of matched entities.

◆ prepare_query_plan()

GAIA_NODISCARD QueryPlan gaia::ecs::detail::QueryImpl::prepare_query_plan ( const QueryInfo queryInfo,
Constraints  constraints 
) const
inline

Selects the prepared execution plan for public iterator callbacks.

Parameters
queryInfoPrepared query cache and execution metadata.
constraintsEntity-row subset exposed to the callback.
Returns
Query execution plan shared by typed and public iterator adapters.

◆ reads() [1/2]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::reads ( )
inline

Declares an additional component or pair type read by this query callback.

Template Parameters
TComponent, entity type, or pair type to mark as read.
Returns
Self reference.
See also
reads(Entity)

◆ reads() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::reads ( Entity  entity)
inline

Declares an additional id read by this query callback.

Use this for data accessed inside the query kernel but not present as a positive query term. The declaration is scheduling metadata only. It does not change query matching or cache identity.

Parameters
entityComponent/entity id read by user code.
Returns
Self reference.
See also
writes(Entity)

◆ run_query_arch_func()

template<typename Func >
static void gaia::ecs::detail::QueryImpl::run_query_arch_func ( World pWorld,
Func  func,
ChunkBatch &  batch,
Constraints  constraints 
)
inlinestatic

Executes an archetype-level iterator callback for one prepared chunk batch. The iterator is initialized with archetype metadata but no chunk rows.

Template Parameters
FuncCallback type invocable with Iter&.
Parameters
pWorldWorld owning the archetype batch.
funcCallback invoked for the initialized iterator.
batchPrepared batch carrying the archetype and inherited metadata.
constraintsEntity-row constraints associated with this execution.
See also
each_arch(Func, Constraints)

◆ run_query_func() [1/2]

template<typename Func , typename TMode >
static void gaia::ecs::detail::QueryImpl::run_query_func ( World pWorld,
Func  func,
ChunkBatch &  batch 
)
inlinestatic

Executes an iterator callback for one prepared chunk batch.

Template Parameters
FuncCallback type invocable with Iter&.
TModeIteration-mode tag controlling enabled/disabled row constraints.
Parameters
pWorldWorld owning the chunk batch.
funcCallback invoked for the initialized iterator.
batchPrepared chunk batch to expose through the iterator.
See also
run_query_func(World*, Func, std::span<ChunkBatch>)

◆ run_query_func() [2/2]

template<typename Func , typename TMode >
static void gaia::ecs::detail::QueryImpl::run_query_func ( World pWorld,
Func  func,
std::span< ChunkBatch >  batches 
)
inlinestatic

Executes an iterator callback over a contiguous list of prepared chunk batches.

Template Parameters
FuncCallback type invocable with Iter&.
TModeIteration-mode tag controlling enabled/disabled row constraints.
Parameters
pWorldWorld owning the chunk batches.
funcCallback invoked once per initialized chunk iterator.
batchesPrepared chunk batches to iterate.
See also
run_query_func(World*, Func, ChunkBatch&)

◆ run_query_on_chunks_runtime_direct_plain_impl()

template<bool HasFilters, bool HasGroups, typename Func >
void gaia::ecs::detail::QueryImpl::run_query_on_chunks_runtime_direct_plain_impl ( QueryInfo queryInfo,
const QueryPlan plan,
Constraints  constraints,
Func &  func 
)
inline

Runs a public Iter callback over cached chunks without creating chunk batches.

Template Parameters
HasFiltersWhen true, chunks must pass changed-filter checks before callback invocation.
HasGroupsWhen true, the prepared cache range carries per-archetype group ids.
FuncPublic iterator callback type.
Parameters
queryInfoPrepared query cache and execution metadata.
planPrepared query execution metadata.
constraintsEntity-row subset exposed to the callback.
funcCallback invoked once for each matching chunk.

Direct dense plans already encode expensive process gates. When no cached archetype can require prefab filtering and no depth-order barrier cache can prune, only deletion state remains dynamic.

◆ scope() [1/2]

GAIA_NODISCARD QueryCacheScope gaia::ecs::detail::QueryImpl::scope ( ) const
inline

Returns the currently requested cache scope.

Returns
Cache scope used by this query.

◆ scope() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::scope ( QueryCacheScope  cacheScope)
inline

Sets the cache scope used by cached queries.

Parameters
cacheScopeWhether cache-backed state stays local or can be shared across identical query shapes.
Returns
Self reference.

◆ set_var() [1/3]

QueryImpl & gaia::ecs::detail::QueryImpl::set_var ( const char *  name,
Entity  value 
)
inline

Binds a named query variable to a concrete entity value.

Parameters
nameNull-terminated variable name previously assigned by var_name(...).
valueEntity value to bind.
Returns
Self reference.

◆ set_var() [2/3]

QueryImpl & gaia::ecs::detail::QueryImpl::set_var ( Entity  varEntity,
Entity  value 
)
inline

Binds a query variable (Var0..Var7) to a concrete entity value. Bound values are applied at runtime before query evaluation.

Parameters
varEntityQuery variable entity (Var0..Var7)
valueEntity value to bind
Returns
Self reference.

◆ set_var() [3/3]

QueryImpl & gaia::ecs::detail::QueryImpl::set_var ( util::str_view  name,
Entity  value 
)
inline

Binds a named query variable to a concrete entity value.

Parameters
nameVariable name previously assigned by var_name(...)
valueEntity value to bind
Returns
Self reference.

◆ sort_by() [1/3]

QueryImpl & gaia::ecs::detail::QueryImpl::sort_by ( Entity  entity,
TSortByFunc  func 
)
inline

Sorts the query by the specified entity and function.

Parameters
entityThe entity to sort by. Use ecs::EntityBad to sort by chunk entities, or anything else to sort by components.
funcThe function to use for sorting. Return -1 to put the first entity before the second, 0 to keep the order, and 1 to put the first entity after the second.
Returns
Self reference.

◆ sort_by() [2/3]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::sort_by ( TSortByFunc  func)

Sorts the query by the specified component and function.

Template Parameters
TThe component to sort by. It is registered if it hasn't been registered yet.
Parameters
funcThe function to use for sorting. Return -1 to put the first entity before the second, 0 to keep the order, and 1 to put the first entity after the second.
Returns
Self reference.

◆ sort_by() [3/3]

template<typename Rel , typename Tgt >
QueryImpl & gaia::ecs::detail::QueryImpl::sort_by ( TSortByFunc  func)

Sorts the query by the specified pair and function.

Template Parameters
RelThe relation to sort by. It is registered if it hasn't been registered yet.
TgtThe target to sort by. It is registered if it hasn't been registered yet.
Parameters
funcThe function to use for sorting. Return -1 to put the first entity before the second, 0 to keep the order, and 1 to put the first entity after the second.
Returns
Self reference.

◆ survives_cascade_hierarchy_enabled_barrier()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::survives_cascade_hierarchy_enabled_barrier ( const QueryInfo queryInfo,
const Archetype archetype 
)
inlinestatic

Fast enabled-subtree gate for cached depth_order(...) queries over fragmenting hierarchy relations. ChildOf is the native built-in example, but the rule is semantic: the relation must support depth_order(...) and also form a fragmenting hierarchy chain. For such relations, all rows in the archetype share the same direct parent target. That lets us prune the entire archetype when its parent chain crosses a disabled entity. Non-fragmenting hierarchy relations such as Parent cannot use this archetype-level check and must stay on the per-entity traversal path instead.

Parameters
queryInfoPrepared query cache and execution metadata.
archetypeMatched archetype to test.
Returns
True when the archetype can be processed under the enabled hierarchy barrier.

◆ uses_in_is_matching()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::uses_in_is_matching ( const QueryTerm term)
inlinestatic

Returns whether a term uses strict semantic Is matching that excludes the base entity itself.

Parameters
termQuery term
Returns
True if strict semantic Is matching is used. False otherwise.

◆ uses_inherited_id_matching()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::uses_inherited_id_matching ( const World world,
const QueryTerm term 
)
inlinestatic

Returns whether a term uses semantic inherited-id matching rather than direct storage matching.

Parameters
worldWorld
termQuery term
Returns
True if inherited-id matching is used. False otherwise.

◆ uses_non_direct_is_matching()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::uses_non_direct_is_matching ( const QueryTerm term)
inlinestatic

Returns whether a term uses any semantic Is matching rather than direct storage matching.

Parameters
termQuery term
Returns
True if any semantic Is matching is used. False otherwise.

◆ uses_potential_inherited_id_matching()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::uses_potential_inherited_id_matching ( const QueryTerm term)
inlinestatic

Returns whether a term could use inherited-id matching based on query shape alone. This intentionally ignores mutable world metadata such as current OnInstantiate policy.

Parameters
termQuery term
Returns
True if the term shape can resolve through inherited-id matching.

◆ uses_semantic_is_matching()

static GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::uses_semantic_is_matching ( const QueryTerm term)
inlinestatic

Returns whether a term uses semantic Is matching rather than direct storage matching.

Parameters
termQuery term
Returns
True if semantic Is matching is used. False otherwise.

◆ valid()

GAIA_NODISCARD bool gaia::ecs::detail::QueryImpl::valid ( )
inline

Returns whether the current query shape satisfies the requested kind.

Returns
True when the current kind requirement is satisfied.

◆ var_name() [1/2]

QueryImpl & gaia::ecs::detail::QueryImpl::var_name ( Entity  varEntity,
const char *  name 
)
inline

Assigns a human-readable name to a query variable entity (Var0..Var7).

Parameters
varEntityQuery variable entity (Var0..Var7).
nameNull-terminated variable name without the $ prefix.
Returns
Self reference.

◆ var_name() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::var_name ( Entity  varEntity,
util::str_view  name 
)
inline

Assigns a human-readable name to a query variable entity (Var0..Var7). The name can be used later by set_var(name, value).

Parameters
varEntityQuery variable entity (Var0..Var7)
nameVariable name (without '$')
Returns
Self reference.
Note
Empty names and reserved name "this" are rejected.

◆ writes() [1/2]

template<typename T >
QueryImpl & gaia::ecs::detail::QueryImpl::writes ( )
inline

Declares an additional component or pair type written by this query callback.

Template Parameters
TComponent, entity type, or pair type to mark as written.
Returns
Self reference.
See also
writes(Entity)

◆ writes() [2/2]

QueryImpl & gaia::ecs::detail::QueryImpl::writes ( Entity  entity)
inline

Declares an additional id written by this query callback.

A write conflicts with any read or write of the same id when comparing two queries with conflicts_with(). The declaration is scheduling metadata only. It does not change query matching or cache identity.

Parameters
entityComponent/entity id written by user code.
Returns
Self reference.
See also
reads(Entity)

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