From ba97aebf3ecc4960674caf59b86c6c3d683e3f25 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sun, 27 Aug 2023 19:58:15 -0400 Subject: [PATCH] Showing FPS on title bar (GameEngine) --- src/GameEngine.cpp | 6 +++++- src/GameEngine.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/GameEngine.cpp b/src/GameEngine.cpp index f023a17..5fa7861 100644 --- a/src/GameEngine.cpp +++ b/src/GameEngine.cpp @@ -11,7 +11,8 @@ GameEngine::GameEngine() { Resources::font.loadFromFile("./assets/JetbrainsMono.ttf"); Resources::game = this; - window.create(sf::VideoMode(1024, 768), "McRogueFace - r/RoguelikeDev Tutorial Run"); + window_title = "McRogueFace - r/RoguelikeDev Tutorial Run"; + window.create(sf::VideoMode(1024, 768), window_title); visible = window.getDefaultView(); window.setFramerateLimit(30); scene = "uitest"; @@ -44,6 +45,7 @@ sf::RenderWindow & GameEngine::getWindow() { return window; } void GameEngine::run() { + float fps = 0.0; clock.restart(); while (running) { @@ -55,6 +57,8 @@ void GameEngine::run() currentScene()->sRender(); currentFrame++; frameTime = clock.restart().asSeconds(); + fps = 1 / frameTime; + window.setTitle(window_title + " " + std::to_string(fps) + " FPS"); } } diff --git a/src/GameEngine.h b/src/GameEngine.h index 35e479a..cce4d3c 100644 --- a/src/GameEngine.h +++ b/src/GameEngine.h @@ -19,6 +19,7 @@ class GameEngine sf::View visible; sf::Clock clock; float frameTime; + std::string window_title; public: GameEngine();