aboutsummaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-06-13 00:34:06 +0200
committer hop311 <hop3114@gmail.com>2024-06-13 21:26:35 +0200
commitdb246d901d1ccd39b0ed3fc024f28ad7b6b4848b (patch)
tree0c06560ddae94550077c997f8b7e14f69057f236 /extension
parent72ae774f249fb408d5a3e3de09695c251906a7cc (diff)
Updated SIM to use separate Instance and Definition Managersinstance-definition-managers
Diffstat (limited to 'extension')
m---------extension/deps/openvic-simulation0
-rw-r--r--extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp19
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.cpp87
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.hpp20
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp115
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.hpp6
-rw-r--r--extension/src/openvic-extension/singletons/ModelSingleton.cpp16
-rw-r--r--extension/src/openvic-extension/singletons/PopulationMenu.cpp52
-rw-r--r--extension/src/openvic-extension/utility/UITools.cpp6
9 files changed, 209 insertions, 112 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation
-Subproject 01a8f60aaca9784d814f4cb35a3fc4be86e1dd2
+Subproject bfd539513af435564daf70f94f6cce146dd5c94
diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
index 51a4235..fdc1a10 100644
--- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
+++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
@@ -36,11 +36,20 @@ Error GFXMaskedFlagTexture::_generate_combined_image() {
if (mask_image.is_valid() && flag_image.is_valid() && flag_image_rect.has_area()) {
const Vector2i centre_translation = (mask_image->get_size() - button_image->get_size()) / 2;
- for (Vector2i combined_image_point { 0, 0 }; combined_image_point.y < button_image->get_height(); ++combined_image_point.y) {
+
+ for (
+ Vector2i combined_image_point { 0, 0 };
+ combined_image_point.y < button_image->get_height();
+ ++combined_image_point.y
+ ) {
+
for (combined_image_point.x = 0; combined_image_point.x < button_image->get_width(); ++combined_image_point.x) {
+
const Color overlay_image_colour = overlay_image->get_pixelv(combined_image_point);
+
// Translate to mask_image coordinates, keeping the centres of each image aligned.
const Vector2i mask_image_point = combined_image_point + centre_translation;
+
if (
0 <= mask_image_point.x && mask_image_point.x < mask_image->get_width() &&
0 <= mask_image_point.y && mask_image_point.y < mask_image->get_height()
@@ -176,13 +185,15 @@ Error GFXMaskedFlagTexture::set_flag_country_and_type(Country const* new_flag_co
return _generate_combined_image();
}
-Error GFXMaskedFlagTexture::set_flag_country_name_and_type(String const& new_flag_country_name, StringName const& new_flag_type) {
+Error GFXMaskedFlagTexture::set_flag_country_name_and_type(
+ String const& new_flag_country_name, StringName const& new_flag_type
+) {
if (new_flag_country_name.is_empty()) {
return set_flag_country_and_type(nullptr, {});
}
GameSingleton* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, FAILED);
- Country const* new_flag_country = game_singleton->get_game_manager().get_country_manager().get_country_by_identifier(
+ Country const* new_flag_country = game_singleton->get_definition_manager().get_country_manager().get_country_by_identifier(
godot_to_std_string(new_flag_country_name)
);
ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, vformat("Country not found: %s", new_flag_country_name));
@@ -200,7 +211,7 @@ Error GFXMaskedFlagTexture::set_flag_country_name(String const& new_flag_country
}
GameSingleton* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, FAILED);
- Country const* new_flag_country = game_singleton->get_game_manager().get_country_manager().get_country_by_identifier(
+ Country const* new_flag_country = game_singleton->get_definition_manager().get_country_manager().get_country_by_identifier(
godot_to_std_string(new_flag_country_name)
);
ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, vformat("Country not found: %s", new_flag_country_name));
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp
index 2e330ac..7114189 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp
@@ -47,6 +47,7 @@ void GameSingleton::_bind_methods() {
OV_BIND_METHOD(GameSingleton::lookup_file_path, { "path" });
OV_BIND_METHOD(GameSingleton::setup_game, { "bookmark_index" });
+ OV_BIND_METHOD(GameSingleton::start_game_session);
OV_BIND_METHOD(GameSingleton::get_province_index_from_uv_coords, { "coords" });
@@ -120,41 +121,49 @@ void GameSingleton::setup_logger() {
}
Error GameSingleton::setup_game(int32_t bookmark_index) {
- Bookmark const* bookmark = game_manager.get_history_manager().get_bookmark_manager().get_bookmark_by_index(bookmark_index);
+ Bookmark const* bookmark = game_manager.get_definition_manager().get_history_manager().get_bookmark_manager()
+ .get_bookmark_by_index(bookmark_index);
ERR_FAIL_NULL_V_MSG(bookmark, FAILED, vformat("Failed to get bookmark with index: %d", bookmark_index));
- bool ret = game_manager.load_bookmark(bookmark);
+ bool ret = game_manager.setup_instance(bookmark);
- for (ProvinceInstance& province : game_manager.get_map_instance().get_province_instances()) {
+ // TODO - remove this temporary crime assignment
+ InstanceManager* instance_manager = get_instance_manager();
+ ERR_FAIL_NULL_V_MSG(instance_manager, FAILED, "Failed to setup instance manager!");
+ for (ProvinceInstance& province : instance_manager->get_map_instance().get_province_instances()) {
province.set_crime(
- game_manager.get_crime_manager().get_crime_modifier_by_index(
+ get_definition_manager().get_crime_manager().get_crime_modifier_by_index(
(province.get_province_definition().get_index() - 1)
- % game_manager.get_crime_manager().get_crime_modifier_count()
+ % get_definition_manager().get_crime_manager().get_crime_modifier_count()
)
);
}
MenuSingleton* menu_singleton = MenuSingleton::get_singleton();
ERR_FAIL_NULL_V(menu_singleton, FAILED);
- menu_singleton->_population_menu_update_provinces();
+ ret &= menu_singleton->_population_menu_update_provinces();
return ERR(ret);
}
+Error GameSingleton::start_game_session() {
+ return ERR(game_manager.start_game_session());
+}
+
int32_t GameSingleton::get_province_index_from_uv_coords(Vector2 const& coords) const {
const Vector2 pos = coords.posmod(1.0f) * get_map_dims();
- return game_manager.get_map_definition().get_province_index_at(Utilities::from_godot_ivec2(pos));
+ return get_definition_manager().get_map_definition().get_province_index_at(Utilities::from_godot_ivec2(pos));
}
int32_t GameSingleton::get_map_width() const {
- return game_manager.get_map_definition().get_width();
+ return get_definition_manager().get_map_definition().get_width();
}
int32_t GameSingleton::get_map_height() const {
- return game_manager.get_map_definition().get_height();
+ return get_definition_manager().get_map_definition().get_height();
}
Vector2i GameSingleton::get_map_dims() const {
- return Utilities::to_godot_ivec2(game_manager.get_map_definition().get_dims());
+ return Utilities::to_godot_ivec2(get_definition_manager().get_map_definition().get_dims());
}
float GameSingleton::get_map_aspect_ratio() const {
@@ -179,7 +188,7 @@ Ref<ImageTexture> GameSingleton::get_flag_sheet_texture() const {
int32_t GameSingleton::get_flag_sheet_index(int32_t country_index, godot::StringName const& flag_type) const {
ERR_FAIL_COND_V_MSG(
- country_index < 0 || country_index >= game_manager.get_country_manager().get_country_count(), -1,
+ country_index < 0 || country_index >= get_definition_manager().get_country_manager().get_country_count(), -1,
vformat("Invalid country index: %d", country_index)
);
@@ -214,7 +223,7 @@ Ref<ImageTexture> GameSingleton::get_province_colour_texture() const {
}
Error GameSingleton::_update_colour_image() {
- MapDefinition const& map_definition = game_manager.get_map_definition();
+ MapDefinition const& map_definition = get_definition_manager().get_map_definition();
ERR_FAIL_COND_V_MSG(
!map_definition.province_definitions_are_locked(), FAILED,
"Cannot generate province colour image before provinces are locked!"
@@ -233,8 +242,10 @@ Error GameSingleton::_update_colour_image() {
ERR_FAIL_COND_V(colour_data_array.resize(colour_data_array_size) != OK, FAILED);
Error err = OK;
- if (!game_manager.get_mapmode_manager().generate_mapmode_colours(
- game_manager.get_map_instance(), mapmode_index, colour_data_array.ptrw()
+
+ InstanceManager const* instance_manager = get_instance_manager();
+ if (instance_manager != nullptr && !get_definition_manager().get_mapmode_manager().generate_mapmode_colours(
+ instance_manager->get_map_instance(), mapmode_index, colour_data_array.ptrw()
)) {
err = FAILED;
}
@@ -262,7 +273,7 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
static const StringName rotation_key = "rotation";
static const StringName scale_key = "scale";
- MapDefinition const& map_definition = game_manager.get_map_definition();
+ MapDefinition const& map_definition = get_definition_manager().get_map_definition();
TypedArray<Dictionary> ret;
ERR_FAIL_COND_V(ret.resize(map_definition.get_province_definition_count()) != OK, {});
@@ -292,11 +303,11 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
}
int32_t GameSingleton::get_mapmode_count() const {
- return game_manager.get_mapmode_manager().get_mapmode_count();
+ return get_definition_manager().get_mapmode_manager().get_mapmode_count();
}
String GameSingleton::get_mapmode_identifier(int32_t index) const {
- Mapmode const* mapmode = game_manager.get_mapmode_manager().get_mapmode_by_index(index);
+ Mapmode const* mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index);
if (mapmode != nullptr) {
return std_view_to_godot_string(mapmode->get_identifier());
}
@@ -304,7 +315,8 @@ String GameSingleton::get_mapmode_identifier(int32_t index) const {
}
Error GameSingleton::set_mapmode(String const& identifier) {
- Mapmode const* mapmode = game_manager.get_mapmode_manager().get_mapmode_by_identifier(godot_to_std_string(identifier));
+ Mapmode const* mapmode =
+ get_definition_manager().get_mapmode_manager().get_mapmode_by_identifier(godot_to_std_string(identifier));
ERR_FAIL_NULL_V_MSG(mapmode, FAILED, vformat("Failed to find mapmode with identifier: %s", identifier));
mapmode_index = mapmode->get_index();
return _update_colour_image();
@@ -315,16 +327,22 @@ bool GameSingleton::is_parchment_mapmode_allowed() const {
// TODO - move mapmode index to SIM/Map?
/* Disallows parchment mapmode for the cosmetic terrain mapmode */
static constexpr std::string_view cosmetic_terrain_mapmode = "mapmode_terrain";
- Mapmode const* mapmode = game_manager.get_mapmode_manager().get_mapmode_by_index(mapmode_index);
+ Mapmode const* mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(mapmode_index);
return mapmode != nullptr && mapmode->get_identifier() != cosmetic_terrain_mapmode;
}
int32_t GameSingleton::get_selected_province_index() const {
- return game_manager.get_map_instance().get_selected_province_index();
+ InstanceManager const* instance_manager = get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, 0);
+
+ return instance_manager->get_map_instance().get_selected_province_index();
}
void GameSingleton::set_selected_province(int32_t index) {
- game_manager.get_map_instance().set_selected_province(index);
+ InstanceManager* instance_manager = get_instance_manager();
+ ERR_FAIL_NULL(instance_manager);
+
+ instance_manager->get_map_instance().set_selected_province(index);
_update_colour_image();
emit_signal(_signal_province_selected(), index);
}
@@ -334,7 +352,10 @@ void GameSingleton::unset_selected_province() {
}
void GameSingleton::try_tick() {
- game_manager.get_simulation_clock().conditionally_advance_game();
+ InstanceManager* instance_manager = get_instance_manager();
+ ERR_FAIL_NULL(instance_manager);
+
+ instance_manager->get_simulation_clock().conditionally_advance_game();
}
Error GameSingleton::_load_map_images() {
@@ -354,7 +375,7 @@ Error GameSingleton::_load_map_images() {
}
MapDefinition::shape_pixel_t const* province_shape_data =
- game_manager.get_map_definition().get_province_shape_image().data();
+ get_definition_manager().get_map_definition().get_province_shape_image().data();
const Vector2i divided_dims = province_dims / image_subdivisions;
const int64_t subdivision_width = divided_dims.x * sizeof(MapDefinition::shape_pixel_t);
@@ -460,12 +481,13 @@ Error GameSingleton::_load_flag_sheet() {
"Flag sheet image and/or texture has already been generated!"
);
- GovernmentTypeManager const& government_type_manager = game_manager.get_politics_manager().get_government_type_manager();
+ GovernmentTypeManager const& government_type_manager =
+ get_definition_manager().get_politics_manager().get_government_type_manager();
ERR_FAIL_COND_V_MSG(
government_type_manager.get_flag_types().empty() || !government_type_manager.government_types_are_locked(), FAILED,
"Cannot load flag images if flag types are empty or government types are not locked!"
);
- CountryManager const& country_manager = game_manager.get_country_manager();
+ CountryManager const& country_manager = get_definition_manager().get_country_manager();
ERR_FAIL_COND_V_MSG(
country_manager.countries_empty() || !country_manager.countries_are_locked(), FAILED,
"Cannot load flag images if countries are empty or not locked!"
@@ -572,14 +594,12 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
Error err = OK;
- if (!dataloader.set_roots(roots)) {
- Logger::error("Failed to set dataloader roots!");
- err = FAILED;
- }
- if (!dataloader.load_defines(game_manager)) {
+ auto add_message = std::bind_front(&LoadLocalisation::add_message, LoadLocalisation::get_singleton());
+ if (!game_manager.load_definitions(roots, add_message)) {
UtilityFunctions::push_error("Failed to load defines!");
err = FAILED;
}
+
if (_load_terrain_variants() != OK) {
UtilityFunctions::push_error("Failed to load terrain variants!");
err = FAILED;
@@ -592,11 +612,6 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
UtilityFunctions::push_error("Failed to load map images!");
err = FAILED;
}
- auto add_message = std::bind_front(&LoadLocalisation::add_message, LoadLocalisation::get_singleton());
- if (!dataloader.load_localisation_files(add_message)) {
- UtilityFunctions::push_error("Failed to load localisation!");
- err = FAILED;
- }
return err;
}
@@ -606,5 +621,5 @@ String GameSingleton::search_for_game_path(String const& hint_path) {
}
String GameSingleton::lookup_file_path(String const& path) const {
- return std_to_godot_string(dataloader.lookup_file(godot_to_std_string(path)).string());
+ return std_to_godot_string(get_dataloader().lookup_file(godot_to_std_string(path)).string());
}
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp
index eab8f63..b29e588 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp
@@ -13,8 +13,7 @@ namespace OpenVic {
static inline GameSingleton* singleton = nullptr;
- GameManager PROPERTY_REF(game_manager);
- Dataloader PROPERTY(dataloader);
+ GameManager game_manager;
godot::Vector2i image_subdivisions;
godot::Ref<godot::Texture2DArray> province_shape_texture;
@@ -54,6 +53,22 @@ namespace OpenVic {
static void setup_logger();
+ inline constexpr Dataloader const& get_dataloader() const {
+ return game_manager.get_dataloader();
+ }
+
+ inline constexpr DefinitionManager const& get_definition_manager() const {
+ return game_manager.get_definition_manager();
+ }
+
+ inline constexpr InstanceManager* get_instance_manager() {
+ return game_manager.get_instance_manager();
+ }
+
+ inline constexpr InstanceManager const* get_instance_manager() const {
+ return game_manager.get_instance_manager();
+ }
+
/* Load the game's defines in compatiblity mode from the filepath
* pointing to the defines folder. */
godot::Error load_defines_compatibility_mode(godot::PackedStringArray const& file_paths);
@@ -63,6 +78,7 @@ namespace OpenVic {
/* Post-load/restart game setup - reset the game to post-load state and load the specified bookmark. */
godot::Error setup_game(int32_t bookmark_index);
+ godot::Error start_game_session();
int32_t get_province_index_from_uv_coords(godot::Vector2 const& coords) const;
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 92af168..79998d7 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -147,15 +147,7 @@ MenuSingleton* MenuSingleton::get_singleton() {
return singleton;
}
-MenuSingleton::MenuSingleton() : game_manager {
- []() -> GameManager* {
- GameSingleton* game_singleton = GameSingleton::get_singleton();
- ERR_FAIL_NULL_V_MSG(
- game_singleton, nullptr, "Cannot initialise MenuSingleton's GameManager pointer - GameSingleton not initialised!"
- );
- return &game_singleton->get_game_manager();
- }()
-} {
+MenuSingleton::MenuSingleton() {
ERR_FAIL_COND(singleton != nullptr);
singleton = this;
}
@@ -168,7 +160,10 @@ MenuSingleton::~MenuSingleton() {
/* PROVINCE OVERVIEW PANEL */
Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
- ERR_FAIL_NULL_V(game_manager, {});
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, {});
static const StringName province_info_province_key = "province";
static const StringName province_info_state_key = "state";
@@ -188,7 +183,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
static const StringName province_info_cores_key = "cores";
static const StringName province_info_buildings_key = "buildings";
- ProvinceInstance const* province = game_manager->get_map_instance().get_province_instance_by_index(index);
+ ProvinceInstance const* province = instance_manager->get_map_instance().get_province_instance_by_index(index);
if (province == nullptr) {
return {};
}
@@ -298,16 +293,19 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
}
int32_t MenuSingleton::get_province_building_count() const {
- ERR_FAIL_NULL_V(game_manager, 0);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, 0);
- return game_manager->get_economy_manager().get_building_type_manager().get_province_building_types().size();
+ return game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager()
+ .get_province_building_types().size();
}
String MenuSingleton::get_province_building_identifier(int32_t building_index) const {
- ERR_FAIL_NULL_V(game_manager, {});
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
- std::vector<BuildingType const*> const& province_building_types =
- game_manager->get_economy_manager().get_building_type_manager().get_province_building_types();
+ std::vector<BuildingType const*> const& province_building_types = game_singleton->get_definition_manager()
+ .get_economy_manager().get_building_type_manager().get_province_building_types();
ERR_FAIL_COND_V_MSG(
building_index < 0 || building_index >= province_building_types.size(), {},
vformat("Invalid province building index: %d", building_index)
@@ -316,35 +314,41 @@ String MenuSingleton::get_province_building_identifier(int32_t building_index) c
}
Error MenuSingleton::expand_selected_province_building(int32_t building_index) {
- ERR_FAIL_NULL_V(game_manager, FAILED);
+ GameSingleton* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, FAILED);
+ InstanceManager* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, FAILED);
ERR_FAIL_COND_V_MSG(
- !game_manager->expand_selected_province_building(building_index), FAILED,
+ !instance_manager->expand_selected_province_building(building_index), FAILED,
vformat("Failed to expand the currently selected province's building index %d", building_index)
);
return OK;
}
int32_t MenuSingleton::get_slave_pop_icon_index() const {
- ERR_FAIL_NULL_V(game_manager, 0);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, 0);
- const PopType::sprite_t sprite = game_manager->get_pop_manager().get_slave_sprite();
+ const PopType::sprite_t sprite = game_singleton->get_definition_manager().get_pop_manager().get_slave_sprite();
ERR_FAIL_COND_V_MSG(sprite <= 0, 0, "Slave sprite unset!");
return sprite;
}
int32_t MenuSingleton::get_administrative_pop_icon_index() const {
- ERR_FAIL_NULL_V(game_manager, 0);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, 0);
- const PopType::sprite_t sprite = game_manager->get_pop_manager().get_administrative_sprite();
+ const PopType::sprite_t sprite = game_singleton->get_definition_manager().get_pop_manager().get_administrative_sprite();
ERR_FAIL_COND_V_MSG(sprite <= 0, 0, "Administrative sprite unset!");
return sprite;
}
int32_t MenuSingleton::get_rgo_owner_pop_icon_index() const {
- ERR_FAIL_NULL_V(game_manager, 0);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, 0);
- const PopType::sprite_t sprite = game_manager->get_economy_manager().get_production_type_manager().get_rgo_owner_sprite();
+ const PopType::sprite_t sprite = game_singleton->get_definition_manager().get_economy_manager().get_production_type_manager().get_rgo_owner_sprite();
ERR_FAIL_COND_V_MSG(sprite <= 0, 0, "RGO owner sprite unset!");
return sprite;
}
@@ -352,55 +356,82 @@ int32_t MenuSingleton::get_rgo_owner_pop_icon_index() const {
/* TIME/SPEED CONTROL PANEL */
void MenuSingleton::set_paused(bool paused) {
- ERR_FAIL_NULL(game_manager);
+ GameSingleton* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL(game_singleton);
+ InstanceManager* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL(instance_manager);
- game_manager->get_simulation_clock().set_paused(paused);
+ instance_manager->get_simulation_clock().set_paused(paused);
}
void MenuSingleton::toggle_paused() {
- ERR_FAIL_NULL(game_manager);
+ GameSingleton* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL(game_singleton);
+ InstanceManager* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL(instance_manager);
- game_manager->get_simulation_clock().toggle_paused();
+ instance_manager->get_simulation_clock().toggle_paused();
}
bool MenuSingleton::is_paused() const {
- ERR_FAIL_NULL_V(game_manager, true);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, true);
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, true);
- return game_manager->get_simulation_clock().is_paused();
+ return instance_manager->get_simulation_clock().is_paused();
}
void MenuSingleton::increase_speed() {
- ERR_FAIL_NULL(game_manager);
+ GameSingleton* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL(game_singleton);
+ InstanceManager* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL(instance_manager);
- game_manager->get_simulation_clock().increase_simulation_speed();
+ instance_manager->get_simulation_clock().increase_simulation_speed();
}
void MenuSingleton::decrease_speed() {
- ERR_FAIL_NULL(game_manager);
+ GameSingleton* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL(game_singleton);
+ InstanceManager* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL(instance_manager);
- game_manager->get_simulation_clock().decrease_simulation_speed();
+ instance_manager->get_simulation_clock().decrease_simulation_speed();
}
int32_t MenuSingleton::get_speed() const {
- ERR_FAIL_NULL_V(game_manager, 0);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, 0);
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, 0);
- return game_manager->get_simulation_clock().get_simulation_speed();
+ return instance_manager->get_simulation_clock().get_simulation_speed();
}
bool MenuSingleton::can_increase_speed() const {
- ERR_FAIL_NULL_V(game_manager, false);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, false);
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, false);
- return game_manager->get_simulation_clock().can_increase_simulation_speed();
+ return instance_manager->get_simulation_clock().can_increase_simulation_speed();
}
bool MenuSingleton::can_decrease_speed() const {
- ERR_FAIL_NULL_V(game_manager, false);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, false);
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, false);
- return game_manager->get_simulation_clock().can_decrease_simulation_speed();
+ return instance_manager->get_simulation_clock().can_decrease_simulation_speed();
}
String MenuSingleton::get_longform_date() const {
- ERR_FAIL_NULL_V(game_manager, {});
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, {});
- return Utilities::date_to_formatted_string(game_manager->get_today());
+ return Utilities::date_to_formatted_string(instance_manager->get_today());
}
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
index efce81f..a3bcb67 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
@@ -6,7 +6,6 @@
#include <openvic-simulation/types/OrderedContainers.hpp>
namespace OpenVic {
- struct GameManager;
struct State;
class MenuSingleton : public godot::Object {
@@ -14,8 +13,6 @@ namespace OpenVic {
static inline MenuSingleton* singleton = nullptr;
- GameManager* game_manager;
-
public:
struct population_menu_t {
enum ProvinceListEntry {
@@ -113,7 +110,7 @@ namespace OpenVic {
godot::String get_longform_date() const;
/* POPULATION MENU */
- void _population_menu_update_provinces();
+ bool _population_menu_update_provinces();
int32_t get_population_menu_province_list_row_count() const;
godot::TypedArray<godot::Dictionary> get_population_menu_province_list_rows(int32_t start, int32_t count) const;
godot::Error population_menu_select_province_list_entry(int32_t select_index, bool set_scroll_index = false);
@@ -129,6 +126,7 @@ namespace OpenVic {
godot::TypedArray<godot::Dictionary> get_population_menu_pop_rows(int32_t start, int32_t count) const;
int32_t get_population_menu_pop_row_count() const;
+ bool _population_menu_generate_pop_filters();
godot::PackedInt32Array get_population_menu_pop_filter_setup_info();
godot::TypedArray<godot::Dictionary> get_population_menu_pop_filter_info() const;
godot::Error population_menu_toggle_pop_filter(int32_t filter_index);
diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp
index 091bd8a..8735780 100644
--- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp
@@ -42,7 +42,7 @@ GFX::Actor const* ModelSingleton::get_actor(std::string_view name, bool error_on
ERR_FAIL_NULL_V(game_singleton, nullptr);
GFX::Actor const* actor =
- game_singleton->get_game_manager().get_ui_manager().get_cast_object_by_identifier<GFX::Actor>(name);
+ game_singleton->get_definition_manager().get_ui_manager().get_cast_object_by_identifier<GFX::Actor>(name);
if (error_on_fail) {
ERR_FAIL_NULL_V_MSG(actor, nullptr, vformat("Failed to find actor \"%s\"", std_view_to_godot_string(name)));
@@ -72,8 +72,8 @@ GFX::Actor const* ModelSingleton::get_cultural_actor(
if (actor == nullptr) {
/* If no Actor exists for the specified GraphicalCultureType then try the default instead. */
- GraphicalCultureType const* default_graphical_culture_type =
- game_singleton->get_game_manager().get_pop_manager().get_culture_manager().get_default_graphical_culture_type();
+ GraphicalCultureType const* default_graphical_culture_type = game_singleton->get_definition_manager().get_pop_manager()
+ .get_culture_manager().get_default_graphical_culture_type();
if (default_graphical_culture_type != nullptr && default_graphical_culture_type->get_identifier() != culture) {
actor_name = StringUtils::append_string_views(default_graphical_culture_type->get_identifier(), name);
@@ -308,10 +308,12 @@ bool ModelSingleton::add_unit_dict(ordered_set<T*> const& units, TypedArray<Dict
TypedArray<Dictionary> ModelSingleton::get_units() const {
GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, {});
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, {});
TypedArray<Dictionary> ret;
- for (ProvinceInstance const& province : game_singleton->get_game_manager().get_map_instance().get_province_instances()) {
+ for (ProvinceInstance const& province : instance_manager->get_map_instance().get_province_instances()) {
if (province.get_province_definition().is_water()) {
if (!add_unit_dict(province.get_navies(), ret)) {
UtilityFunctions::push_error(
@@ -379,7 +381,7 @@ bool ModelSingleton::add_building_dict(
if (
&building.get_building_type() ==
- game_singleton->get_game_manager().get_economy_manager().get_building_type_manager().get_port_building_type()
+ game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager().get_port_building_type()
) {
/* Port */
if (!province_definition.has_port()) {
@@ -442,10 +444,12 @@ bool ModelSingleton::add_building_dict(
TypedArray<Dictionary> ModelSingleton::get_buildings() const {
GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, {});
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, {});
TypedArray<Dictionary> ret;
- for (ProvinceInstance const& province : game_singleton->get_game_manager().get_map_instance().get_province_instances()) {
+ for (ProvinceInstance const& province : instance_manager->get_map_instance().get_province_instances()) {
if (!province.get_province_definition().is_water()) {
for (BuildingInstance const& building : province.get_buildings()) {
if (!add_building_dict(building, province, ret)) {
diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp
index 3144a1a..1804539 100644
--- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp
+++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp
@@ -2,9 +2,11 @@
#include <godot_cpp/variant/utility_functions.hpp>
-#include <openvic-simulation/GameManager.hpp>
+#include <openvic-simulation/DefinitionManager.hpp>
+#include <openvic-simulation/InstanceManager.hpp>
#include "openvic-extension/classes/GFXPieChartTexture.hpp"
+#include "openvic-extension/singletons/GameSingleton.hpp"
#include "openvic-extension/utility/Utilities.hpp"
using namespace godot;
@@ -14,18 +16,22 @@ using OpenVic::Utilities::std_view_to_godot_string;
/* POPULATION MENU */
-void MenuSingleton::_population_menu_update_provinces() {
- ERR_FAIL_NULL(game_manager);
+bool MenuSingleton::_population_menu_update_provinces() {
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, false);
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, false);
population_menu.province_list_entries.clear();
population_menu.visible_province_list_entries = 0;
+ ERR_FAIL_COND_V(!_population_menu_generate_pop_filters(), false);
- MapInstance const& map_instance = game_manager->get_map_instance();
- ERR_FAIL_COND(!map_instance.province_instances_are_locked());
+ MapInstance const& map_instance = instance_manager->get_map_instance();
+ ERR_FAIL_COND_V(!map_instance.province_instances_are_locked(), false);
for (Country const* country : {
// Example country
- game_manager->get_country_manager().get_country_by_identifier("ENG")
+ game_singleton->get_definition_manager().get_country_manager().get_country_by_identifier("ENG")
}) {
ERR_CONTINUE(country == nullptr);
@@ -52,6 +58,8 @@ void MenuSingleton::_population_menu_update_provinces() {
// TODO - may need to emit population_menu_province_list_selected_changed if _update_info cannot be guaranteed
_population_menu_update_pops();
+
+ return true;
}
int32_t MenuSingleton::get_population_menu_province_list_row_count() const {
@@ -60,7 +68,10 @@ int32_t MenuSingleton::get_population_menu_province_list_row_count() const {
TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int32_t start, int32_t count) const {
// TODO - remove when country population is used instead of total map population
- ERR_FAIL_NULL_V(game_manager, {});
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, {});
if (population_menu.province_list_entries.empty()) {
return {};
@@ -163,7 +174,7 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int
return true;
}
- } entry_visitor { *this, start, count, game_manager->get_map_instance().get_total_map_population() };
+ } entry_visitor { *this, start, count, instance_manager->get_map_instance().get_total_map_population() };
while (entry_visitor.index < population_menu.province_list_entries.size()
&& std::visit(entry_visitor, population_menu.province_list_entries[entry_visitor.index])) {
@@ -257,10 +268,13 @@ Error MenuSingleton::population_menu_select_province_list_entry(int32_t select_i
}
Error MenuSingleton::population_menu_select_province(int32_t province_index) {
- ERR_FAIL_NULL_V(game_manager, FAILED);
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, FAILED);
+ InstanceManager const* instance_manager = game_singleton->get_instance_manager();
+ ERR_FAIL_NULL_V(instance_manager, FAILED);
ERR_FAIL_COND_V(
- province_index <= 0 || province_index > game_manager->get_map_instance().get_province_instance_count(), FAILED
+ province_index <= 0 || province_index > instance_manager->get_map_instance().get_province_instance_count(), FAILED
);
struct entry_visitor_t {
@@ -636,15 +650,23 @@ int32_t MenuSingleton::get_population_menu_pop_row_count() const {
return population_menu.filtered_pops.size();
}
-PackedInt32Array MenuSingleton::get_population_menu_pop_filter_setup_info() {
- ERR_FAIL_NULL_V(game_manager, {});
-
+bool MenuSingleton::_population_menu_generate_pop_filters() {
if (population_menu.pop_filters.empty()) {
- for (PopType const& pop_type : game_manager->get_pop_manager().get_pop_types()) {
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, false);
+
+ for (PopType const& pop_type : game_singleton->get_definition_manager().get_pop_manager().get_pop_types()) {
population_menu.pop_filters.emplace(&pop_type, population_menu_t::pop_filter_t { 0, 0, true });
}
+
+ ERR_FAIL_COND_V_MSG(population_menu.pop_filters.empty(), false, "Failed to generate population menu pop filters!");
}
- ERR_FAIL_COND_V_MSG(population_menu.pop_filters.empty(), {}, "Failed to generate population menu pop filters!");
+
+ return true;
+}
+
+PackedInt32Array MenuSingleton::get_population_menu_pop_filter_setup_info() {
+ ERR_FAIL_COND_V(!_population_menu_generate_pop_filters(), {});
PackedInt32Array array;
ERR_FAIL_COND_V(array.resize(population_menu.pop_filters.size()) != OK, {});
diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp
index 6a9384b..53f17b9 100644
--- a/extension/src/openvic-extension/utility/UITools.cpp
+++ b/extension/src/openvic-extension/utility/UITools.cpp
@@ -32,7 +32,7 @@ using OpenVic::Utilities::std_view_to_godot_string_name;
GFX::Sprite const* UITools::get_gfx_sprite(godot::String const& gfx_sprite) {
GameSingleton* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, nullptr);
- GFX::Sprite const* sprite = game_singleton->get_game_manager().get_ui_manager().get_sprite_by_identifier(
+ GFX::Sprite const* sprite = game_singleton->get_definition_manager().get_ui_manager().get_sprite_by_identifier(
godot_to_std_string(gfx_sprite)
);
ERR_FAIL_NULL_V_MSG(sprite, nullptr, vformat("GFX sprite not found: %s", gfx_sprite));
@@ -43,7 +43,7 @@ GUI::Element const* UITools::get_gui_element(godot::String const& gui_scene, god
GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, nullptr);
GUI::Scene const* scene =
- game_singleton->get_game_manager().get_ui_manager().get_scene_by_identifier(godot_to_std_string(gui_scene));
+ game_singleton->get_definition_manager().get_ui_manager().get_scene_by_identifier(godot_to_std_string(gui_scene));
ERR_FAIL_NULL_V_MSG(scene, nullptr, vformat("Failed to find GUI scene %s", gui_scene));
GUI::Element const* element = scene->get_scene_element_by_identifier(godot_to_std_string(gui_element));
ERR_FAIL_NULL_V_MSG(element, nullptr, vformat("Failed to find GUI element %s in GUI scene %s", gui_element, gui_scene));
@@ -54,7 +54,7 @@ GUI::Position const* UITools::get_gui_position(String const& gui_scene, String c
GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, nullptr);
GUI::Scene const* scene =
- game_singleton->get_game_manager().get_ui_manager().get_scene_by_identifier(godot_to_std_string(gui_scene));
+ game_singleton->get_definition_manager().get_ui_manager().get_scene_by_identifier(godot_to_std_string(gui_scene));
ERR_FAIL_NULL_V_MSG(scene, nullptr, vformat("Failed to find GUI scene %s", gui_scene));
GUI::Position const* position = scene->get_scene_position_by_identifier(godot_to_std_string(gui_position));
ERR_FAIL_NULL_V_MSG(position, nullptr, vformat("Failed to find GUI position %s in GUI scene %s", gui_position, gui_scene));