Skip to content

Engine → ECS → query.h

query

Syntax

class CONJURE_API query

Constructors

AccessSignatureDescription
publicquery( world &target, query_desc desc);
publicquery( const query &) = default;
publicquery( query &&) noexcept = default;

Destructors

AccessSignatureDescription
public~query();

Variables

AccessNameTypeDefaultDescription
privatemContextconst system_context *nullptr
privatemDescquery_desc{}
privatemMatchescore::small_vector<archetype *, QUERY_INLINE_MATCHES>{}
privatemRegistryconst component_registry *nullptr
privatemSeenArchetypeCountu320
privatemWorldworld *nullptr

Functions

Public

bind_context

void bind_context(
    const system_context *context) noexcept;

Attaches the running system: every chunk_view this query builds carries it, so a non-const span of a component the system did not declare as written asserts (Debug validation), and non-const spans stamp the system's run version instead of the current world version, so the system never sees its own writes through its next since_version(). Set by system_context::view(); nullptr for plain world queries. The context must outlive the query's iterations.

chunk

[[nodiscard]] chunk_view chunk(
    u32 index);

The chunk at a flat index over the visited chunks (bindings). An out-of-range index yields an invalid view. The caller holds world::lock_iteration() while using the result. The view stamps like for_each_chunk: the bound system's run version, else the current world version.

chunk_count

[[nodiscard]] u32 chunk_count();

Number of chunks the next iteration would visit. Refreshes lazily first (archetypes created since the last refresh join the cached matches), so it is non-const by design.

chunk_passes

[[nodiscard]] bool chunk_passes(
    const archetype &owner,
    u32 chunkIndex) const noexcept;

True when a chunk of a matching archetype passes the changed filter and is not empty.

context

[[nodiscard]] const system_context *context() const noexcept;

The system bound with bind_context(), or nullptr.

desc

[[nodiscard]] const query_desc &desc() const noexcept;

The description this query was built from.

entity_count

[[nodiscard]] u32 entity_count();

Number of entities in the chunks the next iteration would visit. Refreshes lazily first, so it is non-const by design.

for_each_chunk

template <typename Callable> void for_each_chunk(
    Callable &&callable);

Invokes callable(chunk_view &) for every non-empty chunk of every matching archetype that passes the changed filter, under an iteration lock. Non-const spans acquired from the view stamp the run version of the system bound with bind_context(), otherwise the world version current when the iteration started.

matches

[[nodiscard]] std::span<archetype *const> matches();

The matching archetypes. Refreshes lazily first, so it is non-const by design.

owner

[[nodiscard]] world &owner() const noexcept;

The world this query iterates.

refresh

void refresh();

Scans the archetypes created since the last refresh and caches the matching ones.

registry

[[nodiscard]] const component_registry &registry() const noexcept;

The registry of the world.

reset

void reset(
    query_desc desc);

Replaces the description and forgets the cached matches.

Private

visit_chunks

void visit_chunks(
    void (*visit)(void *context, chunk_view &view),
    void *context);

Operator Overloads

Public

operator=

query &operator=(
    const query &) = default;
query &operator=(
    query &&) noexcept = default;