54 throw std::runtime_error(
"The Application is already running!");
62 if (!wStr.empty())
try {
width = std::stoi(wStr); }
catch (...) {}
63 if (!hStr.empty())
try {
height = std::stoi(hStr); }
catch (...) {}
69 std::replace(title.begin(), title.end(),
'_',
' ');
70 Specification.Name = title;
78 if (!rendererArg.empty()) {
90 catch (std::exception& e) {
108 if (renderer) renderer->WaitIdle();
114 m_benchmark =
nullptr;
115 delete m_DebugOverlay;
116 m_DebugOverlay =
nullptr;
123 SLEAK_LOG(
"The application has been successfully closed, have a good day sir");
129 float lastTime = FrameTimer.Elapsed();
131 if(CoreWindow && CoreWindow->InitializeWindow()) {
133 if(renderer && renderer->Initialize()) {
135 renderer->CreateImGUI();
136 if (renderer->GetImGUIEnabled())
137 CoreWindow->SetImGuiReady(
true);
140 m_DebugOverlay->Initialize(renderer, game);
143 m_benchmark->Initialize(renderer);
145 auto& cfg = m_DebugOverlay->GetConfig();
146 cfg.ShowCameraPanel =
false;
147 cfg.ShowPerformancePanel =
false;
150 auto context = renderer->GetContext();
153 float lastTime = FrameTimer.Elapsed();
154 float accumulator = 0.0f;
155 const float fixedTimestep = 1.0f / 60.0f;
159 if (!Game->Initialize()) {
172 if (!msaaStr.empty()) {
173 try { renderer->SetMSAASampleCount(
174 static_cast<uint32_t
>(std::stoi(msaaStr))); }
184 m_benchmark->ToggleRecording();
187 while(!CoreWindow->ShouldClose()) {
189 float currentTime = FrameTimer.Elapsed();
190 DeltaTime = currentTime - lastTime;
191 lastTime = currentTime;
193 #if defined(_DEBUG) && defined(COUNT_FRAME)
197 CoreWindow->Update();
200 if (m_pendingResize) {
201 renderer->Resize(m_pendingResizeW, m_pendingResizeH);
202 width =
static_cast<int>(m_pendingResizeW);
203 height =
static_cast<int>(m_pendingResizeH);
204 m_pendingResize =
false;
209 if (Game && Game->GetActiveScene()) {
210 if (
auto* cam = Game->GetActiveScene()->GetActiveCamera())
211 cam->OnResize(m_pendingResizeW, m_pendingResizeH);
215 renderer->BeginRender();
218 if (Game && Game->GetActiveScene()) {
219 auto* activeScene = Game->GetActiveScene();
222 accumulator += DeltaTime;
223 while (accumulator >= fixedTimestep) {
224 activeScene->FixedUpdate(fixedTimestep);
225 accumulator -= fixedTimestep;
229 activeScene->Update(DeltaTime);
232 activeScene->LateUpdate(DeltaTime);
237 Game->Loop(DeltaTime);
239 m_DebugOverlay->Render(DeltaTime);
242 m_benchmark->Tick(DeltaTime);
244 renderer->FlushPendingTransfers();
246 if (queue && context)
247 queue->ExecuteCommands(context);
249 renderer->EndRender();
270 m_pendingResize =
true;
276 if (w > 0 && h > 0) {
277 m_pendingResizeW =
static_cast<uint32_t
>(w);
278 m_pendingResizeH =
static_cast<uint32_t
>(h);
279 m_pendingResize =
true;
312 if (Game && Game->GetActiveScene()) {
313 Camera* cam = Game->GetActiveScene()->GetActiveCamera();
317 fpc->SetEnabled(!fpc->IsEnabled());
329 CoreWindow->ToggleFullScreen();
334 m_benchmark->ToggleRecording();
350 if (renderer) renderer->WaitIdle();
362 CoreWindow->SetRelativeMouseMode(enabled);
374 switch (renderer->GetType()) {
379 default: r = 0.5f; g = 0.5f; b = 0.5f;
break;
414 m_graphicsConfig = cfg;
417 renderer->SetSSAOBias(cfg.
ssaoBias);
427 renderer->SetExposure(cfg.
exposure);
428 renderer->SetGamma(cfg.
gamma);
433 return m_graphicsConfig;
437 return renderer->GetFeatureCaps();
Application(const char *ProjectName)
void SetVSync(bool enabled)
uint32_t GetMSAASampleCount() const
void OnWindowResize(const Sleak::Events::WindowResizeEvent &e)
Stashes the new size; the resize is applied at the start of the next frame.
void SetSSAOPower(float power)
void SetSSREnabled(bool enabled)
int GetFPS() const
Frames rendered in the last second.
void SetBloomEnabled(bool enabled)
void onMouseClick(const Sleak::Events::Input::MouseButtonPressedEvent &e)
void OnKeyPressed(const Sleak::Events::Input::KeyPressedEvent &e)
Handles engine-level hotkeys (F9 camera toggle, F11 fullscreen, F12 benchmark, Esc).
bool IsBloomEnabled() const
void SetIBLEnabled(bool enabled)
void SetIBLIntensity(float intensity)
const char * GetRendererTypeStr() const
Human-readable name of the active backend (e.g. "Vulkan").
float GetIBLIntensity() const
void OnWindowFullScreen(const Sleak::Events::WindowFullScreen &e)
Treats entering/leaving fullscreen as a resize to the current window size.
int GetVertices() const
Vertices submitted in the last frame.
void SetSSAORadius(float radius)
void SetMSAASampleCount(uint32_t samples)
size_t GetGPUMemoryBudget() const
void onMouseMove(const Sleak::Events::Input::MouseMovedEvent &e)
float GetFrameTime() const
Duration of the last frame, in seconds.
const GraphicsConfig & GetGraphicsConfig() const
Config last passed to ApplyGraphicsConfig().
void GetRendererTypeColor(float &r, float &g, float &b) const
UI accent color associated with the active backend.
bool IsSSAOEnabled() const
void WaitGPUIdle()
Blocks until the GPU finishes all in-flight work. Call before tearing down scene resources.
void ApplyGraphicsConfig(const GraphicsConfig &cfg)
Pushes every field of cfg onto the active renderer in one call.
float GetSSAORadius() const
void SetSSAOBias(float bias)
void SetMouseRelativeMode(bool enabled)
size_t GetGPUMemoryUsed() const
bool IsIBLEnabled() const
int GetTriangles() const
Triangles submitted in the last frame.
bool IsSSREnabled() const
int Run(GameBase *game)
Drives the game loop until the window closes; returns the process exit code.
float GetSSAOPower() const
void SetCursorVisible(bool visible)
uint32_t GetGraphicsCaps() const
float GetSSAOBias() const
uint32_t GetMaxMSAASampleCount() const
bool IsTAAEnabled() const
void SetTAAEnabled(bool enabled)
void SetSSAOEnabled(bool enabled)
static std::string GetValue(const std::string &flag, const std::string &defaultVal="")
Returns the raw string value stored for -flag, or defaultVal if it was not passed.
static bool HasFlag(const std::string &flag)
True if --flag was present on the command line.
static std::string RegisterEventHandler(T *instance, void(T::*memberFunction)(const EventT &))
Registers a member-function handler bound to instance, returning an ID for later unregistration.
uint16_t GetHeight() const
uint16_t GetWidth() const
void SetEnabled(bool enabled) override
Toggles relative mouse mode and, when re-enabling, resets velocity and re-syncs yaw/pitch.
T * GetComponent()
Finds the first attached component of type T, or nullptr.
static void Shutdown()
Release static resources before renderer cleanup.
static RenderCommandQueue * GetInstance()
Lazily creates and returns the process-wide singleton instance.
static Renderer * ParseArg(std::string arg, Window *window)
Resolves a CLI backend name (e.g. "-vulkan") to a Renderer instance.
static Renderer * CreateRenderer(RendererType type, Window *window)
Instantiates and returns the Renderer for the given backend, bound to a window.
RAII stopwatch: logs elapsed time on destruction under the given name.
void Close()
Marks the window for close; actual teardown happens in the destructor.
Vectors, matrices, quaternions, colors, AABBs, and random helpers.
ENGINE_API void ShutdownTextureCache()
Root namespace for everything the engine exposes.
uint32_t shadowMapResolution