2#include "gaia/config/config.h"
6#include "gaia/cnt/darray.h"
7#include "gaia/cnt/map.h"
8#include "gaia/cnt/sarray.h"
9#include "gaia/cnt/sarray_ext.h"
10#include "gaia/core/bit_utils.h"
11#include "gaia/core/hashing_policy.h"
12#include "gaia/core/span.h"
13#include "gaia/core/utility.h"
14#include "gaia/ecs/api.h"
15#include "gaia/ecs/component.h"
16#include "gaia/ecs/id.h"
17#include "gaia/ecs/query_fwd.h"
18#include "gaia/ecs/query_mask.h"
25 using InheritedTermDataView = std::span<const void* const>;
26 GAIA_NODISCARD uint32_t world_rel_version(
const World& world, Entity relation);
27 GAIA_NODISCARD
bool world_has_entity_term(
const World& world, Entity entity, Entity term);
28 GAIA_NODISCARD
bool world_has_entity_term_in(
const World& world, Entity entity, Entity term);
29 GAIA_NODISCARD
bool world_has_entity_term_direct(
const World& world, Entity entity, Entity term);
30 GAIA_NODISCARD
bool world_term_uses_inherit_policy(
const World& world, Entity term);
31 GAIA_NODISCARD
bool world_relation_uses_non_fragmenting_storage(
const World& world, Entity relation);
32 GAIA_NODISCARD
bool world_component_uses_sparse_storage(
const World& world, Entity component);
33 GAIA_NODISCARD
bool world_component_is_non_fragmenting(
const World& world, Entity component);
34 GAIA_NODISCARD uint32_t world_count_direct_term_entities(
const World& world, Entity term);
35 GAIA_NODISCARD uint32_t world_count_in_term_entities(
const World& world, Entity term);
36 GAIA_NODISCARD uint32_t world_count_direct_term_entities_direct(
const World& world, Entity term);
37 void world_collect_direct_term_entities(
const World& world, Entity term, cnt::darray<Entity>& out);
38 void world_collect_in_term_entities(
const World& world, Entity term, cnt::darray<Entity>& out);
39 void world_collect_direct_term_entities_direct(
const World& world, Entity term, cnt::darray<Entity>& out);
41 world_for_each_direct_term_entity(
const World& world, Entity term,
void* ctx,
bool (*func)(
void*, Entity));
43 world_for_each_in_term_entity(
const World& world, Entity term,
void* ctx,
bool (*func)(
void*, Entity));
45 world_for_each_direct_term_entity_direct(
const World& world, Entity term,
void* ctx,
bool (*func)(
void*, Entity));
46 GAIA_NODISCARD
bool world_entity_enabled(
const World& world, Entity entity);
47 GAIA_NODISCARD
bool world_entity_prefab(
const World& world, Entity entity);
48 GAIA_NODISCARD
const Archetype* world_entity_archetype(
const World& world, Entity entity);
49 void world_finish_write(World& world, Entity term, Entity entity);
50 GAIA_NODISCARD uint32_t world_component_index_bucket_size(
const World& world, Entity term);
51 GAIA_NODISCARD uint32_t world_component_index_comp_idx(
const World& world,
const Archetype& archetype, Entity term);
52 GAIA_NODISCARD uint32_t
53 world_component_index_match_count(
const World& world,
const Archetype& archetype, Entity term);
59 GAIA_NODISCARD GroupId group_by_func_depth_order(
const World& world,
const Archetype& archetype, Entity relation);
61 GAIA_NODISCARD
decltype(
auto) world_direct_entity_arg(World& world, Entity entity);
63 GAIA_NODISCARD
decltype(
auto) world_query_entity_arg(World& world, Entity entity);
65 GAIA_NODISCARD Entity world_query_arg_id(World& world);
67 GAIA_NODISCARD
decltype(
auto) world_query_entity_arg_by_id(World& world, Entity entity, Entity
id);
69 GAIA_NODISCARD
decltype(
auto) world_query_entity_arg_by_id_raw(World& world, Entity entity, Entity
id);
71 GAIA_NODISCARD uint32_t world_entity_archetype_version(
const World& world, Entity entity);
74 static constexpr uint32_t MAX_ITEMS_IN_QUERY = 12U;
76 static constexpr uint32_t MAX_TRAV_DEPTH = 128U;
78 GAIA_GCC_WARNING_PUSH()
81 GAIA_GCC_WARNING_DISABLE("-Wshadow")
84 enum class QueryOpKind : uint8_t {
97 enum class QueryAccess : uint8_t {
106 enum class QueryMatchKind : uint8_t {
115 enum class QueryInputFlags : uint8_t {
122 enum class QueryTravKind : uint8_t {
133 GAIA_GCC_WARNING_POP()
139 GAIA_NODISCARD constexpr QueryTravKind operator|(QueryTravKind lhs, QueryTravKind rhs) {
140 return (QueryTravKind)((uint8_t)lhs | (uint8_t)rhs);
147 GAIA_NODISCARD
constexpr bool query_trav_has(QueryTravKind value, QueryTravKind bit) {
148 return (((uint8_t)value) & ((uint8_t)bit)) != 0;
152 using QueryLookupHash = core::direct_hash_key<uint64_t>;
154 using QueryEntityArray = cnt::sarray<Entity, MAX_ITEMS_IN_QUERY>;
156 using QuerySerMap = cnt::map<QueryId, QuerySerBuffer>;
172 static constexpr uint16_t ComponentIndexBad = (uint16_t)-1;
205 void collapse_to_inline_if_needed() {
206 if (m_size != 1 || m_items.
empty())
209 m_inline = m_items[0];
214 ComponentIndexEntryArray() =
default;
215 ComponentIndexEntryArray(ComponentIndexEntryArray&&) noexcept = default;
216 ComponentIndexEntryArray(const ComponentIndexEntryArray&) = default;
217 ComponentIndexEntryArray& operator=(ComponentIndexEntryArray&&) noexcept = default;
218 ComponentIndexEntryArray& operator=(const ComponentIndexEntryArray&) = default;
222 GAIA_NODISCARD
bool empty() const noexcept {
235 return m_size <= 1 ? &m_inline : m_items.
data();
241 return m_size <= 1 ? &m_inline : m_items.
data();
259 return data() + m_size;
265 return data() + m_size;
272 GAIA_ASSERT(idx < m_size);
280 GAIA_ASSERT(idx < m_size);
287 GAIA_ASSERT(m_size > 0);
288 return (*
this)[m_size - 1];
294 GAIA_ASSERT(m_size > 0);
295 return (*
this)[m_size - 1];
320 GAIA_ASSERT(m_size > 0);
328 collapse_to_inline_if_needed();
351 static constexpr QueryId QueryIdBad = (QueryId)-1;
353 static constexpr GroupId GroupIdMax = ((GroupId)-1) - 1;
358 static constexpr uint32_t
IdMask = QueryIdBad;
372 constexpr QueryHandle() noexcept: val((uint64_t)-1) {};
391 GAIA_NODISCARD constexpr
bool operator==(const
QueryHandle& other) const noexcept {
392 return val == other.val;
398 return val != other.val;
403 GAIA_NODISCARD
auto id()
const {
408 GAIA_NODISCARD
auto gen()
const {
419 inline static const QueryHandle QueryHandleBad = QueryHandle();
460 return (
size_t)m_hash.
hash;
467 if GAIA_LIKELY (m_hash != other.m_hash)
470 return m_handle == other.m_handle;
482 inline static const QueryHandleLookupKey QueryHandleBadLookupKey = QueryHandleLookupKey(QueryHandleBad);
490 QueryOpKind
op = QueryOpKind::All;
505 QueryTravKind
travKind = QueryTravKind::Self | QueryTravKind::Up;
525 QueryTravKind
travKind = QueryTravKind::Self | QueryTravKind::Up;
548 travKind = QueryTravKind::Self | QueryTravKind::Up;
578 travKind = QueryTravKind::Self | QueryTravKind::Up;
598 travKind = QueryTravKind::Self | QueryTravKind::Down;
618 travKind = QueryTravKind::Self | QueryTravKind::Down;
642 access = QueryAccess::Read;
649 access = QueryAccess::Write;
700 if (entity == EntityBad || core::has(
reads_view(), entity))
703 GAIA_ASSERT(
readCnt < MAX_ITEMS_IN_QUERY);
704 if (
readCnt < MAX_ITEMS_IN_QUERY)
711 if (entity == EntityBad || core::has(
writes_view(), entity))
714 GAIA_ASSERT(
writeCnt < MAX_ITEMS_IN_QUERY);
724 return QueryAccess::Write;
726 return QueryAccess::Read;
727 return QueryAccess::None;
771 constexpr bool query_term_less_for_lookup(
const QueryTerm& lhs,
const QueryTerm& rhs) {
772 if (lhs.op != rhs.op)
773 return lhs.op < rhs.op;
775 if (lhs.id != rhs.id)
776 return SortComponentCond()(lhs.id, rhs.id);
778 if (lhs.src != rhs.src)
779 return SortComponentCond()(lhs.src, rhs.src);
781 if (lhs.entTrav != rhs.entTrav)
782 return SortComponentCond()(lhs.entTrav, rhs.entTrav);
784 if (lhs.travKind != rhs.travKind)
785 return (uint8_t)lhs.travKind < (uint8_t)rhs.travKind;
787 if (lhs.travDepth != rhs.travDepth)
788 return lhs.travDepth < rhs.travDepth;
790 return (uint8_t)lhs.matchKind < (uint8_t)rhs.matchKind;
795 inline void canonicalize_lookup_terms(std::span<QueryTerm> terms) {
796 const auto idsCnt = (uint32_t)terms.size();
799 uint32_t orIdx = BadIndex;
801 if (terms[i].op != QueryOpKind::Or)
810 terms[orIdx].op = QueryOpKind::All;
813 core::sort(terms.data(), terms.data() + idsCnt, [](
const QueryTerm& left,
const QueryTerm& right) {
814 return query_term_less_for_lookup(left, right);
820 inline void canonicalize_lookup_changed(std::span<Entity> changed) {
821 const auto changedCnt = (uint32_t)changed.size();
823 core::sort(changed.data(), changed.data() + changedCnt, SortComponentCond{});
829 GAIA_NODISCARD
inline bool term_has_variables(
const QueryTerm& term) {
830 if (is_variable(term.src))
834 return is_variable(EntityId(term.id.id())) || is_variable(EntityId(term.id.gen()));
836 return is_variable(EntityId(term.id.id()));
842 GAIA_NODISCARD
inline bool query_term_maps_to_current_archetype(
const QueryTerm& term) {
843 return term.src == EntityBad && term.entTrav == EntityBad && !term_has_variables(term);
850 GAIA_NODISCARD
inline bool query_term_uses_potential_inherited_id_matching(
const QueryTerm& term) {
851 const auto id = term.id;
852 return term.matchKind == QueryMatchKind::Semantic && term.src == EntityBad && term.entTrav == EntityBad &&
853 !term_has_variables(term) && !is_wildcard(
id) && !is_variable((EntityId)
id.
id()) &&
854 (!
id.pair() || !is_variable((EntityId)
id.gen()));
858 using QueryTermArray = cnt::sarray_ext<QueryTerm, MAX_ITEMS_IN_QUERY>;
860 using QueryTermSpan = std::span<QueryTerm>;
862 using QueryRemappingArray = cnt::sarray_ext<uint8_t, MAX_ITEMS_IN_QUERY>;
875 return query_buffer(*world,
serId);
880 query_buffer_reset(*world,
serId);
889 ComponentCache*
cc{};
1066 return (
flags & dependency) != 0;
1072 if (relation == EntityBad || core::has(
relations_view(), relation))
1182 GAIA_NODISCARD std::span<const Entity>
ids_view()
const {
1255 const bool hasBuiltInGroupDep =
groupBy != EntityBad && (
groupByFunc == group_by_func_default ||
1257 if (hasBuiltInGroupDep)
1284 if (hasSources && hasTraversal && !hasVariables)
1287 const uint8_t depCnt = (uint8_t)hasVariables + (uint8_t)hasSources + (uint8_t)hasRelations;
1356 GAIA_FOR((uint32_t)left.size()) {
1357 if (left[i] != right[i])
1365 GAIA_FOR((uint32_t)left.size()) {
1366 if (left[i] != right[i])
1374 GAIA_FOR((uint32_t)left.size()) {
1375 if (left[i] != right[i])
1516 static_assert(MAX_ITEMS_IN_QUERY < 16);
1522 cc = &comp_cache_mut(*pWorld);
1552 uint32_t as_mask_0 = 0;
1553 uint32_t as_mask_1 = 0;
1554 bool isComplex =
false;
1555 bool hasSourceTerms =
false;
1556 bool hasVariableTerms =
false;
1557 bool hasPrefabTerms =
false;
1558 bool hasCreateSelector =
false;
1559 bool canDirectCreateArchetypeMatch =
true;
1560 bool hasEntityFilterTerms =
false;
1561 bool canDirectTargetEval =
true;
1562 bool hasOnlyDirectOrTerms =
true;
1563 bool hasOrTerms =
false;
1564 bool hasDirectTargetEvalPositiveTerms =
false;
1565 const QueryTerm* pSingleDirectTargetAllTerm =
nullptr;
1566 bool singleDirectTargetEvalPossible =
true;
1570 uint32_t idsNoSrcCnt = 0;
1571 uint8_t createSelectorAllCnt = 0;
1572 uint8_t createSelectorOrCnt = 0;
1582 const auto cnt = (uint32_t)terms.size();
1584 const auto& term = terms[i];
1585 const auto id = term.id;
1586 hasPrefabTerms |=
id == Prefab;
1587 const bool isDirectIsTerm = term.src == EntityBad && term.entTrav == EntityBad &&
1588 !term_has_variables(term) && term.matchKind != QueryMatchKind::Direct &&
1589 id.pair() &&
id.id() == Is.
id() && !is_wildcard(
id.gen()) &&
1590 !is_variable((EntityId)
id.gen());
1591 const bool isPotentialInheritedTerm = query_term_uses_potential_inherited_id_matching(term);
1592 const bool isInheritedTerm = isPotentialInheritedTerm && world_term_uses_inherit_policy(*
w,
id);
1593 const bool isNonFragmentingTerm =
1594 term.src == EntityBad && term.entTrav == EntityBad && !term_has_variables(term) &&
1595 ((
id.pair() && world_relation_uses_non_fragmenting_storage(*
w, pair_rel(*
w,
id))) ||
1596 (!
id.
pair() && world_component_is_non_fragmenting(*
w,
id)));
1597 hasEntityFilterTerms |= isNonFragmentingTerm || isDirectIsTerm || isInheritedTerm;
1601 const auto& term = terms[i];
1602 const auto id = term.id;
1603 if (term.src != EntityBad || term.entTrav != EntityBad || term_has_variables(term)) {
1604 singleDirectTargetEvalPossible =
false;
1605 canDirectTargetEval =
false;
1606 hasOnlyDirectOrTerms =
false;
1609 case QueryOpKind::All:
1610 hasDirectTargetEvalPositiveTerms =
true;
1611 if (pSingleDirectTargetAllTerm ==
nullptr)
1612 pSingleDirectTargetAllTerm = &term;
1614 singleDirectTargetEvalPossible =
false;
1615 hasOnlyDirectOrTerms =
false;
1617 case QueryOpKind::Or:
1618 hasDirectTargetEvalPositiveTerms =
true;
1621 case QueryOpKind::Not:
1623 case QueryOpKind::Any:
1624 case QueryOpKind::Count:
1625 singleDirectTargetEvalPossible =
false;
1626 canDirectTargetEval =
false;
1627 hasOnlyDirectOrTerms =
false;
1630 const bool isDirectIsTerm = term.
src == EntityBad && term.entTrav == EntityBad &&
1631 !term_has_variables(term) && term.matchKind != QueryMatchKind::Direct &&
1632 id.pair() &&
id.id() == Is.
id() && !is_wildcard(
id.gen()) &&
1633 !is_variable((EntityId)
id.gen());
1634 const bool isPotentialInheritedTerm = query_term_uses_potential_inherited_id_matching(term);
1635 const bool isInheritedTerm = isPotentialInheritedTerm && world_term_uses_inherit_policy(*
w,
id);
1636 const bool isCachedInheritedDataTerm = isInheritedTerm && !world_component_uses_sparse_storage(*
w,
id);
1637 const bool isNonFragmentingTerm =
1638 term.src == EntityBad && term.entTrav == EntityBad && !term_has_variables(term) &&
1639 ((
id.pair() && world_relation_uses_non_fragmenting_storage(*
w, pair_rel(*
w,
id))) ||
1640 (!
id.
pair() && world_component_is_non_fragmenting(*
w,
id)));
1641 canDirectCreateArchetypeMatch &= term.src == EntityBad;
1642 if (
id.
pair() && (is_wildcard(
id.
id()) || is_wildcard(
id.gen())))
1644 const bool hasDynamicRelationUsage =
1645 term.entTrav != EntityBad || term.src != EntityBad || term_has_variables(term);
1646 if (
id.
pair() && hasDynamicRelationUsage && !is_wildcard(
id.
id()) && !is_variable((EntityId)
id.
id()))
1648 if (term.entTrav != EntityBad) {
1652 if (term.src != EntityBad) {
1653 hasSourceTerms =
true;
1656 if (!is_variable(term.src))
1660 if (term_has_variables(term)) {
1661 hasVariableTerms =
true;
1667 if (isPotentialInheritedTerm)
1670 if (isNonFragmentingTerm || isDirectIsTerm || isInheritedTerm) {
1672 if (isCachedInheritedDataTerm)
1674 if (
id.
pair() && !is_wildcard(
id.
id()) && !is_variable((EntityId)
id.
id()))
1679 if (hasEntityFilterTerms && term.op == QueryOpKind::Or) {
1686 if (term.src != EntityBad) {
1691 if (term.op != QueryOpKind::Any)
1692 idsNoSrc[idsNoSrcCnt++] = id;
1694 if (term.op == QueryOpKind::All || term.op == QueryOpKind::Or) {
1695 hasCreateSelector =
true;
1697 if (term.op == QueryOpKind::All)
1698 createSelectorsAll[createSelectorAllCnt++] = id;
1700 createSelectorsOr[createSelectorOrCnt++] = id;
1701 }
else if (term.op == QueryOpKind::Not) {
1704 }
else if (term.op == QueryOpKind::Any) {
1710 const bool allowSemanticIs = !(
1711 term.matchKind == QueryMatchKind::Direct &&
id.pair() &&
id.id() == Is.
id() && !is_wildcard(
id.gen()));
1713 const auto j = (uint32_t)i;
1714 const auto has_as = allowSemanticIs ? (uint32_t)is_base(*
w,
id) : 0U;
1715 as_mask_0 |= (has_as << j);
1717 const bool idIsWildcard = is_wildcard(
id.
id());
1718 const bool isGenWildcard = is_wildcard(
id.gen());
1719 isComplex |= (idIsWildcard || isGenWildcard);
1721 if (!idIsWildcard) {
1722 const auto j = (uint32_t)i;
1723 const auto e = pair_rel(*
w,
id);
1724 const auto has_as = allowSemanticIs ? (uint32_t)is_base(*
w, e) : 0U;
1725 as_mask_0 |= (has_as << j);
1728 if (!isGenWildcard) {
1729 const auto j = (uint32_t)i;
1730 const auto e = pair_tgt(*
w,
id);
1731 const auto has_as = allowSemanticIs ? (uint32_t)is_base(*
w, e) : 0U;
1732 as_mask_1 |= (has_as << j);
1737 if (singleDirectTargetEvalPossible && pSingleDirectTargetAllTerm !=
nullptr) {
1738 const auto& term = *pSingleDirectTargetAllTerm;
1739 const auto id = term.
id;
1740 if (term.matchKind == QueryMatchKind::In &&
id.pair() &&
id.id() == Is.
id() && !is_wildcard(
id.gen()) &&
1741 !is_variable((EntityId)
id.gen())) {
1744 term.matchKind == QueryMatchKind::Semantic &&
id.pair() &&
id.id() == Is.
id() &&
1745 !is_wildcard(
id.gen()) && !is_variable((EntityId)
id.gen())) {
1748 term.matchKind == QueryMatchKind::Semantic && !is_wildcard(
id) && !is_variable((EntityId)
id.
id()) &&
1749 (!
id.pair() || !is_variable((EntityId)
id.gen())) && world_term_uses_inherit_policy(*
w,
id)) {
1765 if (createSelectorAllCnt != 0) {
1766 auto selector_rank = [](
Entity term) {
1769 if (!is_wildcard(term.id()) && !is_wildcard(term.gen()))
1771 if (is_wildcard(term.id()) && is_wildcard(term.gen()))
1780 uint8_t bestIdx = 0;
1781 auto bestBucketSize = world_component_index_bucket_size(*
w, createSelectorsAll[0]);
1782 auto bestRank = selector_rank(createSelectorsAll[0]);
1783 GAIA_FOR2_(1, createSelectorAllCnt, i) {
1784 const auto bucketSize = world_component_index_bucket_size(*
w, createSelectorsAll[i]);
1785 const auto rank = selector_rank(createSelectorsAll[i]);
1786 if (bucketSize < bestBucketSize || (bucketSize == bestBucketSize && rank < bestRank)) {
1787 bestBucketSize = bucketSize;
1789 bestIdx = (uint8_t)i;
1794 GAIA_FOR(createSelectorOrCnt) {
1808 if (hasVariableTerms)
1813 if (hasSourceTerms || hasVariableTerms)
1869 GAIA_NODISCARD
static bool
1872 if (leftCtx.hashLookup != rightCtx.hashLookup)
1875 const auto& left = leftCtx.data;
1876 const auto& right = rightCtx.data;
1877 return left.identity_payload_equal(right);
1885 GAIA_ASSERT(
q.
handle.
id() == QueryIdBad);
1908 return query_term_less_for_lookup(lhs, rhs);
1914 inline void sort(QueryCtx& ctx) {
1915 const uint32_t idsCnt = ctx.data.idsCnt;
1916 const uint32_t changedCnt = ctx.data.changedCnt;
1918 auto& ctxData = ctx.data;
1923 uint32_t orIdx = BadIndex;
1925 if (ctxData.terms[i].op != QueryOpKind::Or)
1934 ctxData.terms[orIdx].op = QueryOpKind::All;
1941 ctxData.terms.data(), ctxData.terms.data() + ctxData.idsCnt, query_sort_cond{},
1942 [&](uint32_t left, uint32_t right) {
1943 core::swap(ctxData.ids[left], ctxData.ids[right]);
1944 core::swap(ctxData.terms[left], ctxData.terms[right]);
1947 core::swap_bits(ctxData.readWriteMask, left, right);
1948 core::swap_bits(ctxData.as_mask_0, left, right);
1949 core::swap_bits(ctxData.as_mask_1, left, right);
1954 while (i < idsCnt && ctxData.terms[i].op == QueryOpKind::All)
1956 ctxData.firstOr = (uint8_t)i;
1957 while (i < idsCnt && ctxData.terms[i].op == QueryOpKind::Or)
1959 ctxData.firstNot = (uint8_t)i;
1960 while (i < idsCnt && ctxData.terms[i].op == QueryOpKind::Not)
1962 ctxData.firstAny = (uint8_t)i;
1964 ctxData.firstOr = ctxData.firstNot = ctxData.firstAny = 0;
1968 if (changedCnt > 1) {
1969 core::sort(ctxData.changed.data(), ctxData.changed.data() + changedCnt, SortComponentCond{});
1972 GAIA_FOR(changedCnt) {
1973 const auto comp = ctxData.changed[i];
1974 uint32_t compIdx = 0;
1975 while (compIdx < idsCnt && ctxData.ids[compIdx] != comp)
1978 GAIA_ASSERT(compIdx < idsCnt);
1979 ctxData.changedFields[i] = compIdx < idsCnt ? (uint8_t)compIdx : (uint8_t)0xFF;
1986 inline void normalize_cache_src_trav(QueryCtx& ctx) {
1987 auto& ctxData = ctx.data;
1988 if (ctxData.cacheSrcTrav == 0)
1991 bool hasTraversedSourceTerm =
false;
1992 for (
const auto& term: ctxData.terms_view()) {
1993 if (term.src == EntityBad || term.entTrav == EntityBad)
1996 hasTraversedSourceTerm =
true;
2000 if (!hasTraversedSourceTerm)
2001 ctxData.cacheSrcTrav = 0;
2006 inline void calc_lookup_hash(QueryCtx& ctx) {
2007 GAIA_ASSERT(ctx.cc !=
nullptr);
2009 GAIA_ASSERT(ctx.hashLookup.hash == 0);
2011 ctx.hashLookup = ctx.data.calc_lookup_hash();
2021 template <u
int32_t MAX_COMPONENTS>
2022 GAIA_NODISCARD
inline uint32_t comp_idx(
const QueryTerm* pTerms, Entity entity, Entity src) {
2025 GAIA_FOR(MAX_COMPONENTS) {
2026 if (pTerms[i].
id == entity && pTerms[i].src == src)
Array with variable size of elements of type.
Definition darray_impl.h:27
void clear() noexcept
Removes all elements.
Definition darray_impl.h:449
GAIA_NODISCARD bool empty() const noexcept
Checks whether the container has no elements.
Definition darray_impl.h:510
void pop_back() noexcept
Removes the last element.
Definition darray_impl.h:342
GAIA_NODISCARD pointer data() noexcept
Returns a pointer to the element storage.
Definition darray_impl.h:193
void push_back(const T &arg)
Appends an element.
Definition darray_impl.h:309
Fixed-shape group of chunks storing entities that share the same component layout....
Definition archetype.h:97
Small reverse-lookup bucket for entity-to-archetype matches. Most buckets contain one archetype,...
Definition query_common.h:193
void push_back(ComponentIndexEntry entry)
Appends a reverse-index record, spilling inline storage when necessary.
Definition query_common.h:300
GAIA_NODISCARD size_type size() const noexcept
Returns the number of reverse-index records.
Definition query_common.h:228
GAIA_NODISCARD ComponentIndexEntry & back() noexcept
Returns the final mutable record.
Definition query_common.h:286
GAIA_NODISCARD bool empty() const noexcept
Checks whether the bucket contains no reverse-index records.
Definition query_common.h:222
GAIA_NODISCARD const ComponentIndexEntry & operator[](size_type idx) const noexcept
Returns a read-only record by index.
Definition query_common.h:279
GAIA_NODISCARD const ComponentIndexEntry * data() const noexcept
Returns read-only contiguous record storage.
Definition query_common.h:240
GAIA_NODISCARD ComponentIndexEntry * end() noexcept
Returns a mutable iterator past the final record.
Definition query_common.h:258
GAIA_NODISCARD ComponentIndexEntry * begin() noexcept
Returns a mutable iterator to the first record.
Definition query_common.h:246
GAIA_NODISCARD ComponentIndexEntry * data() noexcept
Returns mutable contiguous record storage.
Definition query_common.h:234
GAIA_NODISCARD const ComponentIndexEntry * begin() const noexcept
Returns a read-only iterator to the first record.
Definition query_common.h:252
uint32_t size_type
Unsigned element-count and index type.
Definition query_common.h:198
GAIA_NODISCARD const ComponentIndexEntry * end() const noexcept
Returns a read-only iterator past the final record.
Definition query_common.h:264
GAIA_NODISCARD const ComponentIndexEntry & back() const noexcept
Returns the final read-only record.
Definition query_common.h:293
GAIA_NODISCARD ComponentIndexEntry & operator[](size_type idx) noexcept
Returns a mutable record by index.
Definition query_common.h:271
void pop_back()
Removes the final record and restores inline storage when one record remains.
Definition query_common.h:319
Owns entities, components, archetypes, queries, observers, and systems.
Definition world.h:80
Wrapper for two types forming a relationship pair. Depending on what types are used to form a pair it...
Definition id.h:262
Same API as ser_buffer_binary, but backed by fully dynamic storage.
Definition ser_buffer_binary.h:161
uint64_t Type
Underlying hash storage type.
Definition hashing_policy.h:44
T hash
Precomputed hash value.
Definition hashing_policy.h:51
One archetype record stored in the entity-to-archetype reverse index.
Definition query_common.h:175
GAIA_NODISCARD bool matches(const Archetype *pOther) const
Tests whether this record belongs to an archetype.
Definition query_common.h:186
uint16_t matchCount
Number of archetype components contributing this lookup-key match.
Definition query_common.h:181
Archetype * pArchetype
Archetype matched by the indexed entity or pair key.
Definition query_common.h:177
uint16_t compIdx
Component column index in pArchetype, or ComponentIndexBad when no direct column exists.
Definition query_common.h:179
Hashmap lookup structure used for Entity.
Definition id.h:543
Identifier of an entity or component instance in the world. Packs the entity index,...
Definition id.h:296
GAIA_NODISCARD constexpr auto value() const noexcept
Raw identifier value.
Definition id.h:395
GAIA_NODISCARD constexpr auto id() const noexcept
Entity index in the entity array.
Definition id.h:359
Explicit component/entity access declarations used for scheduling decisions.
Definition query_common.h:675
GAIA_NODISCARD QueryAccess access(Entity entity) const
Returns explicitly declared access for an id.
Definition query_common.h:722
uint8_t readCnt
Number of valid entries in reads.
Definition query_common.h:681
GAIA_NODISCARD std::span< const Entity > writes_view() const
Returns the explicitly declared write ids.
Definition query_common.h:693
void add_read(Entity entity)
Declares that an id is read.
Definition query_common.h:699
cnt::sarray< Entity, MAX_ITEMS_IN_QUERY > reads
Component/entity ids read by the callback outside the query terms.
Definition query_common.h:677
GAIA_NODISCARD std::span< const Entity > reads_view() const
Returns the explicitly declared read ids.
Definition query_common.h:687
uint8_t writeCnt
Number of valid entries in writes.
Definition query_common.h:683
cnt::sarray< Entity, MAX_ITEMS_IN_QUERY > writes
Component/entity ids written by the callback outside the query terms.
Definition query_common.h:679
void add_write(Entity entity)
Declares that an id is written.
Definition query_common.h:710
Incremental query-matching cursor for one entity-to-archetype lookup bucket.
Definition query_common.h:159
uint32_t index
Number of bucket records that were already matched at revision.
Definition query_common.h:161
uint32_t revision
Lookup-bucket revision associated with index.
Definition query_common.h:163
Deduplicated entities and flags that can invalidate or update a query cache.
Definition query_common.h:1000
void set_dep_flag(DependencyFlags dependency)
Records a dependency fact.
Definition query_common.h:1058
GAIA_NODISCARD std::span< const Entity > exclusions_view() const
Returns negative selector ids used during archetype creation.
Definition query_common.h:1040
GAIA_NODISCARD bool has_dep_flag(DependencyFlags dependency) const
Tests whether a dependency fact was recorded.
Definition query_common.h:1065
DependencyFlags flags
Combined DependencyFlags describing the compiled query shape.
Definition query_common.h:1020
GAIA_NODISCARD std::span< const Entity > create_selectors_view() const
Returns positive selector ids used during archetype creation.
Definition query_common.h:1034
uint8_t sourceEntityCnt
Number of valid entries in sourceEntities.
Definition query_common.h:1016
GAIA_NODISCARD std::span< const Entity > src_entities_view() const
Returns concrete source-entity dependencies.
Definition query_common.h:1052
GAIA_NODISCARD std::span< const Entity > relations_view() const
Returns relation-version dependencies.
Definition query_common.h:1046
QueryEntityArray relations
Relations whose topology versions affect cached results.
Definition query_common.h:1006
uint8_t sourceTermCnt
Number of fixed-source terms, including duplicate source entities.
Definition query_common.h:1018
void clear()
Resets dependency counts and flags while retaining fixed storage.
Definition query_common.h:1023
QueryEntityArray createSelectors
Positive selector ids used for archetype-create propagation.
Definition query_common.h:1002
uint8_t createSelectorCnt
Number of valid entries in createSelectors.
Definition query_common.h:1010
uint8_t relationCnt
Number of valid entries in relations.
Definition query_common.h:1014
QueryEntityArray sourceEntities
Concrete source entities whose archetype versions affect cached results.
Definition query_common.h:1008
void add_rel(Entity relation)
Adds a unique relation-version dependency.
Definition query_common.h:1071
uint8_t exclusionCnt
Number of valid entries in exclusions.
Definition query_common.h:1012
GAIA_NODISCARD bool can_reuse_src_cache() const
Checks whether each fixed-source term has a distinct tracked entity.
Definition query_common.h:1091
void add_src_entity(Entity entity)
Adds a unique concrete source-entity dependency.
Definition query_common.h:1081
QueryEntityArray exclusions
Negative selector ids used to reject new archetypes.
Definition query_common.h:1004
Cold canonical payload used exclusively by shared-query hashing and equality.
Definition query_common.h:1097
QueryEntityArray changed
Canonicalized changed-filter ids reused by hash/equality for shared query dedup.
Definition query_common.h:1101
cnt::sarray< QueryTerm, MAX_ITEMS_IN_QUERY > lookupTerms
Canonicalized lookup terms reused by hash/equality for shared query dedup.
Definition query_common.h:1099
QueryEntityArray groupDeps
Canonicalized group dependency ids reused by hash/equality for shared query dedup.
Definition query_common.h:1103
Compact compiled query payload used by matching, identity, and cache maintenance.
Definition query_common.h:998
uint16_t readWriteMask
Read-write mask. Bit 0 stands for component 0 in component arrays. A set bit means write access is re...
Definition query_common.h:1152
uint8_t changedCnt
Number of valid changed-filter ids and field mappings.
Definition query_common.h:1119
QueryEntityArray groupDeps
Explicit grouping invalidation dependencies for custom group_by callbacks.
Definition query_common.h:1125
Entity sortBy
Entity to sort the archetypes by. EntityBad for no sorting.
Definition query_common.h:1127
TGroupByFunc groupByFunc
Function to use to perform the grouping.
Definition query_common.h:1133
uint8_t idsCnt
Number of valid ids and terms in the fixed-capacity query arrays.
Definition query_common.h:1117
GAIA_NODISCARD DynamicCacheKind calc_dynamic_cache_kind() const
Returns the dynamic-cache dependency shape derived from cache policy and dependencies.
Definition query_common.h:1276
uint32_t as_mask_0
Mask for items with Is relationship pair. If the id is a pair, the first part (id) is written here.
Definition query_common.h:1138
Entity groupBy
Entity to group the archetypes by. EntityBad for no grouping.
Definition query_common.h:1131
bool hasOnlyDirectOrTerms
True when the query contains only direct OR/NOT terms and at least one OR term.
Definition query_common.h:1166
void add_group_dep(Entity relation)
Adds a declared grouping invalidation dependency.
Definition query_common.h:1242
cnt::sarray< uint8_t, MAX_ITEMS_IN_QUERY > changedFields
Query term index for each changed-filter component after query canonicalization.
Definition query_common.h:1123
QueryEntityArray ids
Array of queried ids.
Definition query_common.h:1107
GAIA_NODISCARD QueryLookupHash::Type hash_lookup_key_payload() const
Returns the hash contribution from canonical lookup-key payload arrays.
Definition query_common.h:1385
GAIA_NODISCARD bool uses_src_trav_snapshot() const
Returns whether reusable dynamic-cache checks use a traversed source closure snapshot.
Definition query_common.h:1307
GAIA_NODISCARD bool has_sort_payload() const
Returns true when sort identity payload is active.
Definition query_common.h:1456
uint32_t as_mask_1
Mask for items with Is relationship pair. If the id is a pair, the second part (gen) is written here.
Definition query_common.h:1141
bool canDirectEntitySeedEvalShape
True when the query shape is eligible for direct entity seed evaluation.
Definition query_common.h:1164
uint8_t firstOr
First OR record in pairs/ids/ops.
Definition query_common.h:1147
uint16_t cacheSrcTrav
Maximum allowed size of an explicitly cached traversed-source lookup closure.
Definition query_common.h:1156
GAIA_NODISCARD QueryLookupHash::Type hash_sort_payload() const
Returns the hash contribution from sort identity payload.
Definition query_common.h:1462
QueryMask queryMask
Component mask used for faster matching of simple queries.
Definition query_common.h:1135
uint8_t firstAny
First ANY record in pairs/ids/ops.
Definition query_common.h:1145
GAIA_NODISCARD std::span< QueryTerm > lookup_terms_view_mut()
Returns mutable canonicalized lookup terms used by shared query deduplication.
Definition query_common.h:1212
GAIA_NODISCARD bool identity_payload_equal(const Data &other) const
Returns true when the shared query identity payload matches another query context payload.
Definition query_common.h:1472
GAIA_NODISCARD std::span< const Entity > changed_lookup_view() const
Returns canonicalized changed-filter lookup ids used by shared query deduplication.
Definition query_common.h:1218
void refresh_lookup_keys()
Refreshes canonical lookup arrays used by shared query deduplication.
Definition query_common.h:1340
GAIA_NODISCARD std::span< const QueryTerm > lookup_terms_view() const
Returns canonicalized lookup terms used by shared query deduplication.
Definition query_common.h:1206
GAIA_NODISCARD std::span< const Entity > ids_view() const
Returns authored query ids in canonical execution order.
Definition query_common.h:1182
GAIA_NODISCARD std::span< const Entity > group_deps_view() const
Returns explicit grouping invalidation dependencies.
Definition query_common.h:1200
QueryArchetypeCacheIndexMap lastMatchedArchetypeIdx_All
Index of the last checked archetype in the component-to-archetype map.
Definition query_common.h:1111
CreateArchetypeMatchKind createArchetypeMatchKind
Create-time archetype matcher derived from query shape.
Definition query_common.h:1174
Entity directTargetEvalId
Term id used by the specialized direct-target evaluation shape.
Definition query_common.h:1160
void add_group_deps()
Adds all grouping invalidation relations to the dependency set.
Definition query_common.h:1252
GAIA_NODISCARD std::span< const uint8_t > changed_fields_view() const
Returns query-term indices matching changed-filter components.
Definition query_common.h:1194
QueryArchetypeCacheIndexMap lastMatchedArchetypeIdx_Or
Incremental lookup cursors for OR selector terms.
Definition query_common.h:1113
GAIA_NODISCARD QueryLookupHash calc_lookup_hash() const
Returns the finalized lookup hash for shared query identity.
Definition query_common.h:1511
GAIA_NODISCARD bool sort_payload_equal(const Data &other) const
Returns true when the sort identity payload matches another query context payload.
Definition query_common.h:1450
GAIA_NODISCARD std::span< const QueryTerm > terms_view() const
Returns compiled terms in execution order.
Definition query_common.h:1270
GAIA_NODISCARD bool uses_direct_src_version_tracking() const
Returns whether reusable dynamic-cache checks use direct source entity archetype versions.
Definition query_common.h:1301
GAIA_NODISCARD std::span< const Entity > group_deps_lookup_view() const
Returns canonicalized group dependency lookup ids used by shared query deduplication.
Definition query_common.h:1230
DynamicCacheKind dynamicCacheKind
Dynamic-cache dependency shape derived from compiled query metadata.
Definition query_common.h:1176
Dependencies deps
Explicit dependency metadata derived from query shape.
Definition query_common.h:1170
GAIA_NODISCARD std::span< Entity > group_deps_lookup_view_mut()
Returns mutable canonicalized group dependency lookup ids used by shared query deduplication.
Definition query_common.h:1236
TSortByFunc sortByFunc
Function to use to perform sorting.
Definition query_common.h:1129
uint16_t flags
Query flags.
Definition query_common.h:1154
bool canDirectTargetEval
True when the query can evaluate concrete target entities directly.
Definition query_common.h:1162
GAIA_NODISCARD std::span< Entity > changed_lookup_view_mut()
Returns mutable canonicalized changed-filter lookup ids used by shared query deduplication.
Definition query_common.h:1224
GAIA_NODISCARD std::span< QueryTerm > terms_view_mut()
Returns mutable compiled terms in execution order.
Definition query_common.h:1265
uint8_t firstNot
First NOT record in pairs/ids/ops.
Definition query_common.h:1143
CachePolicy cachePolicy
Cache maintenance policy derived from query shape.
Definition query_common.h:1172
GAIA_NODISCARD bool calc_can_reuse_dynamic_cache() const
Returns whether the current query shape can reuse dynamic-cache results.
Definition query_common.h:1313
uint8_t groupDepCnt
Number of defined group dependencies.
Definition query_common.h:1149
GAIA_NODISCARD bool grouping_payload_equal(const Data &other) const
Returns true when grouping identity payload matches another query context payload.
Definition query_common.h:1439
QueryEntityArray changed
Array of filtered components.
Definition query_common.h:1121
GAIA_NODISCARD bool lookup_keys_equal(const Data &other) const
Returns true when canonical lookup arrays match another query context payload.
Definition query_common.h:1352
GAIA_NODISCARD std::span< const Entity > changed_view() const
Returns changed-filter component ids.
Definition query_common.h:1188
GAIA_NODISCARD QueryLookupHash::Type hash_identity_payload() const
Returns the hash contribution from the full shared query identity payload.
Definition query_common.h:1502
cnt::sarray< QueryTerm, MAX_ITEMS_IN_QUERY > terms
Array of terms.
Definition query_common.h:1109
GAIA_NODISCARD QueryLookupHash::Type hash_grouping_payload() const
Returns the hash contribution from grouping identity payload.
Definition query_common.h:1492
LookupIdentity lookupIdentity
Cold canonical shared-query identity payload.
Definition query_common.h:1178
DirectTargetEvalKind directTargetEvalKind
Specialized direct-target evaluation shape for single-term queries.
Definition query_common.h:1158
QueryArchetypeCacheIndexMap lastMatchedArchetypeIdx_Not
Incremental lookup cursors for NOT selector terms.
Definition query_common.h:1115
bool canReuseDynamicCache
True when a dynamic cache can be reused by checking tracked runtime inputs.
Definition query_common.h:1168
Authored and compiled state defining query identity and execution behavior.
Definition query_common.h:885
GAIA_NODISCARD bool operator!=(const QueryCtx &other) const noexcept
Compares query contexts for distinct shared query identity.
Definition query_common.h:1896
struct gaia::ecs::QueryCtx::Data data
Compiled query payload.
ComponentCache * cc
Component cache.
Definition query_common.h:889
const World * w
World against which the query is compiled and executed.
Definition query_common.h:887
void refresh()
Rebuilds derived masks, dependency metadata, and cache policy after authored terms change.
Definition query_common.h:1526
GAIA_NODISCARD bool operator==(const QueryCtx &other) const noexcept
Compares query contexts during initial shared-query lookup.
Definition query_common.h:1883
QueryFlags
Query maintenance and execution flags derived during compilation.
Definition query_common.h:896
@ HasPrefabTerms
Query explicitly mentions Prefab and therefore bypasses automatic exclusion.
Definition query_common.h:914
@ SortGroups
Cached group ranges require sorting.
Definition query_common.h:902
@ MatchPrefab
Includes prefab entities without requiring an explicit Prefab term.
Definition query_common.h:912
@ Empty
No query flags are set.
Definition query_common.h:898
@ SortEntities
Cached entity slices require sorting.
Definition query_common.h:900
@ OrderGroups
Grouped archetypes are ordered by group identifier during cache refresh.
Definition query_common.h:916
@ Complex
Query requires the general matching path.
Definition query_common.h:904
@ HasVariableTerms
Query contains variable-based lookup terms.
Definition query_common.h:910
@ Recompile
VM opcode recompilation is pending.
Definition query_common.h:906
@ HasSourceTerms
Query contains fixed-source lookup terms.
Definition query_common.h:908
DependencyFlags
Dependency facts derived from the compiled term set.
Definition query_common.h:968
@ DependencyHasWildcardTerms
At least one wildcard id or pair term is present.
Definition query_common.h:982
@ DependencyHasPositiveTerms
At least one positive ALL or OR term is present.
Definition query_common.h:976
@ DependencyHasSourceTerms
At least one term uses a fixed source entity.
Definition query_common.h:972
@ DependencyHasEntityFilterTerms
At least one term requires per-entity filtering.
Definition query_common.h:990
@ DependencyHasVariableTerms
At least one term contains a runtime variable.
Definition query_common.h:974
@ DependencyHasPotentialInheritedIdTerms
A term shape may resolve through inherited-id matching.
Definition query_common.h:994
@ DependencyHasAnyTerms
At least one optional ANY term is present.
Definition query_common.h:980
@ DependencyHasInheritedDataTerms
Iteration requires cached inherited component pointers.
Definition query_common.h:992
@ DependencyHasTraversalTerms
At least one source term traverses a relation.
Definition query_common.h:988
@ DependencyHasSort
Query has an entity sorting callback.
Definition query_common.h:984
@ DependencyNone
No dependency facts are present.
Definition query_common.h:970
@ DependencyHasNegativeTerms
At least one negative NOT term is present.
Definition query_common.h:978
@ DependencyHasGroup
Query has an archetype grouping callback.
Definition query_common.h:986
QueryIdentity q
Query identity.
Definition query_common.h:893
CreateArchetypeMatchKind
Matcher selected for newly created archetypes.
Definition query_common.h:930
@ DirectStructuralTerms
Evaluates a small immediate ALL, OR, and NOT query directly on the archetype.
@ Vm
Uses the normal one-archetype VM path.
DirectTargetEvalKind
Specialized evaluation shape for concrete target entities.
Definition query_common.h:954
@ Generic
Uses the general compiled query evaluator.
@ SingleAllSemanticIs
Evaluates one required semantic Is term.
@ SingleAllInherited
Evaluates one required term through inherited component data.
@ SingleAllInIs
Evaluates one required inherited-inclusive Is term.
@ SingleAllDirect
Evaluates one required direct-storage term.
static GAIA_NODISCARD bool equals_no_handle_assumption(const QueryCtx &leftCtx, const QueryCtx &rightCtx) noexcept
Compares shared query identity without requiring invalid handles.
Definition query_common.h:1870
QueryLookupHash hashLookup
Lookup hash for this query.
Definition query_common.h:891
DynamicCacheKind
Dynamic-cache dependency shape derived from compiled query metadata.
Definition query_common.h:938
@ Variable
Dynamic cache tracks runtime variable bindings only.
@ TraversedSource
Dynamic cache tracks a traversed source closure.
@ DirectSource
Dynamic cache tracks concrete source entity archetype versions.
@ Mixed
Dynamic cache tracks more than one dependency family.
@ None
Query does not use dynamic-cache validation.
@ RelationOnly
Dynamic cache is invalidated by relation version dependencies only.
CachePolicy
Strategy used to maintain cached archetype matches.
Definition query_common.h:920
@ Immediate
Updates a structural query immediately when an archetype is created.
@ Lazy
Refreshes a structural query lazily on the next read.
@ Dynamic
Repairs source- or variable-dependent cached state on demand.
void init(World *pWorld)
Attaches the query context to a world and its component cache.
Definition query_common.h:1520
Hashmap lookup structure used for Entity.
Definition query_common.h:422
QueryHandle handle() const
Returns the represented query handle.
Definition query_common.h:453
bool operator!=(const QueryHandleLookupKey &other) const
Compares lookup keys for inequality.
Definition query_common.h:476
bool operator==(const QueryHandleLookupKey &other) const
Compares lookup keys using their cached hashes and handles.
Definition query_common.h:466
static constexpr bool IsDirectHashKey
Indicates that Gaia containers may consume hash() without rehashing the key.
Definition query_common.h:438
QueryHandleLookupKey(QueryHandle handle)
Constructs a lookup key and precomputes its hash.
Definition query_common.h:443
size_t hash() const
Returns the precomputed container hash.
Definition query_common.h:459
Stable query-slot identifier combining a slot index and generation.
Definition query_common.h:356
static constexpr uint32_t IdMask
Bit mask spanning the query-id portion of a packed handle.
Definition query_common.h:358
GAIA_NODISCARD auto gen() const
Returns the query slot generation.
Definition query_common.h:408
GAIA_NODISCARD auto id() const
Returns the query slot identifier.
Definition query_common.h:403
GAIA_NODISCARD auto value() const
Returns the packed handle representation.
Definition query_common.h:413
GAIA_NODISCARD constexpr bool operator!=(const QueryHandle &other) const noexcept
Compares packed query handles for inequality.
Definition query_common.h:397
QueryHandle(QueryId id, uint32_t gen)
Constructs a handle from query slot metadata.
Definition query_common.h:377
Slot and serialization identity owned by a compiled query context.
Definition query_common.h:865
GAIA_NODISCARD QuerySerBuffer & ser_buffer(World *world)
Returns this query's serialization buffer in a world.
Definition query_common.h:874
QueryHandle handle
Query id.
Definition query_common.h:867
QueryId serId
Serialization id.
Definition query_common.h:869
void ser_buffer_reset(World *world)
Resets this query's serialization buffer in a world.
Definition query_common.h:879
Additional options for query terms. This can be used to configure source lookup, traversal and access...
Definition query_common.h:516
QueryTermOptions & trav_self_parent(Entity relation=ChildOf)
Checks the source and its immediate relation target.
Definition query_common.h:576
uint8_t travDepth
Maximum number of traversal steps. 0 means unlimited traversal depth (bounded internally,...
Definition query_common.h:528
QueryTermOptions & write()
Requests mutable access to the term.
Definition query_common.h:648
QueryTermOptions & trav_depth(uint8_t maxDepth)
Sets the maximum traversal distance.
Definition query_common.h:634
Entity entSrc
Source entity to query from.
Definition query_common.h:521
QueryTermOptions & trav_self_down(Entity relation=ChildOf)
Checks the source and recursively traverses entities targeting it.
Definition query_common.h:596
QueryTermOptions & trav(Entity relation=ChildOf)
Traverses the source and its relation targets without a user depth limit.
Definition query_common.h:546
QueryTermOptions & trav_child(Entity relation=ChildOf)
Checks only immediate entities targeting the source.
Definition query_common.h:606
Entity entTrav
Optional traversal relation used for source lookup.
Definition query_common.h:523
QueryAccess access
Access mode for the term. When None, typed query terms infer read/write access from template mutabili...
Definition query_common.h:531
QueryMatchKind matchKind
Match semantics for terms with special meaning, such as Pair(Is, X).
Definition query_common.h:533
QueryTermOptions & src(Entity source)
Selects a fixed or variable source entity for the term.
Definition query_common.h:538
QueryTermOptions & in()
Allows direct and inherited matches for the term.
Definition query_common.h:662
QueryTravKind travKind
Source traversal filter.
Definition query_common.h:525
QueryTermOptions & trav_kind(QueryTravKind kind)
Replaces the traversal filter without changing its relation or depth.
Definition query_common.h:626
static constexpr uint8_t TravDepthUnlimited
Traversal-depth value selecting the internally bounded unlimited mode.
Definition query_common.h:518
QueryTermOptions & read()
Requests read-only access to the term.
Definition query_common.h:641
QueryTermOptions & trav_parent(Entity relation=ChildOf)
Checks only the immediate relation target of the source.
Definition query_common.h:566
QueryTermOptions & trav_down(Entity relation=ChildOf)
Traverses entities targeting the source without a user depth limit.
Definition query_common.h:586
QueryTermOptions & direct()
Restricts the term to direct storage matches.
Definition query_common.h:655
QueryTermOptions & trav_self_child(Entity relation=ChildOf)
Checks the source and immediate entities targeting it.
Definition query_common.h:616
QueryTermOptions & trav_up(Entity relation=ChildOf)
Traverses relation targets without checking the source itself.
Definition query_common.h:556
Internal representation of QueryInput.
Definition query_common.h:732
bool operator==(const QueryTerm &other) const
Compares the matching identity of two compiled terms.
Definition query_common.h:755
Entity id
Queried id.
Definition query_common.h:734
Archetype * srcArchetype
Archetype of the src entity.
Definition query_common.h:746
uint8_t travDepth
Maximum number of traversal steps.
Definition query_common.h:742
QueryMatchKind matchKind
Match semantics for this term.
Definition query_common.h:744
bool operator!=(const QueryTerm &other) const
Compares the matching identity of two compiled terms for inequality.
Definition query_common.h:762
uint8_t fieldIndex
Stable execution field index matching the user-defined query field order.
Definition query_common.h:750
Entity entTrav
Optional traversal relation for source lookups.
Definition query_common.h:738
QueryOpKind op
Operation to perform with the term.
Definition query_common.h:748
Entity src
Source of where the queried id is looked up at.
Definition query_common.h:736
QueryTravKind travKind
Source traversal filter.
Definition query_common.h:740
One lookup-key record collected while indexing a single archetype.
Definition query_common.h:333
EntityLookupKey key
Entity or wildcard-pair lookup key represented by this record.
Definition query_common.h:335
ComponentIndexEntry entry
Reverse-index data associated with key.
Definition query_common.h:337
GAIA_NODISCARD bool matches(EntityLookupKey other) const
Tests whether this item represents a lookup key.
Definition query_common.h:342
Functor for sorting terms in a query before compilation.
Definition query_common.h:1902
constexpr bool operator()(const QueryTerm &lhs, const QueryTerm &rhs) const
Orders two terms by their canonical lookup representation.
Definition query_common.h:1907