Engine → Scene → scene_serializer.h
scene_serializer
| Type | Class |
| Namespace | conjure::scene |
| Include File Path | engine/include/conjure/scene/scene_serializer.h |
| Source File Path | engine/src/scene/scene_serializer.cpp |
| API ↗ | Scenes, hierarchy and prefabs, Scene files, prefabs and snapshots |
Syntax
Functions
Public
bind_asset_refs
bind_asset_refsstatic void bind_asset_refs(
ecs::world &target,
std::span<const ecs::entity> entities,
assets::asset_manager &assets,
std::vector<assets::asset_id> *outIds);Binds every non-null asset_ref field of the entities through asset_manager::bind_slot (never loads) and appends the bound ids to outIds when given.
bind_entity
bind_entitystatic void bind_entity(
ecs::world &target,
ecs::entity entity,
assets::asset_manager &assets);bind_asset_refs for one entity (the editor after component_from_json).
capture_entity
capture_entity[[nodiscard]] static core::result<ecs::entity_archive> capture_entity(
const scene &source,
ecs::entity entity);capture_subtree of the entity alone: one entry, no parent link, every reflected reference outside it dropped (a serializer-owned form keeps its live ids, as for save_entity). INVALID_ENTITY for a dead entity; BAD_FORMAT naming the entity for a layer index of 32 or more.
capture_subtree
capture_subtree[[nodiscard]] static core::result<ecs::entity_archive> capture_subtree(
const scene &source,
ecs::entity root,
ecs::archive_options options = {});Captures a subtree in hierarchy order (root first). Without keepExternalReferences the root's parent link is dropped so entry 0 is a true root; with it the link is kept for undo payloads. INVALID_ENTITY for a dead root; BAD_FORMAT naming the entity when one carries a layer index of 32 or more, which instantiation would refuse (so duplicate_subtree, save_subtree and prefab::build_document, diff and apply refuse it too).
collect_hierarchy_order
collect_hierarchy_orderstatic void collect_hierarchy_order(
const scene &source,
std::vector<ecs::entity> &out);Every entity of the tree in hierarchy order: roots in root order, each subtree depth first in sibling order.
instantiate_subtree
instantiate_subtree[[nodiscard]] static core::result<ecs::entity> instantiate_subtree(
scene &target,
const core::json::value &in,
ecs::entity parent,
bool keepGuids,
u32 index = APPEND_CHILD);Parses a prefab-format value and instantiates it under parent at index; keepGuids keeps the file's guids (DUPLICATE_GUID on a collision), otherwise every guid is regenerated.
load_scene
load_scene[[nodiscard]] static core::result<instantiate_report> load_scene(
scene &target,
const scene_document &document,
scene_id owner,
guid_policy guids);Instantiates a parsed scene into the target (one copy, owner recorded on the new roots) and orders the roots as the header lists them (missing guids skipped with WARN, unlisted roots appended with WARN).
load_scene_file
load_scene_file[[nodiscard]] static core::result<instantiate_report> load_scene_file(
scene &target,
core::vfs::file_system &fs,
std::string_view path,
scene_id owner,
guid_policy guids);Reads, parses and loads a file from the file system.
parse_document
parse_document[[nodiscard]] static core::result<scene_document> parse_document(
const core::json::value &in,
const ecs::component_registry ®istry);Validates the header (BAD_FORMAT, UNSUPPORTED_VERSION) and reads the archive against the registry (unknown components preserved, SERIALIZATION_FAILED for malformed ones). A component field renamed since the file was written is read under its current name first: an old file's character_controller maxSlopeAngleDegrees becomes maxSlopeAngleRadians, converted to radians.
parse_prefab
parse_prefab[[nodiscard]] static core::result<prefab_document> parse_prefab(
const core::json::value &in,
const ecs::component_registry ®istry);Like parse_document for the prefab format; BAD_FORMAT for an empty archive, PREFAB_MULTIPLE_ROOTS unless entry 0 is the only entry without a parent, DUPLICATE_GUID when two entries share a guid.
save_entity
save_entity[[nodiscard]] static core::result<void> save_entity(
const scene &source,
ecs::entity entity,
core::json::writer &out);Writes one entity without its children in the prefab format, the entity-only form of save_subtree (the editor's play-mode persist restores a pinned entity with it). The entity keeps its name and guid; its parent link is dropped, and so is every reflected entity reference, a reference to a child included, since nothing but the entity is inside the archive. A component whose serializer owns its form (no reflection, a remapEntities hook: the script component) keeps the live ids of the entities outside it, which the caller retargets (the editor's persist writes them through their guids). INVALID_ENTITY for a dead entity, BAD_FORMAT for a layer index of 32 or more.
save_scene
save_scene[[nodiscard]] static core::result<void> save_scene(
const scene &source,
core::json::writer &out);Writes the scene (header keys format, version, name, settings, roots, archive) into the writer; every entity of the tree in hierarchy order. BAD_FORMAT naming the entity, and nothing written, when one carries a layer index of 32 or more (loading would refuse it).
save_scene_file
save_scene_file[[nodiscard]] static core::result<void> save_scene_file(
const scene &source,
core::vfs::file_system &fs,
std::string_view path);save_scene into a file written atomically.
save_subtree
save_subtree[[nodiscard]] static core::result<void> save_subtree(
const scene &source,
ecs::entity root,
core::json::writer &out);Writes a subtree in the prefab format (the root keeps its name).
write_document
write_document[[nodiscard]] static core::result<void> write_document(
const scene_document &document,
core::json::writer &out);Writes the scene format from a document (used by the importer to canonicalise a file).
write_prefab
write_prefab[[nodiscard]] static core::result<void> write_prefab(
const prefab_document &document,
core::json::writer &out);Writes the prefab format (format, version, name, archive).