vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
prefab.h
1#pragma once
2
3#include <cstdint>
4#include <map>
5#include <set>
6#include <string>
7#include <vector>
8
9#include "ecs/entity.h"
10#include "ecs/component/core/transform.h"
11#include "ecs/component/prefab/prefab_instance.h"
12
13namespace Vkm::Engine {
14
15class Scene;
16class ResourceManager;
17
32namespace Prefab {
33
45
53 bool isInsideInstance(const Scene& scene, EntityId id);
54
69 bool save(Scene& scene, EntityId root, const std::string& path, const ResourceManager& resources);
70
83 bool definesComponent(const std::string& path, uint32_t uid, const std::string& component);
84
92 using BuiltSlots = std::map<uint32_t, uint32_t>;
93
100 using InstanceSlots = std::map<uint32_t, BuiltSlots>;
101
110
118
130 Scene& scene,
131 ResourceManager& resources,
132 const std::string& path,
133 const Transform& at
134 );
135
147 EntityId instantiate(Scene& scene, ResourceManager& resources, const std::string& path);
148
171 Scene& scene,
172 ResourceManager& resources,
173 const std::string& path,
174 EntityId root,
175 const std::vector<PrefabOverride>& overrides = {},
176 std::set<std::string>* drift = nullptr,
177 const BuiltSlots* slots = nullptr
178 );
179
198 Scene& scene,
199 ResourceManager& resources,
200 const std::string& path,
201 EntityId entity,
202 uint32_t uid,
203 const std::string& component,
204 const std::vector<PrefabOverride>& overrides
205 );
206
207} // namespace Prefab
208
209} // 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
Entity subtrees saved once and instanced many times.
Definition prefab.h:32
bool save(Scene &scene, EntityId root, const std::string &path, const ResourceManager &resources)
Write root and its descendants to path as a prefab.
std::map< uint32_t, BuiltSlots > InstanceSlots
Every instance's BuiltSlots, keyed by the slot its root holds.
Definition prefab.h:100
EntityId instanceRootOf(const Scene &scene, EntityId id)
The root of the prefab instance id belongs to: itself, or its nearest ancestor carrying PrefabInstanc...
bool reloadComponent(Scene &scene, ResourceManager &resources, const std::string &path, EntityId entity, uint32_t uid, const std::string &component, const std::vector< PrefabOverride > &overrides)
Re-read one component of one instance entity from the prefab.
bool isInsideInstance(const Scene &scene, EntityId id)
Is id inside (but not the root of) a prefab instance?
bool instantiateInto(Scene &scene, ResourceManager &resources, const std::string &path, EntityId root, const std::vector< PrefabOverride > &overrides={}, std::set< std::string > *drift=nullptr, const BuiltSlots *slots=nullptr)
Build a prefab into an entity that already exists.
BuiltSlots builtSlotsOf(const Scene &scene, EntityId root)
Where the instance rooted at root put each of its entities.
std::map< uint32_t, uint32_t > BuiltSlots
Where one instance's built entities stand: prefab uid to slot.
Definition prefab.h:92
EntityId instantiate(Scene &scene, ResourceManager &resources, const std::string &path, const Transform &at)
Instantiate path into scene, placing the root at at.
bool definesComponent(const std::string &path, uint32_t uid, const std::string &component)
Does the prefab at path define component on the entity uid names?
InstanceSlots instanceSlotsOf(const Scene &scene)
builtSlotsOf for every instance in scene.
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
Local position, rotation and scale of an entity.
Definition transform.h:17