From 00da4d690af08d45788d770f9aadc9548438f074 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 26 Sep 2019 10:38:12 -0400 Subject: made Config static; added fps measure/text --- src/engine.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/engine.cpp') diff --git a/src/engine.cpp b/src/engine.cpp index a000979..e53f266 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -36,6 +36,7 @@ #include +using namespace std::literals::string_literals; using namespace std::chrono_literals; namespace cr = std::chrono; typedef std::chrono::high_resolution_clock mc; @@ -137,17 +138,20 @@ void Engine::physicsLoop(void) } } -void Engine::renderLoop(void) +void Engine::renderLoop(int& fpsCounter) { entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */ while (shouldRun()) { systems.update(dt); systems.update(dt); + fpsCounter++; } } void Engine::run(void) { + int fpsCounter = 0; + // Start logic thread logicThread = std::thread([this](void) { logicLoop(); @@ -157,12 +161,22 @@ void Engine::run(void) physicsLoop(); }); + debugThread = std::thread([this, &fpsCounter](void) { + while (shouldRun()) { + std::this_thread::sleep_for(1s); + fps = fpsCounter; + fpsCounter = 0; + systems.system()->put("default", 0, 0, "fps: "s + std::to_string(fps)); + } + }); + // Keep render loop on main thread - renderLoop(); + renderLoop(fpsCounter); // Done, bring logic thread back logicThread.join(); physicsThread.join(); + debugThread.join(); // Save the entities' data GameState::save("save.json", entities); -- cgit v1.2.3