aboutsummaryrefslogtreecommitdiff
path: root/src/game/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r--src/game/game.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index c41364a..de2b4df 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -16,7 +16,8 @@ Game::Game(
_cursor_controller(std::move(cursor_controller)),
_generation_tracker(std::move(generation_tracker)),
_status_manager(std::move(status_manager)),
- _user_input_observer(std::move(user_input_observer))
+ _user_input_observer(std::move(user_input_observer)),
+ _gen_update_speed_millis(1000)
{
}
@@ -129,14 +130,33 @@ void Game::on_update() noexcept
_status_manager->set_section_body(StatusLineSection::D, onoff ? "yes" : "no");
}
- const auto time_since_last_update =
- std::chrono::system_clock::now() - _last_update_time;
+ const auto time_now = std::chrono::system_clock::now();
+
+ const auto time_since_last_update = time_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();
+ const auto time_since_last_gen_update =
+ std::chrono::duration_cast<std::chrono::milliseconds>(
+ time_now - _last_gen_update_time);
+
+ if (!_generation_tracker->get_is_paused() &&
+ time_since_last_gen_update.count() > _gen_update_speed_millis)
+ {
+ const auto new_current_gen = _generation_tracker->get_current_generation() + 1U;
+
+ _generation_tracker->set_current_generation(new_current_gen);
+
+ _status_manager->set_section_body(
+ StatusLineSection::E,
+ fmt::format("{}", new_current_gen));
+
+ _last_gen_update_time = time_now;
+ }
+
+ _last_update_time = time_now;
}
void Game::on_exit() const noexcept