aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-22 21:32:16 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:59 +0200
commitb1183c712d94d38f75068bd62df006f73bd3550f (patch)
treeb940c2277bb21d358dd1dcfeb5d1e7cfb5cb3cdc /src/game
parentc05b299e016ea55fa21538e6bee1e913221a650d (diff)
feat: add update speed monitoring
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cpp18
-rw-r--r--src/game/game.hpp3
-rw-r--r--src/game/status_manager.cpp4
3 files changed, 22 insertions, 3 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 18db133..b9f5e3a 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -7,6 +7,7 @@
#include <fmt/core.h>
+#include <chrono>
#include <iostream>
#include <utility>
@@ -35,6 +36,7 @@ void Game::on_start() noexcept
_status_manager->set_section_title(StatusLineSection::C, "Y: ");
_status_manager->set_section_title(StatusLineSection::D, "Paused: ");
_status_manager->set_section_title(StatusLineSection::E, "Generation: ");
+ _status_manager->set_section_title(StatusLineSection::F, "Time since last frame: ");
std::shared_ptr<ISubscriber<Vector2>> vector2_statusline_subscriber_adapter =
_vector2_statusline_subscriber_adapter_factory(
@@ -66,9 +68,23 @@ void Game::on_start() noexcept
_generation_tracker->get_is_paused() ? "yes" : "no");
_status_manager->set_section_body(StatusLineSection::E, "0");
+
+ _status_manager->set_section_body(StatusLineSection::F, "0");
+
+ _last_update_time = std::chrono::system_clock::now();
}
-void Game::on_update() noexcept {}
+void Game::on_update() noexcept
+{
+ const auto time_since_last_update =
+ std::chrono::system_clock::now() - _last_update_time;
+
+ _status_manager->set_section_body(
+ StatusLineSection::F,
+ fmt::format("{} nanoseconds", time_since_last_update.count()));
+
+ _last_update_time = std::chrono::system_clock::now();
+}
void Game::on_exit() const noexcept
{
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 1546a9c..fb2ad63 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -7,6 +7,7 @@
#include "interfaces/status_manager.hpp"
#include "interfaces/statusline_subscriber_adapter.hpp"
+#include <chrono>
#include <memory>
class Game : public IGame
@@ -36,4 +37,6 @@ private:
std::shared_ptr<IStatusManager> _status_manager;
IStatusLineSubscriberAdapterFactory<Vector2>
_vector2_statusline_subscriber_adapter_factory;
+
+ std::chrono::system_clock::time_point _last_update_time;
};
diff --git a/src/game/status_manager.cpp b/src/game/status_manager.cpp
index 1a709d3..33174d1 100644
--- a/src/game/status_manager.cpp
+++ b/src/game/status_manager.cpp
@@ -16,8 +16,8 @@ void StatusManager::initialize() noexcept
_statusline->set_section_length(StatusLineSection::B, 15U);
_statusline->set_section_length(StatusLineSection::C, 15U);
_statusline->set_section_length(StatusLineSection::D, 20U);
- _statusline->set_section_length(StatusLineSection::E, 15U);
- _statusline->set_section_length(StatusLineSection::F, 15U);
+ _statusline->set_section_length(StatusLineSection::E, 25U);
+ _statusline->set_section_length(StatusLineSection::F, 50U);
_statusline->initialize_background();
}