aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-06-18 21:30:42 +0200
committer GitHub <noreply@github.com>2024-06-18 21:30:42 +0200
commitace94963c36fb21288dbaf59b0191223adae6521 (patch)
tree3eb84f934534099aa89cfcbe67fd1098869a1ef0 /extension/src/openvic-extension/singletons
parent3dd525092e3a6027f20f0a1afdf8e871a9eecd34 (diff)
parent508a3ad82c9e20092ede373cdff7ec8d4ed9e881 (diff)
Merge pull request #233 from OpenVicProject/map-instance
Update to use Map instance
Diffstat (limited to 'extension/src/openvic-extension/singletons')
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.cpp58
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp2
-rw-r--r--extension/src/openvic-extension/singletons/ModelSingleton.cpp4
-rw-r--r--extension/src/openvic-extension/singletons/PopulationMenu.cpp12
4 files changed, 39 insertions, 37 deletions
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp
index 7576d0c..2e330ac 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp
@@ -124,7 +124,7 @@ Error GameSingleton::setup_game(int32_t 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);
- for (ProvinceInstance& province : game_manager.get_map().get_province_instances()) {
+ for (ProvinceInstance& province : game_manager.get_map_instance().get_province_instances()) {
province.set_crime(
game_manager.get_crime_manager().get_crime_modifier_by_index(
(province.get_province_definition().get_index() - 1)
@@ -142,19 +142,19 @@ Error GameSingleton::setup_game(int32_t bookmark_index) {
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().get_province_index_at(Utilities::from_godot_ivec2(pos));
+ return game_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().get_width();
+ return game_manager.get_map_definition().get_width();
}
int32_t GameSingleton::get_map_height() const {
- return game_manager.get_map().get_height();
+ return game_manager.get_map_definition().get_height();
}
Vector2i GameSingleton::get_map_dims() const {
- return Utilities::to_godot_ivec2(game_manager.get_map().get_dims());
+ return Utilities::to_godot_ivec2(game_manager.get_map_definition().get_dims());
}
float GameSingleton::get_map_aspect_ratio() const {
@@ -214,24 +214,28 @@ Ref<ImageTexture> GameSingleton::get_province_colour_texture() const {
}
Error GameSingleton::_update_colour_image() {
- Map const& map = game_manager.get_map();
+ MapDefinition const& map_definition = game_manager.get_map_definition();
ERR_FAIL_COND_V_MSG(
- !map.province_definitions_are_locked(), FAILED, "Cannot generate province colour image before provinces are locked!"
+ !map_definition.province_definitions_are_locked(), FAILED,
+ "Cannot generate province colour image before provinces are locked!"
);
/* We reshape the list of colours into a square, as each texture dimensions cannot exceed 16384. */
static constexpr int32_t PROVINCE_INDEX_SQRT = 1 << (sizeof(ProvinceDefinition::index_t) * CHAR_BIT / 2);
static constexpr int32_t colour_image_width = PROVINCE_INDEX_SQRT * sizeof(Mapmode::base_stripe_t) / sizeof(colour_argb_t);
/* Province count + null province, rounded up to next multiple of PROVINCE_INDEX_SQRT.
- * Rearranged from: (map.get_province_count() + 1) + (PROVINCE_INDEX_SQRT - 1) */
- const int32_t colour_image_height = (map.get_province_definition_count() + PROVINCE_INDEX_SQRT) / PROVINCE_INDEX_SQRT;
+ * Rearranged from: (map_definition.get_province_definition_count() + 1) + (PROVINCE_INDEX_SQRT - 1) */
+ const int32_t colour_image_height =
+ (map_definition.get_province_definition_count() + PROVINCE_INDEX_SQRT) / PROVINCE_INDEX_SQRT;
static PackedByteArray colour_data_array;
const int64_t colour_data_array_size = colour_image_width * colour_image_height * sizeof(colour_argb_t);
ERR_FAIL_COND_V(colour_data_array.resize(colour_data_array_size) != OK, FAILED);
Error err = OK;
- if (!map.generate_mapmode_colours(mapmode_index, colour_data_array.ptrw())) {
+ if (!game_manager.get_mapmode_manager().generate_mapmode_colours(
+ game_manager.get_map_instance(), mapmode_index, colour_data_array.ptrw()
+ )) {
err = FAILED;
}
@@ -258,11 +262,13 @@ 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();
+
TypedArray<Dictionary> ret;
- ERR_FAIL_COND_V(ret.resize(game_manager.get_map().get_province_definition_count()) != OK, {});
+ ERR_FAIL_COND_V(ret.resize(map_definition.get_province_definition_count()) != OK, {});
- for (int32_t index = 0; index < game_manager.get_map().get_province_definition_count(); ++index) {
- ProvinceDefinition const& province = game_manager.get_map().get_province_definitions()[index];
+ for (int32_t index = 0; index < map_definition.get_province_definition_count(); ++index) {
+ ProvinceDefinition const& province = map_definition.get_province_definitions()[index];
Dictionary province_dict;
@@ -286,11 +292,11 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const {
}
int32_t GameSingleton::get_mapmode_count() const {
- return game_manager.get_map().get_mapmode_count();
+ return game_manager.get_mapmode_manager().get_mapmode_count();
}
String GameSingleton::get_mapmode_identifier(int32_t index) const {
- Mapmode const* mapmode = game_manager.get_map().get_mapmode_by_index(index);
+ Mapmode const* mapmode = game_manager.get_mapmode_manager().get_mapmode_by_index(index);
if (mapmode != nullptr) {
return std_view_to_godot_string(mapmode->get_identifier());
}
@@ -298,7 +304,7 @@ String GameSingleton::get_mapmode_identifier(int32_t index) const {
}
Error GameSingleton::set_mapmode(String const& identifier) {
- Mapmode const* mapmode = game_manager.get_map().get_mapmode_by_identifier(godot_to_std_string(identifier));
+ Mapmode const* mapmode = game_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();
@@ -309,16 +315,16 @@ 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_map().get_mapmode_by_index(mapmode_index);
+ Mapmode const* mapmode = game_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().get_selected_province_index();
+ return game_manager.get_map_instance().get_selected_province_index();
}
void GameSingleton::set_selected_province(int32_t index) {
- game_manager.get_map().set_selected_province(index);
+ game_manager.get_map_instance().set_selected_province(index);
_update_colour_image();
emit_signal(_signal_province_selected(), index);
}
@@ -336,10 +342,7 @@ Error GameSingleton::_load_map_images() {
Error err = OK;
- const Vector2i province_dims {
- static_cast<int32_t>(game_manager.get_map().get_width()),
- static_cast<int32_t>(game_manager.get_map().get_height())
- };
+ const Vector2i province_dims = get_map_dims();
// For each dimension of the image, this finds the small number of equal subdivisions
// required get the individual texture dims under GPU_DIM_LIMIT
@@ -350,10 +353,11 @@ Error GameSingleton::_load_map_images() {
}
}
- Map::shape_pixel_t const* province_shape_data = game_manager.get_map().get_province_shape_image().data();
+ MapDefinition::shape_pixel_t const* province_shape_data =
+ game_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(Map::shape_pixel_t);
+ const int64_t subdivision_width = divided_dims.x * sizeof(MapDefinition::shape_pixel_t);
const int64_t subdivision_size = subdivision_width * divided_dims.y;
TypedArray<Image> province_shape_images;
@@ -588,10 +592,6 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
UtilityFunctions::push_error("Failed to load map images!");
err = FAILED;
}
- if (!game_manager.load_hardcoded_defines()) {
- UtilityFunctions::push_error("Failed to hardcoded defines!");
- 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!");
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index b304b69..d382d75 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -188,7 +188,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().get_province_instance_by_index(index);
+ ProvinceInstance const* province = game_manager->get_map_instance().get_province_instance_by_index(index);
if (province == nullptr) {
return {};
}
diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp
index 152a7f4..091bd8a 100644
--- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp
@@ -311,7 +311,7 @@ TypedArray<Dictionary> ModelSingleton::get_units() const {
TypedArray<Dictionary> ret;
- for (ProvinceInstance const& province : game_singleton->get_game_manager().get_map().get_province_instances()) {
+ for (ProvinceInstance const& province : game_singleton->get_game_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(
@@ -445,7 +445,7 @@ TypedArray<Dictionary> ModelSingleton::get_buildings() const {
TypedArray<Dictionary> ret;
- for (ProvinceInstance const& province : game_singleton->get_game_manager().get_map().get_province_instances()) {
+ for (ProvinceInstance const& province : game_singleton->get_game_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 4aeedae..3144a1a 100644
--- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp
+++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp
@@ -20,8 +20,8 @@ void MenuSingleton::_population_menu_update_provinces() {
population_menu.province_list_entries.clear();
population_menu.visible_province_list_entries = 0;
- Map const& map = game_manager->get_map();
- ERR_FAIL_COND(!map.province_instances_are_locked());
+ MapInstance const& map_instance = game_manager->get_map_instance();
+ ERR_FAIL_COND(!map_instance.province_instances_are_locked());
for (Country const* country : {
// Example country
@@ -32,7 +32,7 @@ void MenuSingleton::_population_menu_update_provinces() {
population_menu.province_list_entries.emplace_back(population_menu_t::country_entry_t { *country });
population_menu.visible_province_list_entries++;
- for (StateSet const& state_set : map.get_state_manager().get_state_sets()) {
+ for (StateSet const& state_set : map_instance.get_state_manager().get_state_sets()) {
for (State const& state : state_set.get_states()) {
population_menu.province_list_entries.emplace_back(population_menu_t::state_entry_t { state });
@@ -163,7 +163,7 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int
return true;
}
- } entry_visitor { *this, start, count, game_manager->get_map().get_total_map_population() };
+ } entry_visitor { *this, start, count, game_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])) {
@@ -259,7 +259,9 @@ 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);
- ERR_FAIL_COND_V(province_index <= 0 || province_index > game_manager->get_map().get_province_instance_count(), FAILED);
+ ERR_FAIL_COND_V(
+ province_index <= 0 || province_index > game_manager->get_map_instance().get_province_instance_count(), FAILED
+ );
struct entry_visitor_t {