aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/GameAdvancementHook.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-11-22 23:11:42 +0100
committer GitHub <noreply@github.com>2023-11-22 23:11:42 +0100
commita54898b7770e0d66b729216173960686c67e58bb (patch)
treeaf8ed836a4789ef94c5bfed27abb713922f45af3 /src/openvic-simulation/GameAdvancementHook.cpp
parente76336cd92639f4ec71088fc4c80aea4c25528cd (diff)
parent738a203e0d8b4df87c42888043b99c13d5d97511 (diff)
Merge pull request #78 from OpenVicProject/property-macro
Refactoring (*mostly* related to the property macro)
Diffstat (limited to 'src/openvic-simulation/GameAdvancementHook.cpp')
-rw-r--r--src/openvic-simulation/GameAdvancementHook.cpp60
1 files changed, 28 insertions, 32 deletions
diff --git a/src/openvic-simulation/GameAdvancementHook.cpp b/src/openvic-simulation/GameAdvancementHook.cpp
index 4a6449c..e56331c 100644
--- a/src/openvic-simulation/GameAdvancementHook.cpp
+++ b/src/openvic-simulation/GameAdvancementHook.cpp
@@ -8,69 +8,65 @@ const std::vector<std::chrono::milliseconds> GameAdvancementHook::GAME_SPEEDS =
};
GameAdvancementHook::GameAdvancementHook(
- AdvancementFunction tickFunction, RefreshFunction updateFunction, bool startPaused, speed_t startingSpeed
+ AdvancementFunction tick_function, RefreshFunction update_function, bool start_paused, speed_t starting_speed
)
- : triggerFunction { tickFunction }, refreshFunction { updateFunction }, isPaused { startPaused } {
- lastPolledTime = std::chrono::high_resolution_clock::now();
- setSimulationSpeed(startingSpeed);
+ : trigger_function { tick_function }, refresh_function { update_function }, is_paused { start_paused } {
+ last_polled_time = std::chrono::high_resolution_clock::now();
+ set_simulation_speed(starting_speed);
}
-void GameAdvancementHook::setSimulationSpeed(speed_t speed) {
+void GameAdvancementHook::set_simulation_speed(speed_t speed) {
if (speed < 0) {
- currentSpeed = 0;
+ current_speed = 0;
} else if (speed >= GAME_SPEEDS.size()) {
- currentSpeed = GAME_SPEEDS.size() - 1;
+ current_speed = GAME_SPEEDS.size() - 1;
} else {
- currentSpeed = speed;
+ current_speed = speed;
}
}
-GameAdvancementHook::speed_t GameAdvancementHook::getSimulationSpeed() const {
- return currentSpeed;
+void GameAdvancementHook::increase_simulation_speed() {
+ set_simulation_speed(current_speed + 1);
}
-void GameAdvancementHook::increaseSimulationSpeed() {
- setSimulationSpeed(currentSpeed + 1);
+void GameAdvancementHook::decrease_simulation_speed() {
+ set_simulation_speed(current_speed - 1);
}
-void GameAdvancementHook::decreaseSimulationSpeed() {
- setSimulationSpeed(currentSpeed - 1);
+bool GameAdvancementHook::can_increase_simulation_speed() const {
+ return current_speed + 1 < GAME_SPEEDS.size();
}
-bool GameAdvancementHook::canIncreaseSimulationSpeed() const {
- return currentSpeed + 1 < GAME_SPEEDS.size();
-}
-
-bool GameAdvancementHook::canDecreaseSimulationSpeed() const {
- return currentSpeed > 0;
+bool GameAdvancementHook::can_decrease_simulation_speed() const {
+ return current_speed > 0;
}
GameAdvancementHook& GameAdvancementHook::operator++() {
- increaseSimulationSpeed();
+ increase_simulation_speed();
return *this;
};
GameAdvancementHook& GameAdvancementHook::operator--() {
- decreaseSimulationSpeed();
+ decrease_simulation_speed();
return *this;
};
-void GameAdvancementHook::conditionallyAdvanceGame() {
- if (!isPaused) {
+void GameAdvancementHook::conditionally_advance_game() {
+ if (!is_paused) {
time_point_t currentTime = std::chrono::high_resolution_clock::now();
- if (std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - lastPolledTime) >= GAME_SPEEDS[currentSpeed]) {
- lastPolledTime = currentTime;
- if (triggerFunction) {
- triggerFunction();
+ if (std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - last_polled_time) >= GAME_SPEEDS[current_speed]) {
+ last_polled_time = currentTime;
+ if (trigger_function) {
+ trigger_function();
}
}
}
- if (refreshFunction) {
- refreshFunction();
+ if (refresh_function) {
+ refresh_function();
}
}
void GameAdvancementHook::reset() {
- isPaused = true;
- currentSpeed = 0;
+ is_paused = true;
+ current_speed = 0;
}