Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
rendering_engine::SceneManager Class Reference

Manages scenes, resource caches, and scene transitions within the rendering engine. More...

#include <scene_manager.hpp>

Public Types

using Factory = std::function<std::unique_ptr<Scene>(SceneManager&)>

Public Member Functions

 SceneManager (IRenderer *renderer, IApplication *app)
 Constructs a SceneManager instance.
 ~SceneManager ()
 Destructor. Cleans up resources and active scenes.
virtual void Initialize ()
 Initializes the current scene and related caches.
virtual void Update (float deltaTime)
 Updates the currently active scene.
virtual void Draw ()
 Draws the active scene using the associated renderer.
virtual void Shutdown ()
 Releases all scene-related resources and shuts down the manager.
IApplicationGetApplication ()
 Returns the application associated with this SceneManager.
void LoadScene (std::string sceneName)
 Loads a new scene by name.
RenderResourceContext GetRenderResourceContext () const
 Retrieves the current RenderResourceContext.

Static Public Member Functions

static std::vector< std::pair< std::string, Factory > > & GetPendingRegistrations ()
 Type alias for the factory used to create scenes.
static bool RegisterScene (const std::string &name, Factory factory)
 Registers a scene type with a name string.
static std::unique_ptr< SceneCreateScene (const std::string &name, SceneManager &sm)
 Creates a scene instance by its registered name.

Static Public Attributes

static std::string sStartSceneName

Detailed Description

Manages scenes, resource caches, and scene transitions within the rendering engine.

SceneManager handles the creation, updating, and rendering of scenes. It maintains ownership of core caches (TextureCache, ModelCache, MaterialCache), and provides the RenderResourceContext that allows drawable objects to access shared rendering resources.

The class also supports dynamic scene registration through factories, enabling runtime creation of scenes by name.

See also
Scene, RenderResourceContext, TextureCache, ModelCache, MaterialCache

Definition at line 41 of file scene_manager.hpp.

Member Typedef Documentation

◆ Factory

using rendering_engine::SceneManager::Factory = std::function<std::unique_ptr<Scene>(SceneManager&)>

Definition at line 44 of file scene_manager.hpp.

Constructor & Destructor Documentation

◆ SceneManager()

rendering_engine::SceneManager::SceneManager ( IRenderer * renderer,
IApplication * app )

Constructs a SceneManager instance.

Parameters
rendererPointer to the active renderer instance.
appPointer to the owning application instance.

Definition at line 13 of file scene_manager.cpp.

14 :
15 mRenderer(renderer),
16 mApp(app),
17 mCurrentScene(nullptr),
18 mNextScene(nullptr)
19{}

◆ ~SceneManager()

rendering_engine::SceneManager::~SceneManager ( )

Destructor. Cleans up resources and active scenes.

Definition at line 21 of file scene_manager.cpp.

22{
23}

Member Function Documentation

◆ CreateScene()

std::unique_ptr< Scene > rendering_engine::SceneManager::CreateScene ( const std::string & name,
SceneManager & sm )
static

Creates a scene instance by its registered name.

Parameters
nameThe name of the registered scene type.
smReference to the SceneManager creating the scene.
Returns
Unique pointer to the newly created Scene instance.

Definition at line 145 of file scene_manager.cpp.

146{
147 std::unique_ptr<Scene> scene = nullptr;
148 auto& map = GetMap();
149 auto it = map.find(name);
150 if (it != map.end())
151 {
152 scene = (it->second)(sm);
153 }
154 return scene;
155}

◆ Draw()

void rendering_engine::SceneManager::Draw ( )
virtual

Draws the active scene using the associated renderer.

Definition at line 93 of file scene_manager.cpp.

94{
95 if (mCurrentScene)
96 {
97 mCurrentScene->Draw();
98 }
99}

◆ GetApplication()

IApplication * rendering_engine::SceneManager::GetApplication ( )

Returns the application associated with this SceneManager.

Returns
Pointer to the IApplication instance.

Definition at line 112 of file scene_manager.cpp.

113{
114 return mApp;
115}

◆ GetPendingRegistrations()

std::vector< std::pair< std::string, SceneManager::Factory > > & rendering_engine::SceneManager::GetPendingRegistrations ( )
static

Type alias for the factory used to create scenes.

Definition at line 117 of file scene_manager.cpp.

118{
119 static std::vector<std::pair<std::string, Factory>> pending;
120 return pending;
121}

◆ GetRenderResourceContext()

RenderResourceContext rendering_engine::SceneManager::GetRenderResourceContext ( ) const

Retrieves the current RenderResourceContext.

The RenderResourceContext provides references to shared caches (material, model, texture) and allows drawable objects to access resources during initialization and rendering.

Returns
A RenderResourceContext structure populated with shared cache pointers.

Definition at line 128 of file scene_manager.cpp.

129{
130 RenderResourceContext rrc;
131 rrc.renderer = mRenderer;
132 rrc.meshCache = mModelCache.get();
133 rrc.textureCache = mTextureCache.get();
134 rrc.materialCache = mMaterialCache.get();
135
136 return rrc;
137}

◆ Initialize()

void rendering_engine::SceneManager::Initialize ( )
virtual

Initializes the current scene and related caches.

Definition at line 25 of file scene_manager.cpp.

26{
27 // Apply pending registrations once (first initialization only)
28 static bool sRegistrationsApplied = false;
29 if (!sRegistrationsApplied)
30 {
31 auto& pending = GetPendingRegistrations();
32 for (auto& entry : pending)
33 {
34 RegisterScene(entry.first, entry.second);
35 }
36 pending.clear();
37 sRegistrationsApplied = true;
38 }
39 // Innitialize resources in next order.
40 // 1. Textures
41 // 2. Models
42 // 3. Materials
43 mTextureCache = std::make_shared<TextureCache>(mRenderer);
44 mModelCache = std::make_shared<ModelCache>(mRenderer);
45 const auto modelsFolder = Utility::GetModelsFolderPath();
46 mModelCache->CreateQuad2D();
47
49 {
50 mTextureCache->LoadTexturesFromPackage();
51 mModelCache->LoadModelsFromPackage();
52 }
53 else
54 {
55 const auto textureFolder = Utility::GetTextureFolderPath();
56 mTextureCache->LoadTexturesFromFolder(textureFolder.string());
57 mModelCache->LoadModelsFromFolder(modelsFolder.string());
58 }
59 mMaterialCache = std::make_shared<MaterialCache>(mRenderer);
60 mMaterialCache->CreateBuildInMaterials();
61
62 if(!GetMap().empty())
63 {
64 const std::string startScene = sStartSceneName;
65
66 if(!startScene.empty())
67 {
68 LoadScene(startScene);
69 }
70 }
71}
static bool RegisterScene(const std::string &name, Factory factory)
Registers a scene type with a name string.
static std::vector< std::pair< std::string, Factory > > & GetPendingRegistrations()
Type alias for the factory used to create scenes.
void LoadScene(std::string sceneName)
Loads a new scene by name.
static boost::filesystem::path GetTextureFolderPath()
Returns absolute path to Content/Textures.
Definition utility.cpp:192
static boost::filesystem::path GetModelsFolderPath()
Returns absolute path to Content/Models.
Definition utility.cpp:197
static bool IsPackageProvided()
Checks whether packed assets (Pack.bin / Pack.json) exist.
Definition utility.cpp:212

◆ LoadScene()

void rendering_engine::SceneManager::LoadScene ( std::string sceneName)

Loads a new scene by name.

Parameters
sceneNameThe name of the registered scene to load.

If the scene has been registered via SceneAutoRegistrar, it will be instantiated and prepared for initialization on the next update.

Definition at line 123 of file scene_manager.cpp.

124{
125 mNextScene = CreateScene(sceneName, *this);
126}
static std::unique_ptr< Scene > CreateScene(const std::string &name, SceneManager &sm)
Creates a scene instance by its registered name.

◆ RegisterScene()

bool rendering_engine::SceneManager::RegisterScene ( const std::string & name,
Factory factory )
static

Registers a scene type with a name string.

Parameters
nameUnique string identifier for the scene.
factoryFunction that constructs the scene when requested.
Returns
True if registration succeeded, false if a scene with the same name already exists.
Note
Typically used via the REG_SCENE() macro.

Definition at line 139 of file scene_manager.cpp.

140{
141 auto& map = GetMap();
142 return map.emplace(name, std::move(factory)).second;
143}

◆ Shutdown()

void rendering_engine::SceneManager::Shutdown ( )
virtual

Releases all scene-related resources and shuts down the manager.

Definition at line 101 of file scene_manager.cpp.

102{
103 if (mCurrentScene)
104 {
105 mCurrentScene->Shutdown();
106 }
107 mMaterialCache->ReleaseAll();
108 mModelCache->ReleaseAll();
109 mTextureCache->ReleaseAll();
110}

◆ Update()

void rendering_engine::SceneManager::Update ( float deltaTime)
virtual

Updates the currently active scene.

Parameters
deltaTimeTime elapsed since the previous frame, in milliseconds.

Definition at line 73 of file scene_manager.cpp.

74{
75 if (mNextScene)
76 {
77 if (mCurrentScene)
78 {
79 mCurrentScene->Shutdown();
80 }
81
82 mCurrentScene = std::move(mNextScene);
83 mCurrentScene->Initialize();
84 mNextScene = nullptr;
85 }
86
87 if (mCurrentScene)
88 {
89 mCurrentScene->Update(deltaTime);
90 }
91}

Member Data Documentation

◆ sStartSceneName

std::string rendering_engine::SceneManager::sStartSceneName
inlinestatic

Definition at line 126 of file scene_manager.hpp.


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