Skip to content

Engine → Scene → scene_snapshot.h

scene_snapshot

Syntax

struct CONJURE_API scene_snapshot

Constructors

AccessSignatureDescription
publicexplicit scene_snapshot( const ecs::component_registry &registry) noexcept;
publicscene_snapshot( scene_snapshot &&) noexcept = default;

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~scene_snapshot();

Variables

AccessNameTypeDefaultDescription
publicarchiveecs::entity_archive—
publicguidIndexstd::vector<snapshot_guid_entry>{}
publicnamestd::string{}
publicrootEntriesstd::vector<u32>{}
publicrootOwnersstd::vector<scene_id>{}
publicsettingscore::json::documentcore::json::document::object()
publicstructureVersionu640

Functions

Public

component_json

[[nodiscard]] core::result<core::json::document> component_json(
    const core::uuid &guid,
    ecs::component_id id,
    const scene &live) const;

The component of the entry carrying the guid as JSON, in the form the editor reads the live component of live (component_to_json plus the protocol's entity references), so a component the play session did not change reads equal to its live JSON, with two exceptions. What a serializer writes from outside the component's bytes is not in the copy: a running script's live JSON comes from its instance (its "started" and "created" flags, which the script component's copy drops, and every field of its class), the snapshot's from the component (the fields set before play). And a reflected reference to an entity destroyed since the capture reads as the entry's guid here and as null live. A reflected entity field that names a snapshot entry becomes that entry's guid string (null for a null reference or an entry without a guid); a reference outside the archive (a hand-built snapshot) becomes the guid of that entity in live, or null. A component whose serializer owns its JSON form (no reflection, a remapEntities hook: the script component) is copied, its references remapped through the hook to the entities of live that carry the referenced entries' guids (NULL_ENTITY when none does), written with its serializer and destroyed again; that costs one guid lookup per snapshot entry. A tag is {}. GUID_NOT_FOUND for a guid the snapshot does not hold, UNKNOWN_COMPONENT for an id the registry does not know, COMPONENT_NOT_PRESENT when the entry lacks the component; the serializer's error otherwise.

contains

[[nodiscard]] bool contains(
    const core::uuid &guid) const noexcept;

True when an entry of the snapshot carries the guid: the entity existed when the snapshot was taken. O(log n) through guidIndex.

entity_count

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

Entities held by the snapshot.

entry_guid

[[nodiscard]] std::optional<core::uuid> entry_guid(
    u32 entry) const noexcept;

The guid of an archive entry, or nullopt when the entry has none (or is out of range).

find_entry

[[nodiscard]] std::optional<u32> find_entry(
    const core::uuid &guid) const noexcept;

The archive index of the entry carrying the guid, or nullopt. O(log n) through guidIndex.

has_component

[[nodiscard]] bool has_component(
    const core::uuid &guid,
    ecs::component_id id) const noexcept;

True when the entry carrying the guid held the component when the snapshot was taken (a tag counts). False for an unknown guid and for TRANSIENT components, which a snapshot never holds.

index_guids

void index_guids();

Rebuilds guidIndex from the archive (one pass plus a sort). Entries without a guid, or with the null guid, are not indexed; when two entries share a guid the first in archive order wins.

subtree_guids

[[nodiscard]] std::vector<core::uuid> subtree_guids(
    const core::uuid &guid) const;

The guids of the subtree the entry carrying the guid had in the snapshot: the entry first, then its descendants in archive order (entries without a guid left out). Empty for an unknown guid. O(n) over the archive's parent links.

Operator Overloads

Public

operator=

scene_snapshot &operator=(
    scene_snapshot &&) noexcept = default;