Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
helios::ecs::details::QueryState Struct Reference

Query state that caches archetype matching results. More...

#include <query_cache.hpp>

Public Member Functions

 QueryState () noexcept=default
 
 QueryState (const QueryState &other)
 
 QueryState (QueryState &&other) noexcept
 
 ~QueryState ()=default
 
QueryStateoperator= (const QueryState &other)
 
QueryStateoperator= (QueryState &&other) noexcept
 

Public Attributes

std::vector< std::reference_wrapper< const Archetype > > matching_archetypes
 Archetypes that match this query.
 
std::vector< size_tarchetype_generations
 Generation of each matched archetype when cached.
 
std::vector< ComponentTypeIdwith_component_types
 Required component types (sorted)
 
std::vector< ComponentTypeIdwithout_component_types
 Forbidden component types (sorted)
 
size_t query_generation = 0
 Generation when this state was computed.
 
size_t query_hash = 0
 Hash of the query signature.
 
std::atomic< size_tlast_access_time {0}
 Last access timestamp for LRU eviction.
 

Detailed Description

Query state that caches archetype matching results.

Inspired by Bevy's QueryState, this stores pre-computed information about which archetypes match a specific query signature. Each QueryState corresponds to a unique combination of required and forbidden components.

The state includes:

  • List of matching archetypes (cached)
  • Archetype generation counters (for invalidation detection)
  • Component type signature (for efficient lookup)

Definition at line 31 of file query_cache.hpp.

Constructor & Destructor Documentation

◆ QueryState() [1/3]

helios::ecs::details::QueryState::QueryState ( )
defaultnoexcept

◆ QueryState() [2/3]

helios::ecs::details::QueryState::QueryState ( const QueryState other)
inline

Definition at line 49 of file query_cache.hpp.

50 : matching_archetypes(other.matching_archetypes),
51 archetype_generations(other.archetype_generations),
52 with_component_types(other.with_component_types),
53 without_component_types(other.without_component_types),
54 query_generation(other.query_generation),
55 query_hash(other.query_hash),
56 last_access_time(other.last_access_time.load(std::memory_order_relaxed)) {}
std::vector< ComponentTypeId > with_component_types
Required component types (sorted)
size_t query_generation
Generation when this state was computed.
std::vector< ComponentTypeId > without_component_types
Forbidden component types (sorted)
std::vector< size_t > archetype_generations
Generation of each matched archetype when cached.
size_t query_hash
Hash of the query signature.
std::vector< std::reference_wrapper< const Archetype > > matching_archetypes
Archetypes that match this query.
std::atomic< size_t > last_access_time
Last access timestamp for LRU eviction.

◆ QueryState() [3/3]

helios::ecs::details::QueryState::QueryState ( QueryState &&  other)
inlinenoexcept

Definition at line 58 of file query_cache.hpp.

59 : matching_archetypes(std::move(other.matching_archetypes)),
60 archetype_generations(std::move(other.archetype_generations)),
61 with_component_types(std::move(other.with_component_types)),
62 without_component_types(std::move(other.without_component_types)),
63 query_generation(other.query_generation),
64 query_hash(other.query_hash),
65 last_access_time(other.last_access_time.load(std::memory_order_relaxed)) {}

◆ ~QueryState()

helios::ecs::details::QueryState::~QueryState ( )
default

Member Function Documentation

◆ operator=() [1/2]

QueryState & helios::ecs::details::QueryState::operator= ( const QueryState other)
inline

Definition at line 67 of file query_cache.hpp.

67 {
68 if (this == &other) [[unlikely]] {
69 return *this;
70 }
71
72 matching_archetypes = other.matching_archetypes;
73 archetype_generations = other.archetype_generations;
74 with_component_types = other.with_component_types;
75 without_component_types = other.without_component_types;
76 query_generation = other.query_generation;
77 query_hash = other.query_hash;
78 last_access_time.store(other.last_access_time.load(std::memory_order_relaxed), std::memory_order_relaxed);
79
80 return *this;
81}
BasicQuery< World, Allocator, Components... > Query
Type alias for query with mutable world access.
Definition query.hpp:2481

◆ operator=() [2/2]

QueryState & helios::ecs::details::QueryState::operator= ( QueryState &&  other)
inlinenoexcept

Definition at line 83 of file query_cache.hpp.

83 {
84 if (this == &other) [[unlikely]] {
85 return *this;
86 }
87
88 matching_archetypes = std::move(other.matching_archetypes);
89 archetype_generations = std::move(other.archetype_generations);
90 with_component_types = std::move(other.with_component_types);
91 without_component_types = std::move(other.without_component_types);
92 query_generation = other.query_generation;
93 query_hash = other.query_hash;
94 last_access_time.store(other.last_access_time.load(std::memory_order_relaxed), std::memory_order_relaxed);
95
96 return *this;
97}

Member Data Documentation

◆ archetype_generations

std::vector<size_t> helios::ecs::details::QueryState::archetype_generations

Generation of each matched archetype when cached.

Definition at line 33 of file query_cache.hpp.

◆ last_access_time

std::atomic<size_t> helios::ecs::details::QueryState::last_access_time {0}
mutable

Last access timestamp for LRU eviction.

Definition at line 38 of file query_cache.hpp.

38{0}; ///< Last access timestamp for LRU eviction

◆ matching_archetypes

std::vector<std::reference_wrapper<const Archetype> > helios::ecs::details::QueryState::matching_archetypes

Archetypes that match this query.

Definition at line 32 of file query_cache.hpp.

◆ query_generation

size_t helios::ecs::details::QueryState::query_generation = 0

Generation when this state was computed.

Definition at line 36 of file query_cache.hpp.

◆ query_hash

size_t helios::ecs::details::QueryState::query_hash = 0

Hash of the query signature.

Definition at line 37 of file query_cache.hpp.

◆ with_component_types

std::vector<ComponentTypeId> helios::ecs::details::QueryState::with_component_types

Required component types (sorted)

Definition at line 34 of file query_cache.hpp.

◆ without_component_types

std::vector<ComponentTypeId> helios::ecs::details::QueryState::without_component_types

Forbidden component types (sorted)

Definition at line 35 of file query_cache.hpp.