aboutsummaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
m---------extension/deps/openvic-simulation0
-rw-r--r--extension/src/GameSingleton.cpp12
-rw-r--r--extension/src/GameSingleton.hpp5
-rw-r--r--extension/src/LoadGameCompatibility.cpp95
-rw-r--r--extension/src/LoadGameOpenVic.cpp4
-rw-r--r--extension/src/Utilities.hpp4
6 files changed, 19 insertions, 101 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation
-Subproject 366f1b3941315641bdcb0ee98465b4d2134eee8
+Subproject 7772f8871348b7b52cb0a478bb76df68d8799a0
diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp
index 6ccde8d..b435f05 100644
--- a/extension/src/GameSingleton.cpp
+++ b/extension/src/GameSingleton.cpp
@@ -2,7 +2,7 @@
#include <godot_cpp/variant/utility_functions.hpp>
-#include "openvic/utility/Logger.hpp"
+#include "openvic-simulation/utility/Logger.hpp"
#include "Utilities.hpp"
@@ -124,10 +124,8 @@ GameSingleton::~GameSingleton() {
}
Error GameSingleton::setup_game() {
- return_t ret = game_manager.setup();
- if (dataloader.load_pop_history(game_manager, "history/pops/" + game_manager.get_today().to_string()) != SUCCESS) {
- ret = FAILURE;
- }
+ bool ret = game_manager.setup();
+ ret &= dataloader.load_pop_history(game_manager, "history/pops/" + game_manager.get_today().to_string());
return ERR(ret);
}
@@ -297,7 +295,7 @@ Error GameSingleton::_update_colour_image() {
colour_data_array.resize(colour_data_array_size);
Error err = OK;
- if (game_manager.map.generate_mapmode_colours(mapmode_index, colour_data_array.ptrw()) != SUCCESS)
+ if (!game_manager.map.generate_mapmode_colours(mapmode_index, colour_data_array.ptrw()))
err = FAILED;
static constexpr int32_t PROVINCE_INDEX_SQRT = 1 << (sizeof(Province::index_t) * 4);
@@ -348,7 +346,7 @@ void GameSingleton::set_selected_province(int32_t index) {
}
Error GameSingleton::expand_building(int32_t province_index, String const& building_type_identifier) {
- if (game_manager.expand_building(province_index, godot_to_std_string(building_type_identifier)) != SUCCESS) {
+ if (!game_manager.expand_building(province_index, godot_to_std_string(building_type_identifier))) {
UtilityFunctions::push_error("Failed to expand ", building_type_identifier, " at province index ", province_index);
return FAILED;
}
diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp
index eb332f4..ac9d160 100644
--- a/extension/src/GameSingleton.hpp
+++ b/extension/src/GameSingleton.hpp
@@ -3,8 +3,8 @@
#include <godot_cpp/classes/image_texture.hpp>
#include <godot_cpp/classes/texture2d_array.hpp>
-#include "openvic/GameManager.hpp"
-#include "openvic/dataloader/Dataloader.hpp"
+#include "openvic-simulation/GameManager.hpp"
+#include "openvic-simulation/dataloader/Dataloader.hpp"
namespace OpenVic {
@@ -46,7 +46,6 @@ namespace OpenVic {
godot::Error _generate_terrain_texture_array();
godot::Error _load_map_images(godot::String const& province_image_path, godot::String const& terrain_image_path, bool flip_vertical = false);
- godot::Error _load_province_identifier_file_compatibility_mode(godot::String const& file_path);
godot::Error _load_terrain_variants_compatibility_mode(godot::String const& terrain_image_path, godot::String const& terrain_texturesheet_path);
/* Generate the province_colour_texture from the current mapmode.
diff --git a/extension/src/LoadGameCompatibility.cpp b/extension/src/LoadGameCompatibility.cpp
index 3da5f08..bed7442 100644
--- a/extension/src/LoadGameCompatibility.cpp
+++ b/extension/src/LoadGameCompatibility.cpp
@@ -3,89 +3,17 @@
#include <godot_cpp/classes/file_access.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
-#include "openvic/utility/BMP.hpp"
+#include "openvic-simulation/utility/BMP.hpp"
#include "Utilities.hpp"
using namespace godot;
using namespace OpenVic;
-Error GameSingleton::_load_province_identifier_file_compatibility_mode(String const& file_path) {
- UtilityFunctions::print("Loading compatibility mode province identifier file: ", file_path);
-
- const Ref<FileAccess> file = FileAccess::open(file_path, FileAccess::ModeFlags::READ);
- Error err = FileAccess::get_open_error();
- if (err != OK || file.is_null()) {
- UtilityFunctions::push_error("Failed to load compatibility mode province identifier file: ", file_path);
- if (err == OK) err = FAILED;
- } else {
- int line_number = 0;
- while (!file->eof_reached()) {
- const PackedStringArray line = file->get_csv_line(";");
- line_number++;
-
- if (line.is_empty() || (line.size() == 1 && line[0].is_empty()))
- continue;
-
- if (line_number < 2) continue; // skip header line
- std::string identifier;
- colour_t colour = NULL_COLOUR;
- if (line.size() > 0) {
- identifier = godot_to_std_string(line[0]);
- if (identifier.empty()) {
- identifier = std::to_string(game_manager.map.get_province_count() + 1);
- } else {
- bool successful = false;
- const uint64_t val = StringUtils::string_to_uint64(identifier, &successful, 10);
- if (successful) {
- if (val <= Province::NULL_INDEX || val > Province::MAX_INDEX) {
- UtilityFunctions::push_error("Invalid province index ", line[0], " (out of valid range ", Province::NULL_INDEX, " < index <= ", Province::MAX_INDEX, ")");
- err = FAILED;
- }
- } else {
- UtilityFunctions::push_error("Invalid province index ", line[0], " (not a valid integer)");
- err = FAILED;
- }
- }
- for (int i = 1; i < 4; ++i) {
- if (line.size() > i) {
- if (line[i].is_valid_int()) {
- const int64_t int_val = line[i].to_int();
- if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
- colour = (colour << 8) | int_val;
- continue;
- }
- } else if (line[i].is_valid_float()) {
- const double double_val = line[i].to_float();
- if (std::trunc(double_val) == double_val) {
- const int64_t int_val = double_val;
- if (int_val >= NULL_COLOUR && int_val <= FULL_COLOUR) {
- colour = (colour << 8) | int_val;
- continue;
- }
- }
- }
- }
- colour = NULL_COLOUR;
- break;
- }
- }
- if (identifier.empty() || colour == NULL_COLOUR) {
- UtilityFunctions::push_error("Invalid province ID-colour entry \"", line, "\" on line ", line_number, " in file: ", file_path);
- err = FAILED;
- continue;
- }
- if (game_manager.map.add_province(identifier, colour) != SUCCESS) err = FAILED;
- }
- }
- game_manager.map.lock_provinces();
- return err;
-}
-
Error GameSingleton::_load_terrain_variants_compatibility_mode(String const& terrain_image_path, String const& terrain_texturesheet_path) {
// Read BMP's palette to determine terrain variant colours which texture they're associated with
BMP bmp;
- if (bmp.open(godot_to_std_string(terrain_image_path).c_str()) != SUCCESS || bmp.read_header() != SUCCESS || bmp.read_palette() != SUCCESS) {
+ if (!(bmp.open(godot_to_std_string(terrain_image_path).c_str()) && bmp.read_header() && bmp.read_palette())) {
UtilityFunctions::push_error("Failed to read BMP palette from compatibility mode terrain image: ", terrain_image_path);
return FAILED;
}
@@ -111,10 +39,11 @@ Error GameSingleton::_load_terrain_variants_compatibility_mode(String const& ter
const int32_t slice_size = sheet_width / SHEET_DIMS;
{
+ static constexpr colour_t TERRAIN_WATER_INDEX_COLOUR = 0xFFFFFF;
Ref<Image> water_image = Image::create(slice_size, slice_size, false, terrain_sheet->get_format());
ERR_FAIL_NULL_V_EDMSG(water_image, FAILED, "Failed to create water terrain image");
water_image->fill({ 0.1f, 0.1f, 0.5f });
- terrain_variants.add_item({ "terrain_water", 0xFFFFFF, water_image });
+ terrain_variants.add_item({ "terrain_water", TERRAIN_WATER_INDEX_COLOUR, water_image });
}
Error err = OK;
for (int32_t idx = 0; idx < PALETTE_SIZE; ++idx) {
@@ -125,7 +54,7 @@ Error GameSingleton::_load_terrain_variants_compatibility_mode(String const& ter
err = FAILED;
continue;
}
- if (terrain_variants.add_item({ "terrain_" + std::to_string(idx), palette[idx], terrain_image }) != SUCCESS) err = FAILED;
+ if (!terrain_variants.add_item({ "terrain_" + std::to_string(idx), palette[idx], terrain_image })) err = FAILED;
}
terrain_variants.lock();
if (_generate_terrain_texture_array() != OK) return FAILED;
@@ -133,7 +62,6 @@ Error GameSingleton::_load_terrain_variants_compatibility_mode(String const& ter
}
Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& file_paths) {
- static const std::filesystem::path province_identifier_file = "map/definition.csv";
static const std::filesystem::path province_image_file = "map/provinces.bmp";
static const std::filesystem::path terrain_image_file = "map/terrain.bmp";
static const std::filesystem::path terrain_texture_file = "map/terrain/texturesheet.tga";
@@ -145,23 +73,16 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi
Error err = OK;
- if (dataloader.set_roots(roots) != SUCCESS) {
+ if (!dataloader.set_roots(roots)) {
Logger::error("Failed to set dataloader roots!");
err = FAILED;
}
- if (dataloader.load_defines(game_manager) != SUCCESS) {
+ if (!dataloader.load_defines(game_manager)) {
UtilityFunctions::push_error("Failed to load defines!");
err = FAILED;
}
- if (_load_province_identifier_file_compatibility_mode(
- std_to_godot_string(dataloader.lookup_file(province_identifier_file).string())
- ) != OK) {
- UtilityFunctions::push_error("Failed to load province identifiers!");
- err = FAILED;
- }
- game_manager.map.lock_water_provinces();
game_manager.map.lock_regions();
if (_load_terrain_variants_compatibility_mode(
std_to_godot_string(dataloader.lookup_file(terrain_image_file).string()),
@@ -177,7 +98,7 @@ 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() != SUCCESS) {
+ if (!game_manager.load_hardcoded_defines()) {
UtilityFunctions::push_error("Failed to hardcoded defines!");
err = FAILED;
}
diff --git a/extension/src/LoadGameOpenVic.cpp b/extension/src/LoadGameOpenVic.cpp
index 3d3d6c5..fafc864 100644
--- a/extension/src/LoadGameOpenVic.cpp
+++ b/extension/src/LoadGameOpenVic.cpp
@@ -86,8 +86,8 @@ Error GameSingleton::_load_map_images(String const& province_image_path, String
if (err != OK) return err;
// Generate interleaved province and terrain ID image
- if (game_manager.map.generate_province_shape_image(province_dims.x, province_dims.y, province_image->get_data().ptr(),
- terrain_image->get_data().ptr(), terrain_variant_map, false) != SUCCESS) err = FAILED;
+ if (!game_manager.map.generate_province_shape_image(province_dims.x, province_dims.y, province_image->get_data().ptr(),
+ terrain_image->get_data().ptr(), terrain_variant_map, false)) err = FAILED;
static constexpr int32_t GPU_DIM_LIMIT = 0x3FFF;
// For each dimension of the image, this finds the small number of equal subdivisions required get the individual texture dims under GPU_DIM_LIMIT
diff --git a/extension/src/Utilities.hpp b/extension/src/Utilities.hpp
index fedaa6b..afd65c0 100644
--- a/extension/src/Utilities.hpp
+++ b/extension/src/Utilities.hpp
@@ -2,9 +2,9 @@
#include <godot_cpp/classes/image.hpp>
-#include "openvic/types/Colour.hpp"
+#include "openvic-simulation/types/Colour.hpp"
-#define ERR(x) ((x) == SUCCESS ? OK : FAILED)
+#define ERR(x) ((x) ? OK : FAILED)
namespace OpenVic {