Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
core_application.cpp
Go to the documentation of this file.
3#include "vulkan_renderer.hpp"
4#include "app_clock.hpp"
5#include "app_time.hpp"
6#include "scene_manager.hpp"
7#include "utility.hpp"
8
9#include <exception>
10
11namespace rendering_engine
12{
14 :
15 mAppTime(std::make_shared<AppTime>()),
16 mWindowSystem{ nullptr },
17 mRenderer{ nullptr }
18{
20
21 mAppName = appConfig.appName.c_str();
22 bIsFullScreen = appConfig.isFullScreen;
23 mWidth = static_cast<unsigned int>(appConfig.screenWidth);
24 mHeight = static_cast<unsigned int>(appConfig.screenHeight);
25}
27 :
28 bIsFullScreen{true},
29 mAppName(appName),
30 mAppTime(std::make_shared<AppTime>()),
31 mWindowSystem{nullptr},
32 mRenderer{nullptr}
33{
34}
35
36CoreApplication::CoreApplication(unsigned int width, unsigned int height, char const* appName)
37 :
38 bIsFullScreen{false},
39 mWidth{width},
40 mHeight{height},
41 mAppName(appName),
42 mAppTime(std::make_shared<AppTime>()),
43 mWindowSystem{ nullptr },
44 mRenderer{ nullptr }
45{
46}
47
49 unsigned int height,
50 char const* appName,
51 std::shared_ptr<IWindowSystem> windowSystem,
52 std::shared_ptr<IRenderer> renderer)
53 :
54 bIsFullScreen{ false },
55 mWidth{ width },
56 mHeight{ height },
57 mAppName(appName),
58 mAppTime(std::make_shared<AppTime>()),
59 mWindowSystem{ windowSystem },
60 mRenderer{ renderer }
61{}
62
64 std::shared_ptr<IWindowSystem> windowSystem,
65 std::shared_ptr<IRenderer> renderer)
66 :
67 bIsFullScreen{ true },
68 mWidth{ 0 },
69 mHeight{ 0 },
70 mAppName(appName),
71 mAppTime(std::make_shared<AppTime>()),
72 mWindowSystem{ windowSystem },
73 mRenderer{ renderer }
74{}
75
77
79{
80 if (!mWindowSystem)
81 {
82 mWindowSystem = std::make_shared<StandaloneDesktopWindow>(*this);
83 }
84 if (!mRenderer)
85 {
86 mRenderer = std::make_shared<VulkanRenderer>(*mWindowSystem.get());
87 }
88
89
90 mWindowSystem->CreateAppWindow(mWidth, mHeight, mAppName);
91 if (bIsFullScreen)
92 {
93 mWidth = mWindowSystem->GetFullScreenResolution().width;
94 mHeight = mWindowSystem->GetFullScreenResolution().height;
95 }
96 mRenderer->InitializeRenderer();
97
98 mSceneManager = std::make_shared<SceneManager>(mRenderer.get(), this);
99 mSceneManager->Initialize();
100}
101
103{
104 AppClock appClock;
105 appClock.Reset();
106
107 while (!mWindowSystem->ShouldClose())
108 {
109 appClock.UpdateAppTime(*mAppTime);
110 mWindowSystem->PollEvents();
111 Update(mAppTime->ElapsedAppTimeMilliseconds());
112 Draw();
113 }
114}
115
116void CoreApplication::Update(float deltaTime)
117{
118 if (mSceneManager)
119 {
120 mSceneManager->Update(deltaTime);
121 }
122}
123
125{
126 if (mRenderer->BeginFrame())
127 {
128 mRenderer->BeginRenderPass();
129 mSceneManager->Draw();
130 mRenderer->EndRenderPass();
131 mRenderer->EndFrame();
132 }
133}
134
136{
137 mRenderer->WaitIdle();
138 mSceneManager->Shutdown();
139 mRenderer->ShutdownRenderer();
140 mWindowSystem->Shutdown();
141}
142
144{
146 ss.name = mAppName;
148 ss.height = mHeight;
149 ss.width = mWidth;
150
151 return ss;
152}
153
154} // rendering_engine
High-resolution clock for updating application time.
Provides time tracking for the application runtime.
Provides high-resolution timing for frame updates.
Definition app_clock.hpp:50
void Reset()
Resets the clock to the current system time.
Definition app_clock.cpp:31
void UpdateAppTime(AppTime &appTime)
Updates the given AppTime instance with elapsed and total durations.
Definition app_clock.cpp:38
Manages current, total, and elapsed time for the application.
Definition app_time.hpp:36
std::shared_ptr< SceneManager > mSceneManager
CoreApplication()
Constructs a CoreApplication using settings from the config file.
ScreenSettings GetScreenSettings() const override
Retrieves the current screen or window settings.
std::shared_ptr< IWindowSystem > mWindowSystem
void Draw() override
Executes the rendering logic for the current frame.
void Shutdown() override
Performs cleanup and shuts down the application.
std::shared_ptr< AppTime > mAppTime
void Run() override
Runs the main application loop.
void Update(float deltaTime) override
Updates the application state.
std::shared_ptr< IRenderer > mRenderer
void Initialize() override
Initializes the application and its subsystems.
static AppConfig ReadConfigFile()
Reads application settings from the JSON config file.
Definition utility.cpp:32
Basic application settings loaded from a configuration file.
Definition utility.hpp:27
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
Describes window and display configuration for the application.
std::string name
The window or application name.
unsigned int width
Screen or window width in pixels.
unsigned int height
Screen or window height in pixels.
bool isFullScreen
Whether the application runs in fullscreen mode.