From 4a899c1a9e83ab9476b85522751081be434caa35 Mon Sep 17 00:00:00 2001 From: hop311 Date: Sat, 2 Dec 2023 15:48:08 +0000 Subject: Crime+event modifier loading + misc UI backend --- .../misc/GameAdvancementHook.hpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/openvic-simulation/misc/GameAdvancementHook.hpp (limited to 'src/openvic-simulation/misc/GameAdvancementHook.hpp') diff --git a/src/openvic-simulation/misc/GameAdvancementHook.hpp b/src/openvic-simulation/misc/GameAdvancementHook.hpp new file mode 100644 index 0000000..75af718 --- /dev/null +++ b/src/openvic-simulation/misc/GameAdvancementHook.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include +#include "openvic-simulation/utility/Getters.hpp" + +namespace OpenVic { + // Conditionally advances game with provided behaviour + // Class governs game speed and pause state + class GameAdvancementHook { + public: + using AdvancementFunction = std::function; + using RefreshFunction = std::function; + using speed_t = int8_t; + + // Minimum number of miliseconds before the simulation advances + static const std::vector GAME_SPEEDS; + + private: + using time_point_t = std::chrono::time_point; + + 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 trigger_function; + RefreshFunction refresh_function; + speed_t PROPERTY_CUSTOM_NAME(current_speed, get_simulation_speed); + + public: + bool is_paused; + + GameAdvancementHook( + AdvancementFunction tick_function, RefreshFunction update_function, bool start_paused = true, speed_t starting_speed = 0 + ); + + 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 conditionally_advance_game(); + void reset(); + }; +} -- cgit v1.2.3-56-ga3b1