Deki 1.3.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches

Represents a scene containing objects and components. More...

#include <Scene.h>

Public Types

using OnObjectsAboutToBeDestroyedFn = std::function<void(const std::vector<DekiObject*>&)>

Public Member Functions

 Scene ()
 ~Scene ()
DekiObjectInstantiate (Scene *targetScene)
 Instantiate this scene into another scene.
DekiObjectInstantiate (Scene *targetScene, float x, float y)
 Instantiate this scene with a specific position.
void AddObject (DekiObject *obj)
void RemoveObject (DekiObject *obj)
const std::vector< DekiObject * > & GetObjects () const
const std::vector< DekiBehaviour * > & GetBehaviours ()
void InvalidateBehavioursCache ()
DekiObjectCreateDekiObject (const std::string &name="DekiObject")
void DestroyDekiObject (DekiObject *dekiObject)
DekiObjectFindDekiObject (const std::string &name)
DekiObjectFindDekiObject (uint32_t id)
bool LoadData (const uint8_t *data, size_t size)
void InsertObjectAt (DekiObject *obj, size_t index)
int GetObjectIndex (DekiObject *obj) const
bool SaveToFile (const std::string &filePath)
bool LoadFromFile (const std::string &filePath)
std::string SaveToJsonString ()
bool LoadFromJsonString (const std::string &jsonStr)
DekiObjectDuplicateObject (const DekiObject *source)
bool ExpandInstance (DekiObject *instanceObj)
void CollapseInstance (DekiObject *instanceObj)
void ApplyOverrides (DekiObject *instanceObj, const nlohmann::json &overrides)
void CollectOverrides (const DekiObject *instanceRoot, const DekiObject *obj, nlohmann::json &overrides) const
void SetOnObjectsAboutToBeDestroyed (OnObjectsAboutToBeDestroyedFn fn)
 Out of line: the callback is stored in a side table in Scene.cpp, not in a member, so that sizeof(Scene) does not depend on DEKI_EDITOR.
const std::string & GetName () const
void SetName (const std::string &sceneName)
bool IsLoaded () const

Static Public Member Functions

static SceneLoad (const char *path, bool cache=false)
 Load a scene by asset path through AssetManager.
static SceneLoadInternal (const char *path)
 Load a scene directly from the filesystem (binary MessagePack).
static SceneLoadFromMemory (const uint8_t *data, size_t size)
 Load a scene from memory buffer.
static std::vector< std::pair< std::string, std::string > > CollectUnknownProperties ()
 Property keys found in a scene file that no component's current metadata recognises, as {component type name, key}.
static void ClearUnknownProperties ()
 Forget everything collected so far, so a check can scope itself to 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}: the file still carries the name from before a rename.
static nlohmann::json ComponentPropertiesToJson (const DekiComponent *comp, const DekiComponentMeta &meta)
 Every reflected property of comp — its base class's first, then its own — as the JSON a scene file holds for it, keyed by reflected name.
static nlohmann::json ComponentDefaultsToJson (const DekiComponentMeta &meta)
 ComponentPropertiesToJson for a default-constructed instance of meta.

Static Public Attributes

static constexpr const char * AssetTypeName = "Scene"
 Asset type name for AssetManager::Load<T>() lookup.
static std::function< std::string(const std::string &guid)> s_GuidToPathResolver

Detailed Description

Represents a scene containing objects and components.

A Scene is the fundamental content unit in Deki Engine. It can contain objects with components and can be:

  • Loaded as the active/running scene
  • Instanced inside another scene (what other engines call a prefab)
  • Distributed and loaded at runtime

This unified concept eliminates the scene/prefab distinction other engines draw - here everything is a scene.

Member Typedef Documentation

◆ OnObjectsAboutToBeDestroyedFn

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

Constructor & Destructor Documentation

◆ Scene()

Scene::Scene ( )

◆ ~Scene()

Scene::~Scene ( )

Member Function Documentation

◆ Load()

Scene * Scene::Load ( const char * path,
bool cache = false )
static

Load a scene by asset path through AssetManager.

Always returns a fresh Scene instance with the original data.

Parameters
pathAsset-relative path without extension (e.g., "scenes/settings/settings")
cacheIf true, pins the raw file bytes in RAM so subsequent loads skip disk I/O. If false (default), reads from disk every time. Either way, a fresh instance is returned — cached bytes are never mutated.
Returns
Loaded scene or nullptr on failure

◆ LoadInternal()

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

Load a scene directly from the filesystem (binary MessagePack).

Parameters
pathResolved filesystem path to the compiled .scene binary
Returns
Loaded scene or nullptr on failure
Note
Used internally by AssetManager and SceneSystem. Prefer Load() for user code.

◆ LoadFromMemory()

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

Load a scene from memory buffer.

Parameters
dataPointer to scene data
sizeSize of the data
Returns
Loaded scene or nullptr on failure

◆ Instantiate() [1/2]

DekiObject * Scene::Instantiate ( Scene * targetScene)

Instantiate this scene into another scene.

Parameters
targetSceneThe scene to add the instanced objects to
Returns
The root DekiObject of the instanced scene, or nullptr on failure

◆ Instantiate() [2/2]

DekiObject * Scene::Instantiate ( Scene * targetScene,
float x,
float y )

Instantiate this scene with a specific position.

Parameters
targetSceneThe scene to add the instanced objects to
xX position for the root object
yY position for the root object
Returns
The root DekiObject of the instanced scene, or nullptr on failure

◆ AddObject()

void Scene::AddObject ( DekiObject * obj)

◆ RemoveObject()

void Scene::RemoveObject ( DekiObject * obj)

◆ GetObjects()

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

◆ GetBehaviours()

const std::vector< DekiBehaviour * > & Scene::GetBehaviours ( )

◆ InvalidateBehavioursCache()

void Scene::InvalidateBehavioursCache ( )
inline

◆ CreateDekiObject()

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

◆ DestroyDekiObject()

void Scene::DestroyDekiObject ( DekiObject * dekiObject)

◆ FindDekiObject() [1/2]

DekiObject * Scene::FindDekiObject ( const std::string & name)

◆ FindDekiObject() [2/2]

DekiObject * Scene::FindDekiObject ( uint32_t id)

◆ LoadData()

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

◆ InsertObjectAt()

void Scene::InsertObjectAt ( DekiObject * obj,
size_t index )

◆ GetObjectIndex()

int Scene::GetObjectIndex ( DekiObject * obj) const

◆ SaveToFile()

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

◆ LoadFromFile()

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

◆ SaveToJsonString()

std::string Scene::SaveToJsonString ( )

◆ LoadFromJsonString()

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

◆ DuplicateObject()

DekiObject * Scene::DuplicateObject ( const DekiObject * source)

◆ ExpandInstance()

bool Scene::ExpandInstance ( DekiObject * instanceObj)

◆ CollapseInstance()

void Scene::CollapseInstance ( DekiObject * instanceObj)

◆ ApplyOverrides()

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

◆ CollectOverrides()

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

◆ CollectUnknownProperties()

std::vector< std::pair< std::string, std::string > > Scene::CollectUnknownProperties ( )
static

Property keys found in a scene file that no component's current metadata recognises, as {component type name, key}.

Reflected member names ARE the scene-file format: reflection_codegen emits each C++ identifier as a DekiHashString key, with no opt-in gate. So renaming a reflected member silently changes the on-disk key, the parser's switch falls through, and the property reverts to its default — no error, no log line. The value itself survives (unknown keys are re-emitted on save), but the behaviour is gone.

This is the detector for that. Load every scene in a project and assert this comes back empty; a missed rename names itself. Populated on load, so it reflects the scenes loaded so far in this session.

◆ ClearUnknownProperties()

void Scene::ClearUnknownProperties ( )
static

Forget everything collected so far, so a check can scope itself to the scenes it is about to load.

Clears the legacy list too.

◆ CollectLegacyProperties()

std::vector< std::pair< std::string, std::string > > Scene::CollectLegacyProperties ( )
static

Property keys read through a DEKI_RENAMED_FROM alias since the last clear, as {component type name, old key}: the file still carries the name from before a rename.

A save writes the current name, so this is a warning ("re-save to migrate"), not an error.

◆ ComponentPropertiesToJson()

nlohmann::json Scene::ComponentPropertiesToJson ( const DekiComponent * comp,
const DekiComponentMeta & meta )
static

Every reflected property of comp — its base class's first, then its own — as the JSON a scene file holds for it, keyed by reflected name.

The same writer SaveToFile uses, so a value prints exactly as it would be saved. The docs build reads default values through this.

◆ ComponentDefaultsToJson()

nlohmann::json Scene::ComponentDefaultsToJson ( const DekiComponentMeta & meta)
static

ComponentPropertiesToJson for a default-constructed instance of meta.

Null when the type is abstract or has no factory.

◆ SetOnObjectsAboutToBeDestroyed()

void Scene::SetOnObjectsAboutToBeDestroyed ( OnObjectsAboutToBeDestroyedFn fn)

Out of line: the callback is stored in a side table in Scene.cpp, not in a member, so that sizeof(Scene) does not depend on DEKI_EDITOR.

std::function is 32 bytes here — too much to carry unconditionally on an embedded target that can never invoke it.

◆ GetName()

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

◆ SetName()

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

◆ IsLoaded()

bool Scene::IsLoaded ( ) const
inline

Member Data Documentation

◆ AssetTypeName

const char* Scene::AssetTypeName = "Scene"
staticconstexpr

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

◆ s_GuidToPathResolver

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

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