From 738a203e0d8b4df87c42888043b99c13d5d97511 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Wed, 22 Nov 2023 17:16:49 +0100 Subject: chore: change some lingering lowerCamelCase to snake_case --- src/openvic-simulation/GameAdvancementHook.cpp | 60 ++++++++++++------------- src/openvic-simulation/GameAdvancementHook.hpp | 26 +++++------ src/openvic-simulation/dataloader/NodeTools.cpp | 6 +-- src/openvic-simulation/types/Date.cpp | 22 ++++----- src/openvic-simulation/types/Date.hpp | 14 +++--- 5 files changed, 62 insertions(+), 66 deletions(-) (limited to 'src') 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 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(currentTime - lastPolledTime) >= GAME_SPEEDS[currentSpeed]) { - lastPolledTime = currentTime; - if (triggerFunction) { - triggerFunction(); + if (std::chrono::duration_cast(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; } diff --git a/src/openvic-simulation/GameAdvancementHook.hpp b/src/openvic-simulation/GameAdvancementHook.hpp index 2a27ff9..75af718 100644 --- a/src/openvic-simulation/GameAdvancementHook.hpp +++ b/src/openvic-simulation/GameAdvancementHook.hpp @@ -3,6 +3,7 @@ #include #include #include +#include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { // Conditionally advances game with provided behaviour @@ -19,29 +20,28 @@ namespace OpenVic { private: using time_point_t = std::chrono::time_point; - time_point_t lastPolledTime; + time_point_t last_polled_time; // A function pointer that advances the simulation, intended to be a capturing // lambda or something similar. May need to be reworked later - AdvancementFunction triggerFunction; - RefreshFunction refreshFunction; - speed_t currentSpeed; + AdvancementFunction trigger_function; + RefreshFunction refresh_function; + speed_t PROPERTY_CUSTOM_NAME(current_speed, get_simulation_speed); public: - bool isPaused; + bool is_paused; GameAdvancementHook( - AdvancementFunction tickFunction, RefreshFunction updateFunction, bool startPaused = true, speed_t startingSpeed = 0 + AdvancementFunction tick_function, RefreshFunction update_function, bool start_paused = true, speed_t starting_speed = 0 ); - void setSimulationSpeed(speed_t speed); - speed_t getSimulationSpeed() const; - void increaseSimulationSpeed(); - void decreaseSimulationSpeed(); - bool canIncreaseSimulationSpeed() const; - bool canDecreaseSimulationSpeed() const; + void set_simulation_speed(speed_t speed); + void increase_simulation_speed(); + void decrease_simulation_speed(); + bool can_increase_simulation_speed() const; + bool can_decrease_simulation_speed() const; GameAdvancementHook& operator++(); GameAdvancementHook& operator--(); - void conditionallyAdvanceGame(); + void conditionally_advance_game(); void reset(); }; } diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index 19f5dd7..12e51a4 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -163,19 +163,19 @@ node_callback_t NodeTools::expect_date(callback_t callback) { node_callback_t NodeTools::expect_years(callback_t callback) { return expect_uint([callback](Timespan::day_t val) -> bool { - return callback(Timespan::fromYears(val)); + return callback(Timespan::from_years(val)); }); } node_callback_t NodeTools::expect_months(callback_t callback) { return expect_uint([callback](Timespan::day_t val) -> bool { - return callback(Timespan::fromMonths(val)); + return callback(Timespan::from_months(val)); }); } node_callback_t NodeTools::expect_days(callback_t callback) { return expect_uint([callback](Timespan::day_t val) -> bool { - return callback(Timespan::fromDays(val)); + return callback(Timespan::from_days(val)); }); } diff --git a/src/openvic-simulation/types/Date.cpp b/src/openvic-simulation/types/Date.cpp index e695e45..1b15e45 100644 --- a/src/openvic-simulation/types/Date.cpp +++ b/src/openvic-simulation/types/Date.cpp @@ -84,15 +84,15 @@ Timespan::operator std::string() const { return to_string(); } -Timespan Timespan::fromYears(day_t num) { +Timespan Timespan::from_years(day_t num) { return num * Date::DAYS_IN_YEAR; } -Timespan Timespan::fromMonths(day_t num) { +Timespan Timespan::from_months(day_t num) { return (num / Date::MONTHS_IN_YEAR) * Date::DAYS_IN_YEAR + Date::DAYS_UP_TO_MONTH[num % Date::MONTHS_IN_YEAR]; } -Timespan Timespan::fromDays(day_t num) { +Timespan Timespan::from_days(day_t num) { return num; } @@ -100,7 +100,7 @@ std::ostream& OpenVic::operator<<(std::ostream& out, Timespan const& timespan) { return out << timespan.to_string(); } -Timespan Date::_dateToTimespan(year_t year, month_t month, day_t day) { +Timespan Date::_date_to_timespan(year_t year, month_t month, day_t day) { month = std::clamp(month, 1, MONTHS_IN_YEAR); day = std::clamp(day, 1, DAYS_IN_MONTH[month - 1]); return year * DAYS_IN_YEAR + DAYS_UP_TO_MONTH[month - 1] + day - 1; @@ -142,18 +142,18 @@ Date::Date(Timespan total_days) : timespan { total_days } { } } -Date::Date(year_t year, month_t month, day_t day) : timespan { _dateToTimespan(year, month, day) } {} +Date::Date(year_t year, month_t month, day_t day) : timespan { _date_to_timespan(year, month, day) } {} -Date::year_t Date::getYear() const { +Date::year_t Date::get_year() const { return static_cast(timespan) / DAYS_IN_YEAR; } -Date::month_t Date::getMonth() const { +Date::month_t Date::get_month() const { return MONTH_FROM_DAY_IN_YEAR[static_cast(timespan) % DAYS_IN_YEAR]; } -Date::day_t Date::getDay() const { - return (static_cast(timespan) % DAYS_IN_YEAR) - DAYS_UP_TO_MONTH[getMonth() - 1] + 1; +Date::day_t Date::get_day() const { + return (static_cast(timespan) % DAYS_IN_YEAR) - DAYS_UP_TO_MONTH[get_month() - 1] + 1; } bool Date::operator<(Date other) const { @@ -219,8 +219,8 @@ Date::operator std::string() const { } std::ostream& OpenVic::operator<<(std::ostream& out, Date date) { - return out << static_cast(date.getYear()) << Date::SEPARATOR_CHARACTER << static_cast(date.getMonth()) - << Date::SEPARATOR_CHARACTER << static_cast(date.getDay()); + return out << static_cast(date.get_year()) << Date::SEPARATOR_CHARACTER << static_cast(date.get_month()) + << Date::SEPARATOR_CHARACTER << static_cast(date.get_day()); } // Parsed from string of the form YYYY.MM.DD diff --git a/src/openvic-simulation/types/Date.hpp b/src/openvic-simulation/types/Date.hpp index 5aed49b..cce1308 100644 --- a/src/openvic-simulation/types/Date.hpp +++ b/src/openvic-simulation/types/Date.hpp @@ -38,9 +38,9 @@ namespace OpenVic { std::string to_string() const; explicit operator std::string() const; - static Timespan fromYears(day_t num); - static Timespan fromMonths(day_t num); - static Timespan fromDays(day_t num); + static Timespan from_years(day_t num); + static Timespan from_months(day_t num); + static Timespan from_days(day_t num); }; std::ostream& operator<<(std::ostream& out, Timespan const& timespan); @@ -63,7 +63,7 @@ namespace OpenVic { // Number of days since Jan 1st, Year 0 Timespan timespan; - static Timespan _dateToTimespan(year_t year, month_t month, day_t day); + static Timespan _date_to_timespan(year_t year, month_t month, day_t day); static Timespan::day_t const* generate_days_up_to_month(); static month_t const* generate_month_from_day_in_year(); @@ -73,9 +73,9 @@ namespace OpenVic { // Year month day specification Date(year_t year = 0, month_t month = 1, day_t day = 1); - year_t getYear() const; - month_t getMonth() const; - day_t getDay() const; + year_t get_year() const; + month_t get_month() const; + day_t get_day() const; bool operator<(Date other) const; bool operator>(Date other) const; -- cgit v1.2.3-56-ga3b1