DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
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 ()
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 AddObject (Object *obj)
void RemoveObject (Object *obj)
const std::vector< Object * > & GetObjects () const
const std::vector< Component * > & GetActiveComponents ()
void InvalidateComponentsCache ()
Object * CreateDekiObject (const std::string &name="DekiObject")
void DestroyDekiObject (Object *dekiObject)
Object * FindDekiObject (const std::string &name)
Object * FindDekiObject (uint32_t id)
bool LoadData (const uint8_t *data, size_t size)
void InsertObjectAt (Object *obj, size_t index)
int GetObjectIndex (Object *obj) const
bool SaveToFile (const std::string &filePath)
bool LoadFromFile (const std::string &filePath)
std::string SaveToJsonString ()
bool LoadFromJsonString (const std::string &jsonStr)
Object * DuplicateObject (const Object *source)
bool ExpandInstance (Object *instanceObj)
void CollapseInstance (Object *instanceObj)
void ApplyOverrides (Object *instanceObj, const nlohmann::json &overrides)
void CollectOverrides (const Object *instanceRoot, const Object *obj, nlohmann::json &overrides) const
bool TryCollectOverrides (const Object *instanceRoot, const Object *obj, nlohmann::json &overrides) const
 CollectOverrides, telling whether there was a source to compare with.
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.
const std::string & GetName () const
void SetName (const std::string &sceneName)
bool IsLoaded () const

Static Public Member Functions

static Scene * Load (const char *path, bool cache=false)
 Loads a scene through AssetManager.
static Scene * LoadInternal (const char *path)
 Loads a compiled .scene (binary MessagePack) from a resolved filesystem path, or returns nullptr.
static Scene * LoadFromMemory (const uint8_t *data, size_t size)
 Loads a scene from compiled bytes in memory, or returns nullptr.
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 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 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 nlohmann::json ComponentDefaultsToJson (const ComponentMeta &meta)
 ComponentPropertiesToJson for a default-constructed instance of meta.

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

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

◆ 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.

◆ 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().

◆ LoadFromMemory()

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

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

◆ 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).

◆ AddObject()

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

◆ RemoveObject()

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

◆ GetObjects()

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

◆ GetActiveComponents()

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

◆ InvalidateComponentsCache()

void Deki::Scene::InvalidateComponentsCache ( )
inline

◆ CreateDekiObject()

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

◆ DestroyDekiObject()

void Deki::Scene::DestroyDekiObject ( Object * dekiObject)

◆ FindDekiObject() [1/2]

Object * Deki::Scene::FindDekiObject ( const std::string & name)

◆ FindDekiObject() [2/2]

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

◆ LoadData()

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

◆ InsertObjectAt()

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

◆ GetObjectIndex()

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

◆ SaveToFile()

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

◆ LoadFromFile()

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

◆ SaveToJsonString()

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

◆ LoadFromJsonString()

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

◆ DuplicateObject()

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

◆ ExpandInstance()

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

◆ CollapseInstance()

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

◆ ApplyOverrides()

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

◆ CollectOverrides()

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

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ GetName()

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

◆ SetName()

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

◆ IsLoaded()

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

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: