From 3a22a3746f6c63c9f47b01f2cb07aa23efd938c8 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Mon, 16 Mar 2026 11:41:25 +0100 Subject: [PATCH] deltatime window --- include/game/gamemanager.hpp | 2 ++ src/game/gamemanager.cpp | 2 ++ src/window/window.cpp | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/game/gamemanager.hpp b/include/game/gamemanager.hpp index 900a298..b54515d 100644 --- a/include/game/gamemanager.hpp +++ b/include/game/gamemanager.hpp @@ -25,6 +25,7 @@ namespace Game { void run(std::stop_token stopToken); void setTargetUpdatesPerSecond(int target) { mTargetUpdatesPerSecond = target; } int getTargetUpdatesPerSecond() { return mTargetUpdatesPerSecond; } + float getLastDelta() { return mLastDelta; } static void setSharedData(const std::string& key, std::string data); static std::string getSharedData(const std::string& key); @@ -34,5 +35,6 @@ namespace Game { int mTargetUpdatesPerSecond = TARGET_UPDATE_RATE; clock::time_point mLastUpdate; static std::unordered_map mSharedStrings; + float mLastDelta = 0.f; }; } \ No newline at end of file diff --git a/src/game/gamemanager.cpp b/src/game/gamemanager.cpp index 8cf2794..279f4e3 100644 --- a/src/game/gamemanager.cpp +++ b/src/game/gamemanager.cpp @@ -30,6 +30,8 @@ namespace Game { ERROR("Exception in GameManager thread: " << e.what()); } + mLastDelta = seconds; + mLastUpdate = now; const auto elapsed = std::chrono::steady_clock::now() - frameStart; diff --git a/src/window/window.cpp b/src/window/window.cpp index 9150513..620f17e 100644 --- a/src/window/window.cpp +++ b/src/window/window.cpp @@ -98,7 +98,8 @@ namespace Game::Window { auto elapsed = std::chrono::duration_cast(now - mLastFPSTime).count(); if (elapsed >= 1) { int fps = static_cast(mFrameCount / elapsed); - SDL_SetWindowTitle(mWindow, ("Game Window - FPS: " + std::to_string(fps)).c_str()); + std::string title = "Game Window - FPS: " + std::to_string(fps) + " : Update Time: " + std::to_string(mGameManager.getLastDelta()); + SDL_SetWindowTitle(mWindow, title.c_str()); mFrameCount = 0; mLastFPSTime = now; }