![]() |
vkmEngine 1.0.0
A C++ game engine · vkmengine.com
|
Save / load a Scene + the assets it references to/from JSON. More...
Functions | |
| void | saveComponents (const Scene &scene, EntityId id, nlohmann::json &out, const ResourceManager &resources) |
Write every serialized component of id into out, naming the entities they refer to by their scene slot. | |
| void | saveComponents (const Scene &scene, EntityId id, nlohmann::json &out, const ResourceManager &resources, const EntityNamer &name) |
Write every serialized component of id into out, naming the entities they refer to through name. | |
| void | loadComponents (const nlohmann::json &src, Scene &scene, EntityId entity, const ResourceManager &resources, const EntityResolver &resolve) |
Add every component present in src to entity. | |
| bool | save (const Scene &scene, const ResourceManager &resources, const std::string &path) |
Save scene + the assets it references to path. | |
| bool | load (Scene &scene, ResourceManager &resources, const std::string &path) |
Load a scene from path, replacing the live scene atomically. | |
| std::vector< MissingAssetRef > | unresolvedRefs (const Scene &scene, const ResourceManager &resources, EntityId id) |
The entries of id's unresolved-reference record whose field is still empty. | |
| std::string | saveToString (const Scene &scene, const ResourceManager &resources) |
Serialize scene + the assets it references to an in-memory JSON string (same content as save(), no file written). | |
| bool | loadFromString (const std::string &text, Scene &scene, ResourceManager &resources, const Prefab::InstanceSlots *instanceSlots=nullptr) |
Load a scene from an in-memory JSON string produced by saveToString(), replacing scene and merging into resources. | |
Save / load a Scene + the assets it references to/from JSON.
An assets block sits beside entities, rebuilt through AssetSerializer::loadAssets; components name assets by name.
load() stages the scene and the asset graph and swaps both in only on full success; loadFromString() stages the scene only. Entities return to their saved slots (Scene::createEntityAt), so references in the file need no remap.
| void Vkm::Engine::SceneSerializer::saveComponents | ( | const Scene & | scene, |
| EntityId | id, | ||
| nlohmann::json & | out, | ||
| const ResourceManager & | resources ) |
Write every serialized component of id into out, naming the entities they refer to by their scene slot.
| scene | Scene holding the entity. |
| id | Entity to serialize. |
| out | JSON object to fill, keyed by component name. |
| resources | Resolves asset handles to their names. |
| void Vkm::Engine::SceneSerializer::saveComponents | ( | const Scene & | scene, |
| EntityId | id, | ||
| nlohmann::json & | out, | ||
| const ResourceManager & | resources, | ||
| const EntityNamer & | name ) |
Write every serialized component of id into out, naming the entities they refer to through name.
For a carrier with its own numbering, such as a prefab's file order.
| scene | Scene holding the entity. |
| id | Entity to serialize. |
| out | JSON object to fill, keyed by component name. |
| resources | Resolves asset handles to their names. |
| name | Names the entities the components refer to. |
| void Vkm::Engine::SceneSerializer::loadComponents | ( | const nlohmann::json & | src, |
| Scene & | scene, | ||
| EntityId | entity, | ||
| const ResourceManager & | resources, | ||
| const EntityResolver & | resolve ) |
Add every component present in src to entity.
Hierarchy is not read: its parent may not exist yet, so callers wire it in a second pass.
| src | JSON object written by saveComponents. |
| scene | Scene to add into. |
| entity | The entity receiving the components. |
| resources | Resolves asset names back to handles. |
| resolve | Reads the carrier's names for entities back to entities. |
|
nodiscard |
Save scene + the assets it references to path.
| scene | Scene to write. |
| resources | Resolves each handle the scene holds to the name written. |
| path | File to write. |
|
nodiscard |
Load a scene from path, replacing the live scene atomically.
| scene | Scene to replace. |
| resources | Asset graph, replaced by the one the file's assets build. |
| path | File to read. |
| std::vector< MissingAssetRef > Vkm::Engine::SceneSerializer::unresolvedRefs | ( | const Scene & | scene, |
| const ResourceManager & | resources, | ||
| EntityId | id ) |
The entries of id's unresolved-reference record whose field is still empty.
The record is never trimmed, since an undo can empty a filled field again and the name must still be there; readers ask this instead. Answered by writing the entity and reading the field back, as the save does.
| scene | Scene holding the entity. |
| resources | Asset graph the entity's references resolve against. |
| id | Entity to ask about. |
| std::string Vkm::Engine::SceneSerializer::saveToString | ( | const Scene & | scene, |
| const ResourceManager & | resources ) |
Serialize scene + the assets it references to an in-memory JSON string (same content as save(), no file written).
Pairs with loadFromString(); see PlaySnapshot.
| scene | Scene to write. |
| resources | Resolves each handle the scene holds to the name written. |
|
nodiscard |
Load a scene from an in-memory JSON string produced by saveToString(), replacing scene and merging into resources.
The scene swaps in as in load(); the asset graph is not swapped, so every handle issued from it stays valid. The document stores an instance as a reference, so instanceSlots restores where its own entities stood.
| text | A document from saveToString(). |
| scene | Scene to replace on success. |
| resources | Asset graph to resolve against, added to only where a name is absent. |
| instanceSlots | Optional: Prefab::instanceSlotsOf the source world; without it an instance's entities take whatever slots are free. |