DEKI/ENGINE docs
manual api reference
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
Loading...
Searching...
No Matches

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

Detailed Description

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.

Member Typedef Documentation

◆ OnObjectsAboutToBeDestroyedFn

using Deki::Scene::OnObjectsAboutToBeDestroyedFn = std::function<void(const std::vector<Object*>&)>

Constructor & Destructor Documentation

◆ Scene()

Deki::Scene::Scene ( )

◆ ~Scene()

Deki::Scene::~Scene ( )

Member Function Documentation

◆ AddObject()

void Deki::Scene::AddObject ( Object * obj)

◆ AllProperties()

std::vector< const PropertyInfo * > Deki::Scene::AllProperties ( const ComponentMeta & meta)
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.

◆ ApplyOverrides()

void Deki::Scene::ApplyOverrides ( Object * instanceObj,
const nlohmann::json & overrides )

◆ ClearUnknownProperties()

void Deki::Scene::ClearUnknownProperties ( )
static

Forgets everything collected so far, so a check can cover only the scenes it is about to load.

Clears the legacy list too.

◆ CollapseInstance()

void Deki::Scene::CollapseInstance ( Object * instanceObj)

◆ CollectLegacyProperties()

std::vector< std::pair< std::string, std::string > > Deki::Scene::CollectLegacyProperties ( )
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.

◆ CollectOverrides()

void Deki::Scene::CollectOverrides ( const Object * instanceRoot,
const Object * obj,
nlohmann::json & overrides ) const

◆ CollectUnknownProperties()

std::vector< std::pair< std::string, std::string > > Deki::Scene::CollectUnknownProperties ( )
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.

◆ ComponentDefaultsToJson()

nlohmann::json Deki::Scene::ComponentDefaultsToJson ( const ComponentMeta & meta)
static

ComponentPropertiesToJson for a default-constructed instance of meta.

Null when the type is abstract or has no factory.

◆ ComponentPropertiesToJson()

nlohmann::json Deki::Scene::ComponentPropertiesToJson ( const Component * comp,
const ComponentMeta & meta )
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.

◆ CreateDekiObject()

Object * Deki::Scene::CreateDekiObject ( const std::string & name = "DekiObject")

◆ DestroyDekiObject()

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.

◆ DuplicateObject()

Object * Deki::Scene::DuplicateObject ( const Object * source)

◆ ExpandInstance()

bool Deki::Scene::ExpandInstance ( Object * instanceObj)

◆ FindDekiObject() [1/2]

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.

◆ FindDekiObject() [2/2]

Object * Deki::Scene::FindDekiObject ( uint32_t id)

◆ FindProperty()

const PropertyInfo * Deki::Scene::FindProperty ( const ComponentMeta & meta,
const std::string & name )
static

The property named name among AllProperties(meta), or null.

◆ GetActiveComponents()

const std::vector< Component * > & Deki::Scene::GetActiveComponents ( )

◆ GetName()

const std::string & Deki::Scene::GetName ( ) const
inline

◆ GetObjectIndex()

int Deki::Scene::GetObjectIndex ( Object * obj) const

◆ GetObjects()

const std::vector< Object * > & Deki::Scene::GetObjects ( ) const
inline

◆ InsertObjectAt()

void Deki::Scene::InsertObjectAt ( Object * obj,
size_t index )

◆ Instantiate() [1/2]

Object * Deki::Scene::Instantiate ( Scene * targetScene)

Adds a copy of this scene's objects to targetScene.

Returns the copy's root object, or nullptr on failure.

◆ Instantiate() [2/2]

Object * Deki::Scene::Instantiate ( Scene * targetScene,
float x,
float y )

Instantiate(targetScene), with the root object placed at (x, y).

◆ InvalidateComponentsCache()

void Deki::Scene::InvalidateComponentsCache ( )
inline

◆ IsLoaded()

bool Deki::Scene::IsLoaded ( ) const
inline

◆ Load()

Scene * Deki::Scene::Load ( const char * path,
bool cache = false )
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.

◆ LoadData()

bool Deki::Scene::LoadData ( const uint8_t * data,
size_t size )

◆ LoadFromFile()

bool Deki::Scene::LoadFromFile ( const std::string & filePath)

◆ LoadFromJsonString()

bool Deki::Scene::LoadFromJsonString ( const std::string & jsonStr)

◆ LoadFromMemory()

Scene * Deki::Scene::LoadFromMemory ( const uint8_t * data,
size_t size )
static

Loads a scene from compiled bytes in memory, or returns nullptr.

◆ LoadInternal()

Scene * Deki::Scene::LoadInternal ( const char * path)
static

Loads a compiled .scene (binary MessagePack) from a resolved filesystem path, or returns nullptr.

For AssetManager and SceneSystem; user code should call Load().

◆ PropertyFromJson()

bool Deki::Scene::PropertyFromJson ( Component * comp,
const PropertyInfo & prop,
const nlohmann::json & value )
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.

◆ PropertyFromJsonObject()

bool Deki::Scene::PropertyFromJsonObject ( Component * comp,
const PropertyInfo & prop,
const nlohmann::json & props )
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.

◆ PropertyToJson()

nlohmann::json Deki::Scene::PropertyToJson ( const Component * comp,
const PropertyInfo & prop )
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.

◆ RemoveObject()

void Deki::Scene::RemoveObject ( Object * obj)

◆ SaveToFile()

bool Deki::Scene::SaveToFile ( const std::string & filePath)

◆ SaveToJsonString()

std::string Deki::Scene::SaveToJsonString ( )

◆ SetName()

void Deki::Scene::SetName ( const std::string & sceneName)
inline

◆ SetOnObjectsAboutToBeDestroyed()

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.

◆ TransformFromJson()

void Deki::Scene::TransformFromJson ( Object * obj,
const nlohmann::json & transform )
static

Sets obj's local transform from TransformToJson's form.

A key that is absent sets that part to its default.

◆ TransformToJson()

nlohmann::json Deki::Scene::TransformToJson ( const Object * obj)
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.

◆ TryCollectOverrides()

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.

◆ LifecycleManager

friend class LifecycleManager
friend

Member Data Documentation

◆ kAssetTypeName

const char* Deki::Scene::kAssetTypeName = "Scene"
staticconstexpr

Asset type name for AssetManager::Load<T>().

◆ s_GuidToPathResolver

std::function<std::string(const std::string& guid)> Deki::Scene::s_GuidToPathResolver
static

The documentation for this class was generated from the following file: