|
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
|
A scene: objects with components, and Deki's basic unit of content. More...
#include <deki/Scene.h>
Public Types | |
| using | OnObjectsAboutToBeDestroyedFn = std::function<void(const std::vector<Object*>&)> |
Public Member Functions | |
| Scene () | |
| ~Scene () | |
| void | AddObject (Object *obj) |
| void | ApplyOverrides (Object *instanceObj, const nlohmann::json &overrides) |
| void | CollapseInstance (Object *instanceObj) |
| void | CollectOverrides (const Object *instanceRoot, const Object *obj, nlohmann::json &overrides) const |
| Object * | CreateDekiObject (const std::string &name="DekiObject") |
| void | DestroyDekiObject (Object *dekiObject) |
| Deletes dekiObject and its children. | |
| Object * | DuplicateObject (const Object *source) |
| bool | ExpandInstance (Object *instanceObj) |
| Object * | FindDekiObject (const std::string &name) |
| The first object with this name, or this id, anywhere in the scene. | |
| Object * | FindDekiObject (uint32_t id) |
| const std::vector< Component * > & | GetActiveComponents () |
| const std::string & | GetName () const |
| int | GetObjectIndex (Object *obj) const |
| const std::vector< Object * > & | GetObjects () const |
| void | InsertObjectAt (Object *obj, size_t index) |
| Object * | Instantiate (Scene *targetScene) |
| Adds a copy of this scene's objects to targetScene. | |
| Object * | Instantiate (Scene *targetScene, float x, float y) |
| Instantiate(targetScene), with the root object placed at (x, y). | |
| void | InvalidateComponentsCache () |
| bool | IsLoaded () const |
| bool | LoadData (const uint8_t *data, size_t size) |
| bool | LoadFromFile (const std::string &filePath) |
| bool | LoadFromJsonString (const std::string &jsonStr) |
| void | RemoveObject (Object *obj) |
| bool | SaveToFile (const std::string &filePath) |
| std::string | SaveToJsonString () |
| void | SetName (const std::string &sceneName) |
| void | SetOnObjectsAboutToBeDestroyed (OnObjectsAboutToBeDestroyedFn fn) |
| Out of line: the callback lives in a side table in Scene.cpp, not in a member, so sizeof(Scene) does not depend on DEKI_EDITOR and embedded targets do not carry a 32-byte std::function they never call. | |
| bool | TryCollectOverrides (const Object *instanceRoot, const Object *obj, nlohmann::json &overrides) const |
| CollectOverrides, telling whether there was a source to compare with. | |
Static Public Member Functions | |
| static std::vector< const PropertyInfo * > | AllProperties (const ComponentMeta &meta) |
| Every reflected property of meta's type: its base classes' first, from the root down, then its own. | |
| static void | ClearUnknownProperties () |
| Forgets everything collected so far, so a check can cover only the scenes it is about to load. | |
| static std::vector< std::pair< std::string, std::string > > | CollectLegacyProperties () |
| Property keys read through a DEKI_RENAMED_FROM alias since the last clear, as {component type name, old key}. | |
| static std::vector< std::pair< std::string, std::string > > | CollectUnknownProperties () |
| Property keys found in a scene file that no component's current metadata knows, as {component type name, key}. | |
| static nlohmann::json | ComponentDefaultsToJson (const ComponentMeta &meta) |
| ComponentPropertiesToJson for a default-constructed instance of meta. | |
| static nlohmann::json | ComponentPropertiesToJson (const Component *comp, const ComponentMeta &meta) |
| Every reflected property of comp (its base class's first, then its own) as the JSON a scene file holds, keyed by reflected name. | |
| static const PropertyInfo * | FindProperty (const ComponentMeta &meta, const std::string &name) |
| The property named name among AllProperties(meta), or null. | |
| static Scene * | Load (const char *path, bool cache=false) |
| Loads a scene through AssetManager. | |
| static Scene * | LoadFromMemory (const uint8_t *data, size_t size) |
| Loads a scene from compiled bytes in memory, or returns nullptr. | |
| static Scene * | LoadInternal (const char *path) |
| Loads a compiled .scene (binary MessagePack) from a resolved filesystem path, or returns nullptr. | |
| static bool | PropertyFromJson (Component *comp, const PropertyInfo &prop, const nlohmann::json &value) |
| Sets prop from value: any form PropertyToJson writes, the forms older scene files hold, and the plain ones code builds: an enum's stored number, a colour as [r, g, b, a]. | |
| static bool | PropertyFromJsonObject (Component *comp, const PropertyInfo &prop, const nlohmann::json &props) |
| PropertyFromJson of prop's entry in props, an object keyed by property name as a scene's or settings file's "properties" is: under its name, else under its DEKI_RENAMED_FROM name. | |
| static nlohmann::json | PropertyToJson (const Component *comp, const PropertyInfo &prop) |
| prop's value as a scene file holds it: an enum by name (its number when the enum declares none for it), a colour as "#RRGGBBAA", an asset by GUID (with its source as {"guid", "source"}), a vector as an array. | |
| static void | TransformFromJson (Object *obj, const nlohmann::json &transform) |
| Sets obj's local transform from TransformToJson's form. | |
| static nlohmann::json | TransformToJson (const Object *obj) |
| obj's local transform as a scene file holds it: x, y, rotation (in radians), scaleX and scaleY, and the depth (z, rotationX, rotationY, scaleZ) where it is not at its default, so a 2D project's files carry none. | |
Static Public Attributes | |
| static constexpr const char * | kAssetTypeName = "Scene" |
| Asset type name for AssetManager::Load<T>(). | |
| static std::function< std::string(const std::string &guid)> | s_GuidToPathResolver |
Friends | |
| class | LifecycleManager |
A scene: objects with components, and Deki's basic unit of content.
A scene can be loaded as the running scene, instanced inside another scene (what other engines call a prefab), or shipped and loaded at runtime. There is no separate prefab type.
| using Deki::Scene::OnObjectsAboutToBeDestroyedFn = std::function<void(const std::vector<Object*>&)> |
| Deki::Scene::Scene | ( | ) |
| Deki::Scene::~Scene | ( | ) |
| void Deki::Scene::AddObject | ( | Object * | obj | ) |
|
static |
Every reflected property of meta's type: its base classes' first, from the root down, then its own.
The one walk that saving, loading and looking a property up share.
| void Deki::Scene::ApplyOverrides | ( | Object * | instanceObj, |
| const nlohmann::json & | overrides ) |
|
static |
Forgets everything collected so far, so a check can cover only the scenes it is about to load.
Clears the legacy list too.
| void Deki::Scene::CollapseInstance | ( | Object * | instanceObj | ) |
|
static |
Property keys read through a DEKI_RENAMED_FROM alias since the last clear, as {component type name, old key}.
A save writes the current name, so this is a warning ("re-save to migrate"), not an error.
| void Deki::Scene::CollectOverrides | ( | const Object * | instanceRoot, |
| const Object * | obj, | ||
| nlohmann::json & | overrides ) const |
|
static |
Property keys found in a scene file that no component's current metadata knows, as {component type name, key}.
Reflected member names are the scene-file keys, so renaming a member changes its key and the old value silently falls back to its default (the value is kept and written back on save, but nothing reads it). Load every scene in a project and check this is empty to catch a rename that lacks DEKI_RENAMED_FROM. Filled on load, so it covers the scenes loaded so far in this session.
|
static |
ComponentPropertiesToJson for a default-constructed instance of meta.
Null when the type is abstract or has no factory.
|
static |
Every reflected property of comp (its base class's first, then its own) as the JSON a scene file holds, keyed by reflected name.
Uses the same writer as SaveToFile, so values print exactly as saved. The docs build reads default values through this.
| Object * Deki::Scene::CreateDekiObject | ( | const std::string & | name = "DekiObject" | ) |
| void Deki::Scene::DestroyDekiObject | ( | Object * | dekiObject | ) |
Deletes dekiObject and its children.
ObjectRefs to them read as empty from this call on. From a component's Awake, Start or Update the object stops running at once and its memory stays valid until that phase ends, so it is safe to destroy any object, the caller's own included. A raw pointer you kept to it is yours to drop.
| bool Deki::Scene::ExpandInstance | ( | Object * | instanceObj | ) |
| Object * Deki::Scene::FindDekiObject | ( | const std::string & | name | ) |
The first object with this name, or this id, anywhere in the scene.
An object being destroyed, and everything under it, is not found.
| Object * Deki::Scene::FindDekiObject | ( | uint32_t | id | ) |
|
static |
The property named name among AllProperties(meta), or null.
| const std::vector< Component * > & Deki::Scene::GetActiveComponents | ( | ) |
|
inline |
| int Deki::Scene::GetObjectIndex | ( | Object * | obj | ) | const |
|
inline |
| void Deki::Scene::InsertObjectAt | ( | Object * | obj, |
| size_t | index ) |
Adds a copy of this scene's objects to targetScene.
Returns the copy's root object, or nullptr on failure.
Instantiate(targetScene), with the root object placed at (x, y).
|
inline |
|
inline |
|
static |
Loads a scene through AssetManager.
path is asset-relative without extension (such as "scenes/settings/settings"). Always returns a fresh Scene, or nullptr on failure. With cache, the raw file bytes stay in RAM so later loads skip the disk; the cached bytes are never modified.
| bool Deki::Scene::LoadData | ( | const uint8_t * | data, |
| size_t | size ) |
| bool Deki::Scene::LoadFromFile | ( | const std::string & | filePath | ) |
| bool Deki::Scene::LoadFromJsonString | ( | const std::string & | jsonStr | ) |
|
static |
Loads a scene from compiled bytes in memory, or returns nullptr.
|
static |
Loads a compiled .scene (binary MessagePack) from a resolved filesystem path, or returns nullptr.
For AssetManager and SceneSystem; user code should call Load().
|
static |
Sets prop from value: any form PropertyToJson writes, the forms older scene files hold, and the plain ones code builds: an enum's stored number, a colour as [r, g, b, a].
False, leaving it as it was, when value is none of them.
|
static |
PropertyFromJson of prop's entry in props, an object keyed by property name as a scene's or settings file's "properties" is: under its name, else under its DEKI_RENAMED_FROM name.
False, leaving it as it was, when neither is there or the value does not fit.
|
static |
prop's value as a scene file holds it: an enum by name (its number when the enum declares none for it), a colour as "#RRGGBBAA", an asset by GUID (with its source as {"guid", "source"}), a vector as an array.
Discarded (is_discarded()) for a type a scene file does not store.
| void Deki::Scene::RemoveObject | ( | Object * | obj | ) |
| bool Deki::Scene::SaveToFile | ( | const std::string & | filePath | ) |
| std::string Deki::Scene::SaveToJsonString | ( | ) |
|
inline |
| void Deki::Scene::SetOnObjectsAboutToBeDestroyed | ( | OnObjectsAboutToBeDestroyedFn | fn | ) |
Out of line: the callback lives in a side table in Scene.cpp, not in a member, so sizeof(Scene) does not depend on DEKI_EDITOR and embedded targets do not carry a 32-byte std::function they never call.
|
static |
Sets obj's local transform from TransformToJson's form.
A key that is absent sets that part to its default.
|
static |
obj's local transform as a scene file holds it: x, y, rotation (in radians), scaleX and scaleY, and the depth (z, rotationX, rotationY, scaleZ) where it is not at its default, so a 2D project's files carry none.
The editor's one form of a transform: scene files, copy and paste, and undo use it.
| bool Deki::Scene::TryCollectOverrides | ( | const Object * | instanceRoot, |
| const Object * | obj, | ||
| nlohmann::json & | overrides ) const |
CollectOverrides, telling whether there was a source to compare with.
False when the source scene could not be found or loaded (a merge conflict, saved by a newer editor, missing for a moment); overrides is then empty, and saving it would drop the instance's overrides.
|
friend |
|
staticconstexpr |
Asset type name for AssetManager::Load<T>().
|
static |