Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::Scene Class Reference

Container for the entire game object graph. More...

#include <Scene.h>

Public Member Functions

void Update (f32 deltaTime)
 
void Clear ()
 Destroy all objects and reset the scene to an empty state.
 
GameObjectCreateObject (const std::string &name, GameObject *parent=nullptr)
 Create a plain GameObject owned by this scene.
 
GameObjectCreateObject (const std::string &type, const std::string &name, GameObject *parent=nullptr)
 
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<GameObject, T>>>
TCreateObject (const str &name, GameObject *parent=nullptr)
 Create a typed GameObject subclass owned by this scene.
 
bool SetParent (GameObject *obj, GameObject *parent)
 Move a GameObject in the hierarchy.
 
void SetMainCamera (GameObject *camera)
 Designate the camera object whose CameraComponent drives the view.
 
GameObjectGetMainCamera ()
 Returns the current main camera object (set via SetMainCamera).
 
std::vector< LightDataCollectLight ()
 Walk the entire object tree and collect all LightData.
 
const std::vector< std::unique_ptr< GameObject > > & GetRootObjects () const
 Editor access: iterate root GameObjects (non-owning).
 

Static Public Member Functions

static void RegisterTypes ()
 Update all root objects (which recursively update their children).
 
static std::shared_ptr< SceneLoad (const str &path)
 

Detailed Description

Container for the entire game object graph.

Owns root-level GameObjects and provides the three services that Engine::Run() needs each frame:

  1. Update() — propagate deltaTime to every active object and component.
  2. GetMainCamera() — return the designated camera object so the engine can extract CameraData.
  3. CollectLight() — walk the hierarchy and gather LightData from every LightComponent.

Definition at line 58 of file Scene.h.

Member Function Documentation

◆ Clear()

void mnd::Scene::Clear ( )

Destroy all objects and reset the scene to an empty state.

Definition at line 108 of file Scene.cpp.

References LOG_INFO.

◆ CollectLight()

std::vector< LightData > mnd::Scene::CollectLight ( )

Walk the entire object tree and collect all LightData.

Called by Engine::Run() once per frame. Each GameObject that has a LightComponent contributes one LightData entry.

Returns
Vector of LightData for all active lights in the scene.

Definition at line 82 of file Scene.cpp.

◆ CreateObject() [1/3]

GameObject * mnd::Scene::CreateObject ( const std::string &  name,
GameObject parent = nullptr 
)

Create a plain GameObject owned by this scene.

Parameters
nameDisplay name for the new object.
parentOptional parent; makes the object a child rather than a root.
Returns
Non-owning pointer to the new object.

Definition at line 132 of file Scene.cpp.

References mnd::GameObject::GetName(), kRootObjectLabel, LOG_INFO, mnd::GameObject::SetName(), and SetParent().

Referenced by mnd::ModelImporter::Import(), mnd::GameObject::LoadGLTF(), and mnd::ParseGLTFNode().

◆ CreateObject() [2/3]

GameObject * mnd::Scene::CreateObject ( const std::string &  type,
const std::string &  name,
GameObject parent = nullptr 
)

◆ CreateObject() [3/3]

template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<GameObject, T>>>
T * mnd::Scene::CreateObject ( const str name,
GameObject parent = nullptr 
)
inline

Create a typed GameObject subclass owned by this scene.

Use this overload when you need to store extra data directly on the GameObject instead of in a Component.

Template Parameters
TA class derived from GameObject.
Parameters
nameDisplay name.
parentOptional parent node.
Returns
Typed non-owning pointer to the new object.

Definition at line 92 of file Scene.h.

References SetParent(), and mnd::T.

◆ GetMainCamera()

GameObject * mnd::Scene::GetMainCamera ( )

Returns the current main camera object (set via SetMainCamera).

Definition at line 77 of file Scene.cpp.

◆ GetRootObjects()

const std::vector< std::unique_ptr< GameObject > > & mnd::Scene::GetRootObjects ( ) const
inline

Editor access: iterate root GameObjects (non-owning).

Definition at line 137 of file Scene.h.

◆ Load()

◆ RegisterTypes()

void mnd::Scene::RegisterTypes ( )
static

Update all root objects (which recursively update their children).

Parameters
deltaTimeSeconds since the previous frame.

Definition at line 29 of file Scene.cpp.

Referenced by mnd::Engine::Init().

◆ SetMainCamera()

void mnd::Scene::SetMainCamera ( GameObject camera)

Designate the camera object whose CameraComponent drives the view.

Parameters
cameraA GameObject that must have a CameraComponent attached.

Definition at line 72 of file Scene.cpp.

◆ SetParent()

bool mnd::Scene::SetParent ( GameObject obj,
GameObject parent 
)

Move a GameObject in the hierarchy.

Parameters
objThe object to re-parent.
parentNew parent, or nullptr to promote to root.
Returns
true if the operation succeeded.

Definition at line 339 of file Scene.cpp.

References mnd::GameObject::GetName(), mnd::GameObject::GetParent(), LOG_ERROR, and LOG_WARN.

Referenced by CreateObject(), CreateObject(), CreateObject(), mnd::GameObject::SetParent(), and Update().

◆ Update()

void mnd::Scene::Update ( f32  deltaTime)

Definition at line 44 of file Scene.cpp.

References SetParent().


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