Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::CoreApplication Class Reference

Default implementation of the IApplication interface. More...

#include <core_application.hpp>

Inherits rendering_engine::IApplication.

Public Member Functions

 CoreApplication ()
 Constructs a CoreApplication using settings from the config file. More...
 
 CoreApplication (char const *appName)
 Constructs a CoreApplication with full-screen window size. More...
 
 CoreApplication (unsigned int width, unsigned int height, char const *appName)
 Constructs a CoreApplication with explicit window size. More...
 
 CoreApplication (unsigned int width, unsigned int height, char const *appName, std::shared_ptr< IWindowSystem > windowSystem, std::shared_ptr< IRenderer > renderer)
 Constructs a CoreApplication with injected subsystems. More...
 
 CoreApplication (char const *appName, std::shared_ptr< IWindowSystem > windowSystem, std::shared_ptr< IRenderer > renderer)
 Constructs a CoreApplication with custom systems but default window size. More...
 
virtual ~CoreApplication ()
 
void Initialize () override
 Initializes the application and its subsystems. More...
 
void Run () override
 Runs the main application loop. More...
 
void Update (float deltaTime) override
 Updates the application state. More...
 
void Draw () override
 Executes the rendering logic for the current frame. More...
 
void Shutdown () override
 Performs cleanup and shuts down the application. More...
 
ScreenSettings GetScreenSettings () const override
 Retrieves the current screen or window settings. More...
 
FrameMetrics GetFrameMetrics () const override
 Returns performance metrics of the last processed frame. More...
 
- Public Member Functions inherited from rendering_engine::IApplication
virtual void Initialize ()=0
 Initializes the application and its subsystems. More...
 
virtual void Run ()=0
 Runs the main application loop. More...
 
virtual void Update (float deltaTime)=0
 Updates the application state. More...
 
virtual void Draw ()=0
 Executes the rendering logic for the current frame. More...
 
virtual void Shutdown ()=0
 Performs cleanup and shuts down the application. More...
 
virtual ~IApplication ()=default
 Virtual destructor for safe polymorphic deletion. More...
 
virtual ScreenSettings GetScreenSettings () const =0
 Retrieves the current screen or window settings. More...
 
virtual FrameMetrics GetFrameMetrics () const =0
 Returns performance metrics of the last processed frame. More...
 

Protected Attributes

bool bIsFullScreen
 
unsigned int mWidth
 
unsigned int mHeight
 
std::string mAppName
 
AppConfig mAppConfig
 
FrameMetrics mFrameMetrics
 
std::shared_ptr< AppTimemAppTime
 
std::shared_ptr< IWindowSystemmWindowSystem
 
std::shared_ptr< IRenderermRenderer
 
std::shared_ptr< SceneManagermSceneManager
 

Detailed Description

Default implementation of the IApplication interface.

Coordinates the main execution flow of a rendering-based application, including initialization, update, rendering, and shutdown. It acts as the central manager that connects the renderer, window system, and scene management subsystems.

See also
IApplication
IWindowSystem
IRenderer

Definition at line 34 of file core_application.hpp.

Constructor & Destructor Documentation

◆ CoreApplication() [1/5]

rendering_engine::CoreApplication::CoreApplication ( )

Constructs a CoreApplication using settings from the config file.

Loads AppConfig and applies its values to window setup.

Definition at line 15 of file core_application.cpp.

16 :
17 mAppTime(std::make_shared<AppTime>()),
18 mWindowSystem{ nullptr },
19 mRenderer{ nullptr }
20{
22
23 mAppName = mAppConfig.appName.c_str();
25 mWidth = static_cast<unsigned int>(mAppConfig.screenWidth);
26 mHeight = static_cast<unsigned int>(mAppConfig.screenHeight);
27}
std::shared_ptr< IWindowSystem > mWindowSystem
std::shared_ptr< AppTime > mAppTime
std::shared_ptr< IRenderer > mRenderer
static AppConfig ReadConfigFile()
Reads application settings from the JSON config file.
Definition: utility.cpp:34
float screenWidth
Desired window width in pixels (ignored in full-screen mode).
Definition: utility.hpp:33
bool isFullScreen
Whether the application should start in full-screen mode.
Definition: utility.hpp:31
std::string appName
Name of the application.
Definition: utility.hpp:29
float screenHeight
Desired window height in pixels (ignored in full-screen mode).
Definition: utility.hpp:35

◆ CoreApplication() [2/5]

rendering_engine::CoreApplication::CoreApplication ( char const *  appName)

Constructs a CoreApplication with full-screen window size.

Parameters
appNameName of the application, used for window caption and logging.

Definition at line 28 of file core_application.cpp.

29 :
30 bIsFullScreen{true},
31 mAppName(appName),
32 mAppTime(std::make_shared<AppTime>()),
33 mWindowSystem{nullptr},
34 mRenderer{nullptr}
35{
37}

◆ CoreApplication() [3/5]

rendering_engine::CoreApplication::CoreApplication ( unsigned int  width,
unsigned int  height,
char const *  appName 
)

Constructs a CoreApplication with explicit window size.

Parameters
widthWindow width in pixels.
heightWindow height in pixels.
appNameName of the application.

Definition at line 39 of file core_application.cpp.

40 :
41 bIsFullScreen{false},
42 mWidth{width},
43 mHeight{height},
44 mAppName(appName),
45 mAppTime(std::make_shared<AppTime>()),
46 mWindowSystem{ nullptr },
47 mRenderer{ nullptr }
48{
50}

◆ CoreApplication() [4/5]

rendering_engine::CoreApplication::CoreApplication ( unsigned int  width,
unsigned int  height,
char const *  appName,
std::shared_ptr< IWindowSystem windowSystem,
std::shared_ptr< IRenderer renderer 
)

Constructs a CoreApplication with injected subsystems.

Parameters
widthWindow width in pixels.
heightWindow height in pixels.
appNameName of the application.
windowSystemShared pointer to a custom window system implementation.
rendererShared pointer to a custom renderer implementation.

Definition at line 52 of file core_application.cpp.

57 :
58 bIsFullScreen{ false },
59 mWidth{ width },
60 mHeight{ height },
61 mAppName(appName),
62 mAppTime(std::make_shared<AppTime>()),
63 mWindowSystem{ windowSystem },
64 mRenderer{ renderer }
65{
67}

◆ CoreApplication() [5/5]

rendering_engine::CoreApplication::CoreApplication ( char const *  appName,
std::shared_ptr< IWindowSystem windowSystem,
std::shared_ptr< IRenderer renderer 
)

Constructs a CoreApplication with custom systems but default window size.

Parameters
appNameName of the application.
windowSystemShared pointer to a custom window system implementation.
rendererShared pointer to a custom renderer implementation.

Definition at line 69 of file core_application.cpp.

72 :
73 bIsFullScreen{ true },
74 mWidth{ 0 },
75 mHeight{ 0 },
76 mAppName(appName),
77 mAppTime(std::make_shared<AppTime>()),
78 mWindowSystem{ windowSystem },
79 mRenderer{ renderer }
80{
82}

◆ ~CoreApplication()

rendering_engine::CoreApplication::~CoreApplication ( )
virtual

Definition at line 84 of file core_application.cpp.

84{};

Member Function Documentation

◆ Draw()

void rendering_engine::CoreApplication::Draw ( )
overridevirtual

Executes the rendering logic for the current frame.

Implements rendering_engine::IApplication.

Definition at line 217 of file core_application.cpp.

218{
219 if (mRenderer->BeginFrame())
220 {
221 mRenderer->BeginRenderPass();
222 mSceneManager->Draw();
223 mRenderer->EndRenderPass();
224 mRenderer->EndFrame();
225 }
226}
std::shared_ptr< SceneManager > mSceneManager

◆ GetFrameMetrics()

FrameMetrics rendering_engine::CoreApplication::GetFrameMetrics ( ) const
overridevirtual

Returns performance metrics of the last processed frame.

Returns
FrameMetrics structure containing timing and FPS data.

Implements rendering_engine::IApplication.

Definition at line 253 of file core_application.cpp.

254{
255 return mFrameMetrics;
256}

◆ GetScreenSettings()

ScreenSettings rendering_engine::CoreApplication::GetScreenSettings ( ) const
overridevirtual

Retrieves the current screen or window settings.

Returns
A structure describing screen configuration parameters.

Implements rendering_engine::IApplication.

Definition at line 242 of file core_application.cpp.

243{
244 ScreenSettings ss;
245 ss.name = mAppName;
246 ss.isFullScreen = bIsFullScreen;
247 ss.height = mHeight;
248 ss.width = mWidth;
249
250 return ss;
251}

◆ Initialize()

void rendering_engine::CoreApplication::Initialize ( )
overridevirtual

Initializes the application and its subsystems.

Implements rendering_engine::IApplication.

Definition at line 86 of file core_application.cpp.

87{
89
90 LOG_INFO("Initializing CoreApplication...");
91 LOG_INFO(std::string("Application name: ") + mAppName);
92
93 auto startTime = std::chrono::steady_clock::now();
94
95 if (!mWindowSystem)
96 {
97 LOG_DEBUG("Creating StandaloneDesktopWindow...");
98 mWindowSystem = std::make_shared<StandaloneDesktopWindow>(*this);
99 }
100 if (!mRenderer)
101 {
102 LOG_DEBUG("Creating VulkanRenderer...");
103 mRenderer = std::make_shared<VulkanRenderer>(*mWindowSystem.get());
104 }
105
106 LOG_INFO("Creating application window...");
107 mWindowSystem->CreateAppWindow(mWidth, mHeight, mAppName);
108 if (bIsFullScreen)
109 {
110 mWidth = mWindowSystem->GetFullScreenResolution().width;
111 mHeight = mWindowSystem->GetFullScreenResolution().height;
112
113 LOG_INFO("Fullscreen mode enabled. Resolution set to: "
114 + std::to_string(mWidth) + "x" + std::to_string(mHeight));
115 }
116 LOG_INFO("Initializing renderer...");
117 mRenderer->InitializeRenderer();
118
119 LOG_INFO("Initializing SceneManager...");
120 mSceneManager = std::make_shared<SceneManager>(mRenderer.get(), this);
121 mSceneManager->Initialize();
122
123 auto endTime = std::chrono::steady_clock::now();
124 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
125
126 LOG_INFO("CoreApplication initialized in " + std::to_string(duration) + " ms.");
127}
void Initialize(const std::string &appName)
Initializes logging system and creates a new log file.
Definition: logger.cpp:39
static Logger & Get()
Returns singleton logger instance.
Definition: logger.cpp:33
#define LOG_DEBUG(msg)
Definition: logger.hpp:38
#define LOG_INFO(msg)
Definition: logger.hpp:39

◆ Run()

void rendering_engine::CoreApplication::Run ( )
overridevirtual

Runs the main application loop.

Implements rendering_engine::IApplication.

Definition at line 129 of file core_application.cpp.

130{
131 LOG_INFO("Entering main loop.");
132
133 AppClock appClock;
134 appClock.Reset();
135
136 const float targetFrameTimeMs =
137 (mAppConfig.targetFPS > 0) ? (1000.0f / static_cast<float>(mAppConfig.targetFPS)) : 0.0f;
138
139 while (!mWindowSystem->ShouldClose())
140 {
141 const auto frameStart = std::chrono::steady_clock::now();
142
143 appClock.UpdateAppTime(*mAppTime);
144 mWindowSystem->PollEvents();
145
146 const auto updateStart = std::chrono::steady_clock::now();
147 Update(mAppTime->ElapsedAppTimeSeconds());
148 const auto updateEnd = std::chrono::steady_clock::now();
149
150 const auto drawStart = std::chrono::steady_clock::now();
151 Draw();
152 const auto drawEnd = std::chrono::steady_clock::now();
153
154 const auto frameEnd = std::chrono::steady_clock::now();
155
157 std::chrono::duration<float, std::milli>(updateEnd - updateStart).count();
159 std::chrono::duration<float, std::milli>(drawEnd - drawStart).count();
161 std::chrono::duration<float, std::milli>(frameEnd - frameStart).count();
162
163
164 // Frame pacing (sleep)
165 if (mAppConfig.targetFPS > 0)
166 {
167 const auto afterMetrics = std::chrono::steady_clock::now();
168
169 const float actualFrameTimeMs =
170 std::chrono::duration<float, std::milli>(afterMetrics - frameStart).count();
171
172 if (actualFrameTimeMs < targetFrameTimeMs)
173 {
174 const auto sleepDuration =
175 std::chrono::duration<float, std::milli>(
176 targetFrameTimeMs - actualFrameTimeMs);
177
178 std::this_thread::sleep_for(sleepDuration);
179 }
180 }
181
182 const auto frameEndTotal = std::chrono::steady_clock::now();
183 const auto frameLengthTotal = std::chrono::duration<float, std::milli>(frameEndTotal - frameStart).count();
184
186 {
187 mFrameMetrics.fpsRaw = 1000.0f / frameLengthTotal;
188
189 const float alpha = 0.1f;
190
191 if (mFrameMetrics.fpsSmoothed == 0.0f)
192 {
194 }
195 else
196 {
198 alpha * mFrameMetrics.fpsRaw +
199 (1.0f - alpha) * mFrameMetrics.fpsSmoothed;
200 }
201 }
202 }
203
204 LOG_INFO("Main loop exited.");
205
206 Shutdown();
207}
void Draw() override
Executes the rendering logic for the current frame.
void Shutdown() override
Performs cleanup and shuts down the application.
void Update(float deltaTime) override
Updates the application state.
float targetFPS
Target frame rate (0 = uncapped).
Definition: utility.hpp:45

◆ Shutdown()

void rendering_engine::CoreApplication::Shutdown ( )
overridevirtual

Performs cleanup and shuts down the application.

Implements rendering_engine::IApplication.

Definition at line 228 of file core_application.cpp.

229{
230 LOG_INFO("Shutting down CoreApplication...");
231 mRenderer->WaitIdle();
232 LOG_DEBUG("Shutting down SceneManager...");
233 mSceneManager->Shutdown();
234 LOG_DEBUG("Shutting down Renderer...");
235 mRenderer->ShutdownRenderer();
236 LOG_DEBUG("Shutting down WindowSystem...");
237 mWindowSystem->Shutdown();
238 LOG_INFO("CoreApplication shutdown complete.");
240}
void Shutdown()
Finalizes logging system and closes the log file.
Definition: logger.cpp:82

◆ Update()

void rendering_engine::CoreApplication::Update ( float  deltaTime)
overridevirtual

Updates the application state.

Parameters
deltaTimeTime elapsed since the previous frame, in milliseconds.

Implements rendering_engine::IApplication.

Definition at line 209 of file core_application.cpp.

210{
211 if (mSceneManager)
212 {
213 mSceneManager->Update(deltaTime);
214 }
215}

Member Data Documentation

◆ bIsFullScreen

bool rendering_engine::CoreApplication::bIsFullScreen
protected

Definition at line 97 of file core_application.hpp.

◆ mAppConfig

AppConfig rendering_engine::CoreApplication::mAppConfig
protected

Definition at line 101 of file core_application.hpp.

◆ mAppName

std::string rendering_engine::CoreApplication::mAppName
protected

Definition at line 100 of file core_application.hpp.

◆ mAppTime

std::shared_ptr<AppTime> rendering_engine::CoreApplication::mAppTime
protected

Definition at line 105 of file core_application.hpp.

◆ mFrameMetrics

FrameMetrics rendering_engine::CoreApplication::mFrameMetrics
protected

Definition at line 103 of file core_application.hpp.

◆ mHeight

unsigned int rendering_engine::CoreApplication::mHeight
protected

Definition at line 99 of file core_application.hpp.

◆ mRenderer

std::shared_ptr<IRenderer> rendering_engine::CoreApplication::mRenderer
protected

Definition at line 107 of file core_application.hpp.

◆ mSceneManager

std::shared_ptr<SceneManager> rendering_engine::CoreApplication::mSceneManager
protected

Definition at line 109 of file core_application.hpp.

◆ mWidth

unsigned int rendering_engine::CoreApplication::mWidth
protected

Definition at line 98 of file core_application.hpp.

◆ mWindowSystem

std::shared_ptr<IWindowSystem> rendering_engine::CoreApplication::mWindowSystem
protected

Definition at line 106 of file core_application.hpp.


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