aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/InstanceManager.hpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-06-13 00:24:00 +0200
committer hop311 <hop3114@gmail.com>2024-06-13 00:24:00 +0200
commit4b39e77304094708d5c503b6a221386408cc4409 (patch)
tree7ba5a06714c267185dd3a59aabc6556a105c122f /src/openvic-simulation/InstanceManager.hpp
parentc0ba822ee46551a40ad6b43e8f56b80e27ae35b5 (diff)
Separated GameManager into Definition and Instance Managersinstance-definition-managers
Diffstat (limited to 'src/openvic-simulation/InstanceManager.hpp')
-rw-r--r--src/openvic-simulation/InstanceManager.hpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/openvic-simulation/InstanceManager.hpp b/src/openvic-simulation/InstanceManager.hpp
new file mode 100644
index 0000000..743fd71
--- /dev/null
+++ b/src/openvic-simulation/InstanceManager.hpp
@@ -0,0 +1,64 @@
+#pragma once
+
+#include <functional>
+
+#include "openvic-simulation/country/CountryInstance.hpp"
+#include "openvic-simulation/diplomacy/CountryRelation.hpp"
+#include "openvic-simulation/economy/GoodInstance.hpp"
+#include "openvic-simulation/map/MapInstance.hpp"
+#include "openvic-simulation/map/Mapmode.hpp"
+#include "openvic-simulation/military/UnitInstance.hpp"
+#include "openvic-simulation/misc/SimulationClock.hpp"
+#include "openvic-simulation/types/Date.hpp"
+
+namespace OpenVic {
+ struct DefinitionManager;
+ struct Bookmark;
+
+ struct InstanceManager {
+ using gamestate_updated_func_t = std::function<void()>;
+
+ private:
+ DefinitionManager const& PROPERTY(definition_manager);
+
+ CountryInstanceManager PROPERTY_REF(country_instance_manager);
+ CountryRelationManager PROPERTY_REF(country_relation_manager);
+ GoodInstanceManager PROPERTY_REF(good_instance_manager);
+ UnitInstanceManager PROPERTY_REF(unit_instance_manager);
+ /* Near the end so it is freed after other managers that may depend on it,
+ * e.g. if we want to remove military units from the province they're in when they're destructed. */
+ MapInstance PROPERTY_REF(map_instance);
+ SimulationClock PROPERTY_REF(simulation_clock);
+
+ bool PROPERTY_CUSTOM_PREFIX(game_instance_setup, is);
+ bool PROPERTY_CUSTOM_PREFIX(game_session_started, is);
+
+ public:
+ inline constexpr bool is_bookmark_loaded() const {
+ return bookmark != nullptr;
+ }
+
+ private:
+ time_t session_start; /* SS-54, as well as allowing time-tracking */
+ Bookmark const* PROPERTY(bookmark);
+ Date PROPERTY(today);
+ gamestate_updated_func_t gamestate_updated;
+ bool gamestate_needs_update, currently_updating_gamestate;
+
+ void set_gamestate_needs_update();
+ void update_gamestate();
+ void tick();
+
+ public:
+ InstanceManager(
+ DefinitionManager const& new_definition_manager, gamestate_updated_func_t gamestate_updated_callback,
+ SimulationClock::state_changed_function_t clock_state_changed_callback
+ );
+
+ bool setup();
+ bool load_bookmark(Bookmark const* new_bookmark);
+ bool start_game_session();
+
+ bool expand_selected_province_building(size_t building_index);
+ };
+}