deltatime window
This commit is contained in:
@@ -25,6 +25,7 @@ namespace Game {
|
|||||||
void run(std::stop_token stopToken);
|
void run(std::stop_token stopToken);
|
||||||
void setTargetUpdatesPerSecond(int target) { mTargetUpdatesPerSecond = target; }
|
void setTargetUpdatesPerSecond(int target) { mTargetUpdatesPerSecond = target; }
|
||||||
int getTargetUpdatesPerSecond() { return mTargetUpdatesPerSecond; }
|
int getTargetUpdatesPerSecond() { return mTargetUpdatesPerSecond; }
|
||||||
|
float getLastDelta() { return mLastDelta; }
|
||||||
|
|
||||||
static void setSharedData(const std::string& key, std::string data);
|
static void setSharedData(const std::string& key, std::string data);
|
||||||
static std::string getSharedData(const std::string& key);
|
static std::string getSharedData(const std::string& key);
|
||||||
@@ -34,5 +35,6 @@ namespace Game {
|
|||||||
int mTargetUpdatesPerSecond = TARGET_UPDATE_RATE;
|
int mTargetUpdatesPerSecond = TARGET_UPDATE_RATE;
|
||||||
clock::time_point mLastUpdate;
|
clock::time_point mLastUpdate;
|
||||||
static std::unordered_map<std::string, std::string> mSharedStrings;
|
static std::unordered_map<std::string, std::string> mSharedStrings;
|
||||||
|
float mLastDelta = 0.f;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,8 @@ namespace Game {
|
|||||||
ERROR("Exception in GameManager thread: " << e.what());
|
ERROR("Exception in GameManager thread: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mLastDelta = seconds;
|
||||||
|
|
||||||
mLastUpdate = now;
|
mLastUpdate = now;
|
||||||
|
|
||||||
const auto elapsed = std::chrono::steady_clock::now() - frameStart;
|
const auto elapsed = std::chrono::steady_clock::now() - frameStart;
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ namespace Game::Window {
|
|||||||
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - mLastFPSTime).count();
|
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - mLastFPSTime).count();
|
||||||
if (elapsed >= 1) {
|
if (elapsed >= 1) {
|
||||||
int fps = static_cast<int>(mFrameCount / elapsed);
|
int fps = static_cast<int>(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;
|
mFrameCount = 0;
|
||||||
mLastFPSTime = now;
|
mLastFPSTime = now;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user