21 mSceneManager(sceneManager),
22 mStatsOverlay(nullptr)
27 mActiveCamera3D = std::make_shared<Camera>(*mSceneManager.
GetApplication());
28 mActiveCamera3D->Initialize();
30 mActiveCamera2D = std::make_shared<Camera2D>(*mSceneManager.
GetApplication());
31 mActiveCamera2D->Initialize();
36 mStatsOverlay = SpawnActor2D<StatsOverlay>();
39 const float x = screenWidth / 2 - 200.0f;
40 const float y = -screenHeight / 2 + 130.0f;
50 mActiveCamera2D->Update(deltaTime);
58 for (
auto& actor : mActors)
60 if (!actor->IsPendingDestroy())
62 actor->Update(deltaTime);
65 for (
auto& actor2D : mActors2D)
67 if (!actor2D->IsPendingDestroy())
69 actor2D->Update(deltaTime);
73 for (
auto& drawable2D : mDrawables2D)
75 drawable2D->Update(deltaTime);
77 for (
auto& drawable3D : mDrawables3D)
79 drawable3D->Update(deltaTime);
89 for (
auto& drawable3D : mDrawables3D)
91 drawable3D->Draw(*mActiveCamera3D);
97 for (
auto& drawable2D : mDrawables2D)
99 drawable2D->Draw(*mActiveCamera2D);
110 for (
auto* d : mDrawables2D) {
if (d) { d->Shutdown();
delete d; } }
111 mDrawables2D.clear();
113 for (
auto* d : mDrawables3D) {
if (d) { d->Shutdown();
delete d; } }
114 mDrawables3D.clear();
117 for (
auto* a : mActors) {
if (a) { a->Shutdown();
delete a; } }
120 for (
auto* a : mActors2D) {
if (a) { a->Shutdown();
delete a; } }
123 mPendingDestroy2D.clear();
124 mPendingDestroy3D.clear();
125 mPendingDestroyActors.clear();
126 mPendingDestroyActors2D.clear();
131 return mSceneManager;
141 return mActiveCamera3D;
146 return mActiveCamera2D;
151 mPendingDestroy3D.push_back(drawable3D);
156 mPendingDestroy2D.push_back(drawable2D);
161 mPendingDestroyActors.push_back(actor);
166 mPendingDestroyActors2D.push_back(actor2D);
169void Scene::FlushDestroyed()
171 for (
auto* d : mPendingDestroy3D)
173 auto it = std::find(mDrawables3D.begin(), mDrawables3D.end(), d);
174 if (it != mDrawables3D.end())
178 mDrawables3D.erase(it);
181 mPendingDestroy3D.clear();
183 for (
auto* d : mPendingDestroy2D)
185 auto it = std::find(mDrawables2D.begin(), mDrawables2D.end(), d);
186 if (it != mDrawables2D.end())
190 mDrawables2D.erase(it);
193 mPendingDestroy2D.clear();
195 for (
auto* actor : mPendingDestroyActors)
197 auto it = std::find(mActors.begin(), mActors.end(), actor);
198 if (it != mActors.end())
205 mPendingDestroyActors.clear();
207 for (
auto* actor2D : mPendingDestroyActors2D)
209 auto it = std::find(mActors2D.begin(), mActors2D.end(), actor2D);
210 if (it != mActors2D.end())
217 mPendingDestroyActors2D.clear();
Base class representing a 2D entity within a Scene.
void SetPosition(const glm::vec2 &position)
Sets the actor's position in world space.
Base class representing a 3D entity within a Scene.
2D drawable component for rendering objects in 2D space.
3D drawable component for rendering objects in 3D space.
virtual ScreenSettings GetScreenSettings() const =0
Retrieves the current screen or window settings.
virtual void SetDefaultColor(float r, float g, float b)=0
Sets the renderer clear color.
Manages scenes, resource caches, and scene transitions within the rendering engine.
IApplication * GetApplication()
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.
void SetBackgroundColor(glm::vec3 color)
Sets the scene background clear color.
virtual void Shutdown()
Releases scene-specific resources and prepares for shutdown.
std::shared_ptr< Camera2D > GetActiveCamera2D()
Returns the active 2D camera of the scene.
virtual void Update(float deltaTime)
Updates all objects within the scene.
void DestroyDrawable3D(Drawable3D *drawable3D)
Schedules a 3D drawable for deferred destruction.
void LoadScene(std::string newSceneName)
Requests to load another scene.
SceneManager & GetSceneManager()
Gets a reference to the SceneManager that owns this scene.
void DestroyActor(Actor *actor)
Schedules a 3D actor for deferred destruction.
std::shared_ptr< Camera > GetActiveCamera3D()
Returns the active 3D camera of the scene.
void DestroyDrawable2D(Drawable2D *drawable2D)
Schedules a 2D drawable for deferred destruction.
virtual void Initialize()
Initializes scene resources and drawables.
Scene(SceneManager &sceneManager)
Constructs a Scene instance associated with a SceneManager.
virtual void Draw()
Renders all 3D and 2D drawables in the scene.
static AppConfig ReadConfigFile()
Reads application settings from the JSON config file.
Engine-wide logging system for runtime diagnostics and performance tracking.
Basic application settings loaded from a configuration file.
bool showStatsOverlay
Enable on-screen statistics overlay.
unsigned int width
Screen or window width in pixels.
unsigned int height
Screen or window height in pixels.