diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-23 19:08:02 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:59 +0200 |
commit | c9297a82291882e4043ae5e0de2e631940e96b52 (patch) | |
tree | 77caa40174ebef3b77ff81a404930d18e8ac46ef /src/game/game.cpp | |
parent | 18e1db1fb8692752f64d3912c3b5ff1818be9028 (diff) |
feat: add incrementing generation
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r-- | src/game/game.cpp | 28 |
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 |