Skip to content

Engine → ECS → entity.h

entity_remap

Syntax

class entity_remap

Constructors

AccessSignatureDescription
publicentity_remap() = default;
publicexplicit entity_remap( std::vector<entity> targets);Takes ownership of a local -> real table.
publicentity_remap( const entity_remap &) = default;
publicentity_remap( entity_remap &&) noexcept = default;

Destructors

AccessSignatureDescription
public~entity_remap() = default;

Variables

AccessNameTypeDefaultDescription
privatemIndexstd::vector<std::pair<u64, u32>>{}
privatemTargetsstd::vector<entity>{}

Functions

Public

clear

void clear() noexcept;

Empties the table and its index.

index_targets

void index_targets();

Optional: builds a sorted index of the targets so remap() turns a real entity into its local index by binary search instead of a linear scan. Worth calling once the table is complete and many real -> local lookups follow (entity_archive::capture does). A target listed twice maps to its first local index, as the linear scan does. set(), resize() and clear() drop the index, after which remap() scans again until the next call.

remap

[[nodiscard]] entity remap(
    entity value) const noexcept;

Resolves one reference in whichever direction the value needs: an archive-local value becomes its real entity (as resolve), a real entity that is one of the targets becomes the archive-local index of that target, and every other value is returned unchanged. The same table therefore serves entity_archive::capture (real -> local, targets = the captured entities) and world::instantiate (local -> real): a live world never holds archive-local ids and an archive never holds a real id that is also one of its own targets. A real value is found by binary search after index_targets(), by a linear scan otherwise.

resize

void resize(
    u32 count);

Resizes the table; new entries are NULL_ENTITY. Drops the index_targets() index.

resolve

[[nodiscard]] entity resolve(
    entity value) const noexcept;

Resolves one reference: an archive-local value becomes its real entity (NULL_ENTITY when the local index is out of range); every other value, real or null, is returned unchanged.

set

void set(
    u32 localIndex,
    entity target);

Sets the real entity of a local index, growing the table when needed. Drops the index_targets() index.

size

[[nodiscard]] u32 size() const noexcept;

Number of local indices the table covers.

target

[[nodiscard]] entity target(
    u32 localIndex) const noexcept;

The real entity of a local index, or NULL_ENTITY when out of range.

targets

[[nodiscard]] std::span<const entity> targets() const noexcept;

The whole table.

Operator Overloads

Public

operator=

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