vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
scene_serializer.h
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include <nlohmann/json_fwd.hpp>
7
8#include "ecs/component/core/missing_assets.h"
9#include "ecs/entity.h"
10#include "ecs/entity_mapping.h"
11#include "io/scene/prefab.h"
12
13namespace Vkm::Engine {
14
15class Scene;
16class ResourceManager;
17
28namespace SceneSerializer {
39 const Scene& scene,
40 EntityId id,
41 nlohmann::json& out,
42 const ResourceManager& resources
43 );
44
58 const Scene& scene,
59 EntityId id,
60 nlohmann::json& out,
61 const ResourceManager& resources,
62 const EntityNamer& name
63 );
64
78 const nlohmann::json& src,
79 Scene& scene,
80 EntityId entity,
81 const ResourceManager& resources,
82 const EntityResolver& resolve
83 );
84
93 [[nodiscard]] bool save(const Scene& scene, const ResourceManager& resources, const std::string& path);
94
104 [[nodiscard]] bool load(Scene& scene, ResourceManager& resources, const std::string& path);
105
119 std::vector<MissingAssetRef> unresolvedRefs(
120 const Scene& scene,
121 const ResourceManager& resources,
122 EntityId id
123 );
124
135 std::string saveToString(const Scene& scene, const ResourceManager& resources);
136
153 [[nodiscard]] bool loadFromString(
154 const std::string& text,
155 Scene& scene,
156 ResourceManager& resources,
157 const Prefab::InstanceSlots* instanceSlots = nullptr
158 );
159
160} // namespace SceneSerializer
161
162} // namespace Vkm::Engine
Open type-erased resource registry with typed handles and generational lifetimes.
Definition resource_manager.h:46
Central registry managing entities and an open set of component types.
Definition scene.h:29
std::map< uint32_t, BuiltSlots > InstanceSlots
Every instance's BuiltSlots, keyed by the slot its root holds.
Definition prefab.h:100
Save / load a Scene + the assets it references to/from JSON.
Definition scene_serializer.h:28
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 in...
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 slo...
bool load(Scene &scene, ResourceManager &resources, const std::string &path)
Load a scene from path, replacing the live scene atomically.
void loadComponents(const nlohmann::json &src, Scene &scene, EntityId entity, const ResourceManager &resources, const EntityResolver &resolve)
Add every component present in src to entity.
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.
bool save(const Scene &scene, const ResourceManager &resources, const std::string &path)
Save scene + the assets it references to path.
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(),...
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23