aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-12 14:26:04 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:57:01 +0200
commite0021112e98639baeee0aae3a483bb725cc99d57 (patch)
tree9e272bb0366099a241107c23a95e0f61faba6418 /src/game
parent09ebfa21311e9e8bcf24bb59784574ede0557ef4 (diff)
refactor: clarify generation speed in statusline
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cpp17
-rw-r--r--src/game/game.hpp9
-rw-r--r--src/game/status_manager.cpp2
3 files changed, 15 insertions, 13 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index f0df83b..893be97 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -58,9 +58,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,
- "Minimum time since last generation: ");
+ _status_manager->set_section_title(StatusLineSection::F, "Generation speed: ");
_status_manager->set_section_title(StatusLineSection::G, "Living cells: ");
_status_manager->set_section_title(StatusLineSection::H, "Window size: ");
@@ -297,14 +295,17 @@ void Game::_on_normal_mode_update() noexcept
break;
case '+':
- if (_min_time_since_last_gen_millis > 0)
+ if (_generations_per_second < MAXIMUM_GENERATIONS_PER_SECOND)
{
- _min_time_since_last_gen_millis -= MIN_TIME_SINCE_LAST_GEN_INCREMENT;
+ _generations_per_second++;
}
break;
case '-':
- _min_time_since_last_gen_millis += MIN_TIME_SINCE_LAST_GEN_DECREMENT;
+ if (_generations_per_second > 1)
+ {
+ _generations_per_second--;
+ }
break;
default:
@@ -326,7 +327,7 @@ void Game::_on_normal_mode_update() noexcept
_status_manager->set_section_body(
StatusLineSection::F,
- fmt::format("{} milliseconds", _min_time_since_last_gen_millis));
+ fmt::format("{}/s", _generations_per_second));
_status_manager->set_section_body(
StatusLineSection::G,
@@ -343,7 +344,7 @@ void Game::_on_normal_mode_update() noexcept
std::chrono::duration_cast<std::chrono::milliseconds>(
time_now - _last_gen_update_time);
- if (time_since_last_gen.count() <= _min_time_since_last_gen_millis)
+ if (time_since_last_gen.count() <= MILLIS_IN_SECOND / _generations_per_second)
{
return;
}
diff --git a/src/game/game.hpp b/src/game/game.hpp
index abee6ec..09a9ee0 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -23,10 +23,11 @@
#include <string_view>
#include <vector>
-constexpr auto DEFAULT_MIN_TIME_SINCE_LAST_GEN_MILLIS = 200;
+constexpr auto DEFAULT_GENERATIONS_PER_SECOND = 5L;
-constexpr auto MIN_TIME_SINCE_LAST_GEN_INCREMENT = 50;
-constexpr auto MIN_TIME_SINCE_LAST_GEN_DECREMENT = 50;
+constexpr auto MAXIMUM_GENERATIONS_PER_SECOND = 512L;
+
+constexpr auto MILLIS_IN_SECOND = 1000;
constexpr auto CURSOR_FALLBACK_POS_X = 10;
constexpr auto CURSOR_FALLBACK_POS_Y = 10;
@@ -92,7 +93,7 @@ private:
std::chrono::system_clock::time_point _last_gen_update_time;
- int32_t _min_time_since_last_gen_millis = DEFAULT_MIN_TIME_SINCE_LAST_GEN_MILLIS;
+ int64_t _generations_per_second = DEFAULT_GENERATIONS_PER_SECOND;
std::list<Vector2> _living_cell_positions;
diff --git a/src/game/status_manager.cpp b/src/game/status_manager.cpp
index b4496ba..ac86e0a 100644
--- a/src/game/status_manager.cpp
+++ b/src/game/status_manager.cpp
@@ -13,7 +13,7 @@ void StatusManager::bind(const std::shared_ptr<IStatusLine> &statusline) noexcep
_statusline->set_section_length(StatusLineSection::C, 15);
_statusline->set_section_length(StatusLineSection::D, 20);
_statusline->set_section_length(StatusLineSection::E, 25);
- _statusline->set_section_length(StatusLineSection::F, 60);
+ _statusline->set_section_length(StatusLineSection::F, 30);
_statusline->set_section_length(StatusLineSection::G, 30);
_statusline->set_section_length(StatusLineSection::H, 30);
}