diff options
-rw-r--r-- | .vscode/launch.json | 20 | ||||
-rw-r--r-- | build_scons_and_execute_windows.bat | 4 | ||||
-rw-r--r-- | delete_obj_files_windows.bat | 1 | ||||
m--------- | deps/openvic-dataloader | 0 | ||||
-rw-r--r-- | src/openvic-simulation/map/Map.cpp | 71 | ||||
-rw-r--r-- | src/openvic-simulation/map/Province.hpp | 1 |
6 files changed, 51 insertions, 46 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index da3dff4..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "(Windows) Launch", - "type": "cppvsdbg", - "request": "launch", - "program": "${workspaceFolder}/bin/openvic-simulation.headless.windows.template_debug.dev.x86_64.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [], - "console": "integratedTerminal" - } - - ] -}
\ No newline at end of file diff --git a/build_scons_and_execute_windows.bat b/build_scons_and_execute_windows.bat deleted file mode 100644 index e48c2a2..0000000 --- a/build_scons_and_execute_windows.bat +++ /dev/null @@ -1,4 +0,0 @@ -scons -cd bin -openvic-simulation.headless.windows.template_debug.x86_64.exe -cd ../
\ No newline at end of file diff --git a/delete_obj_files_windows.bat b/delete_obj_files_windows.bat deleted file mode 100644 index bf32282..0000000 --- a/delete_obj_files_windows.bat +++ /dev/null @@ -1 +0,0 @@ -del /S *.obj
\ No newline at end of file diff --git a/deps/openvic-dataloader b/deps/openvic-dataloader -Subproject ce1f1e5fe32ed0856bd2b6df5136dad3f6bc991 +Subproject ebf9972d080e2120a9aa9bd15af8150dc2d5a3b diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp index 5d8c6e2..b272f1f 100644 --- a/src/openvic-simulation/map/Map.cpp +++ b/src/openvic-simulation/map/Map.cpp @@ -500,34 +500,41 @@ bool Map::load_map_images(fs::path const& province_path, fs::path const& terrain std::vector<fixed_point_map_t<TerrainType const*>> terrain_type_pixels_list(provinces.size()); bool ret = true; std::unordered_set<colour_t> unrecognised_province_colours; + + std::vector<fixed_point_t> pixels_per_province(provinces.size()); + std::vector<fixed_point_t> x_sum_per_province(provinces.size()); + std::vector<fixed_point_t> y_sum_per_province(provinces.size()); for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { - const size_t idx = x + y * width; + const size_t pixel_index = x + y * width; + const colour_t province_colour = colour_at(province_data, pixel_index); - const colour_t province_colour = colour_at(province_data, idx); if (x > 0) { - const size_t jdx = idx - 1; + const size_t jdx = pixel_index - 1; if (colour_at(province_data, jdx) == province_colour) { - province_shape_image[idx].index = province_shape_image[jdx].index; + province_shape_image[pixel_index].index = province_shape_image[jdx].index; goto set_terrain; } } + if (y > 0) { - const size_t jdx = idx - width; + const size_t jdx = pixel_index - width; if (colour_at(province_data, jdx) == province_colour) { - province_shape_image[idx].index = province_shape_image[jdx].index; + province_shape_image[pixel_index].index = province_shape_image[jdx].index; goto set_terrain; } } + { - const Province::index_t index = get_index_from_colour(province_colour); - if (index != Province::NULL_INDEX) { - province_checklist[index - 1] = true; - province_shape_image[idx].index = index; + const Province::index_t province_index = get_index_from_colour(province_colour); + if (province_index != Province::NULL_INDEX) { + province_checklist[province_index - 1] = true; + province_shape_image[pixel_index].index = province_index; goto set_terrain; } } + if (!unrecognised_province_colours.contains(province_colour)) { unrecognised_province_colours.insert(province_colour); if (detailed_errors) { @@ -536,20 +543,30 @@ bool Map::load_map_images(fs::path const& province_path, fs::path const& terrain ); } } - province_shape_image[idx].index = Province::NULL_INDEX; + + province_shape_image[pixel_index].index = Province::NULL_INDEX; set_terrain: - const TerrainTypeMapping::index_t terrain = terrain_data[idx]; + const Province::index_t province_index = province_shape_image[pixel_index].index; + if (province_index != Province::NULL_INDEX) { + const uint16_t array_index = province_index - 1; + pixels_per_province[array_index]++; + x_sum_per_province[array_index] += x; + y_sum_per_province[array_index] += y; + } + + const TerrainTypeMapping::index_t terrain = terrain_data[pixel_index]; TerrainTypeMapping const* mapping = terrain_type_manager.get_terrain_type_mapping_for(terrain); if (mapping != nullptr) { - if (province_shape_image[idx].index != Province::NULL_INDEX) { - terrain_type_pixels_list[province_shape_image[idx].index - 1][&mapping->get_type()]++; + + if (province_index != Province::NULL_INDEX) { + terrain_type_pixels_list[province_index - 1][&mapping->get_type()]++; } - province_shape_image[idx].terrain = + province_shape_image[pixel_index].terrain = mapping->get_has_texture() && terrain < terrain_type_manager.get_terrain_texture_limit() ? terrain + 1 : 0; } else { - province_shape_image[idx].terrain = 0; + province_shape_image[pixel_index].terrain = 0; } } } @@ -559,11 +576,22 @@ bool Map::load_map_images(fs::path const& province_path, fs::path const& terrain } size_t missing = 0; - for (size_t idx = 0; idx < province_checklist.size(); ++idx) { - Province* province = provinces.get_item_by_index(idx); - const fixed_point_map_const_iterator_t<TerrainType const*> largest = get_largest_item(terrain_type_pixels_list[idx]); - province->default_terrain_type = largest != terrain_type_pixels_list[idx].end() ? largest->first : nullptr; - province->on_map = province_checklist[idx]; + for (size_t array_index = 0; array_index < province_checklist.size(); ++array_index) { + Province* province = provinces.get_item_by_index(array_index); + const fixed_point_t pixel_count = pixels_per_province[array_index]; + if(pixel_count > 0) { + const fixed_point_t x = x_sum_per_province[array_index] / pixel_count; + const fixed_point_t y = y_sum_per_province[array_index] / pixel_count; + const fvec2_t center { x, y }; + province->positions.center = center; + } + else { + Logger::warning("Province ",province->index," has no pixels"); + } + + const fixed_point_map_const_iterator_t<TerrainType const*> largest = get_largest_item(terrain_type_pixels_list[array_index]); + province->default_terrain_type = largest != terrain_type_pixels_list[array_index].end() ? largest->first : nullptr; + province->on_map = province_checklist[array_index]; if (!province->on_map) { if (detailed_errors) { Logger::warning("Province missing from shape image: ", province->to_string()); @@ -595,6 +623,7 @@ bool Map::_generate_province_adjacencies() { for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { Province* cur = get_province_by_index(province_shape_image[x + y * width].index); + if (cur != nullptr) { changed |= generate_adjacency(cur, (x + 1) % width, y); if (y + 1 < height) { diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index 1eea458..37ecdaa 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -43,6 +43,7 @@ namespace OpenVic { }; struct province_positions_t { + fvec2_t center; fvec2_t text; fixed_point_t text_rotation; fixed_point_t text_scale; |