diff options
author | Hop311 <hop3114@gmail.com> | 2023-09-02 13:55:36 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-09-09 22:57:26 +0200 |
commit | c715187bffa8c84428acf3631e3d03c088a719d9 (patch) | |
tree | b880594195ad803fe716c9c6184591b8b47fa42c | |
parent | aa49dbbb3cf9dbff18c08245b0e46a9943df9b15 (diff) |
Followup big dataloader commit
m--------- | extension/deps/openvic-simulation | 0 | ||||
-rw-r--r-- | extension/src/GameSingleton.cpp | 1 | ||||
-rw-r--r-- | extension/src/GameSingleton.hpp | 4 | ||||
-rw-r--r-- | extension/src/LoadGameCompatibility.cpp | 31 | ||||
-rw-r--r-- | extension/src/LoadGameOpenVic.cpp | 6 | ||||
-rw-r--r-- | game/localisation/en_GB/mapmodes.csv | 1 | ||||
-rw-r--r-- | game/src/Game/GameStart.gd | 28 |
7 files changed, 44 insertions, 27 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation -Subproject d20459988118dc18ddc9feb12b09f5e65ad03b2 +Subproject 366f1b3941315641bdcb0ee98465b4d2134eee8 diff --git a/extension/src/GameSingleton.cpp b/extension/src/GameSingleton.cpp index 07be9aa..6ccde8d 100644 --- a/extension/src/GameSingleton.cpp +++ b/extension/src/GameSingleton.cpp @@ -23,6 +23,7 @@ GameSingleton* GameSingleton::singleton = nullptr; void GameSingleton::_bind_methods() { ClassDB::bind_static_method("GameSingleton", D_METHOD("setup_logger"), &GameSingleton::setup_logger); ClassDB::bind_method(D_METHOD("load_defines_compatibility_mode", "file_paths"), &GameSingleton::load_defines_compatibility_mode); + ClassDB::bind_method(D_METHOD("lookup_file", "path"), &GameSingleton::lookup_file); ClassDB::bind_method(D_METHOD("setup_game"), &GameSingleton::setup_game); ClassDB::bind_method(D_METHOD("get_province_index_from_uv_coords", "coords"), &GameSingleton::get_province_index_from_uv_coords); diff --git a/extension/src/GameSingleton.hpp b/extension/src/GameSingleton.hpp index a484520..eb332f4 100644 --- a/extension/src/GameSingleton.hpp +++ b/extension/src/GameSingleton.hpp @@ -7,6 +7,7 @@ #include "openvic/dataloader/Dataloader.hpp" namespace OpenVic { + struct TerrainVariant : HasIdentifierAndColour { friend class GameSingleton; @@ -23,6 +24,7 @@ namespace OpenVic { godot::Ref<godot::Image> get_image() const; }; + class GameSingleton : public godot::Object { GDCLASS(GameSingleton, godot::Object) @@ -76,6 +78,8 @@ namespace OpenVic { */ godot::Error load_defines_compatibility_mode(godot::PackedStringArray const& file_paths); + godot::String lookup_file(godot::String const& path) const; + /* Post-load/restart game setup - reset the game to post-load state * and (re)generate starting data, e.g. buildings. */ diff --git a/extension/src/LoadGameCompatibility.cpp b/extension/src/LoadGameCompatibility.cpp index 1567977..3da5f08 100644 --- a/extension/src/LoadGameCompatibility.cpp +++ b/extension/src/LoadGameCompatibility.cpp @@ -28,14 +28,24 @@ Error GameSingleton::_load_province_identifier_file_compatibility_mode(String co continue; if (line_number < 2) continue; // skip header line - Province::index_t id = Province::NULL_INDEX; + std::string identifier; colour_t colour = NULL_COLOUR; if (line.size() > 0) { - if (line[0].is_empty()) { - id = game_manager.map.get_province_count() + 1; - } else if (line[0].is_valid_int()) { - const int64_t val = line[0].to_int(); - if (val > Province::NULL_INDEX && val <= Province::MAX_INDEX) id = val; + 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) { @@ -60,12 +70,12 @@ Error GameSingleton::_load_province_identifier_file_compatibility_mode(String co break; } } - if (id == Province::NULL_INDEX || colour == NULL_COLOUR) { + 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(std::to_string(id), colour) != SUCCESS) err = FAILED; + if (game_manager.map.add_province(identifier, colour) != SUCCESS) err = FAILED; } } game_manager.map.lock_provinces(); @@ -167,10 +177,13 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi UtilityFunctions::push_error("Failed to load map images!"); err = FAILED; } - game_manager.good_manager.lock_goods(); if (game_manager.load_hardcoded_defines() != SUCCESS) { UtilityFunctions::push_error("Failed to hardcoded defines!"); err = FAILED; } return err; } + +String GameSingleton::lookup_file(String const& path) const { + return std_to_godot_string(dataloader.lookup_file(godot_to_std_string(path)).string()); +} diff --git a/extension/src/LoadGameOpenVic.cpp b/extension/src/LoadGameOpenVic.cpp index b262a28..3d3d6c5 100644 --- a/extension/src/LoadGameOpenVic.cpp +++ b/extension/src/LoadGameOpenVic.cpp @@ -11,19 +11,19 @@ using namespace OpenVic; Error GameSingleton::_generate_terrain_texture_array() { Error err = OK; - if (terrain_variants.get_item_count() == 0) { + if (terrain_variants.size() == 0) { UtilityFunctions::push_error("Failed to load terrain textures!"); return FAILED; } // TerrainVariant count is limited by the data type representing it in the map image - if (terrain_variants.get_item_count() > TerrainVariant::MAX_TERRIN_VARIANT_COUNT) { + if (terrain_variants.size() > TerrainVariant::MAX_TERRIN_VARIANT_COUNT) { UtilityFunctions::push_error("Too many terrain textures - all after the first ", static_cast<uint64_t>(TerrainVariant::MAX_TERRIN_VARIANT_COUNT), " will be ignored"); err = FAILED; } Array terrain_images; - for (size_t i = 0; i < terrain_variants.get_item_count() && i < TerrainVariant::MAX_TERRIN_VARIANT_COUNT; ++i) { + for (size_t i = 0; i < terrain_variants.size() && i < TerrainVariant::MAX_TERRIN_VARIANT_COUNT; ++i) { TerrainVariant const& var = *terrain_variants.get_item_by_index(i); terrain_variant_map[var.get_colour()] = i; terrain_images.append(var.get_image()); diff --git a/game/localisation/en_GB/mapmodes.csv b/game/localisation/en_GB/mapmodes.csv index 8fa5798..bcb466f 100644 --- a/game/localisation/en_GB/mapmodes.csv +++ b/game/localisation/en_GB/mapmodes.csv @@ -8,3 +8,4 @@ mapmode_rgo;RGO mapmode_infrastructure;Infrastructure mapmode_population;Population Density mapmode_culture;Nationality +mapmode_religion;Religion diff --git a/game/src/Game/GameStart.gd b/game/src/Game/GameStart.gd index a5524d6..422a42a 100644 --- a/game/src/Game/GameStart.gd +++ b/game/src/Game/GameStart.gd @@ -25,12 +25,7 @@ func _ready() -> void: loading_screen.start_loading_screen(_initialize_game) -# REQUIREMENTS -# * FS-333, FS-334, FS-335, FS-341 -func _initialize_game() -> void: - GameSingleton.setup_logger() - loading_screen.try_update_loading_screen(5) - +func _load_compatibility_mode(): # Set this to your Vic2 install dir or a mod's dir to enable compatibility mode # (this won't work for mods which rely on vanilla map assets, copy missing assets # into the mod's dir for a temporary fix) @@ -48,21 +43,24 @@ func _initialize_game() -> void: # Example for adding mod paths #compatibility_mode_paths.push_back("C:/Program Files (x86)/Steam/steamapps/common/Victoria 2/mod/TGC") + if GameSingleton.load_defines_compatibility_mode(compatibility_mode_paths) != OK: + push_error("Errors loading game defines!") + +# REQUIREMENTS +# * FS-333, FS-334, FS-335, FS-341 +func _initialize_game() -> void: var start := Time.get_ticks_usec() + loading_screen.try_update_loading_screen(0) + GameSingleton.setup_logger() - loading_screen.try_update_loading_screen(15) - loading_screen.try_update_loading_screen(25) Localisation.initialize() - loading_screen.try_update_loading_screen(45) - loading_screen.try_update_loading_screen(50, true) + loading_screen.try_update_loading_screen(15, true) - # TODO: Loading takes way too long to keep the LoadingScreen at 50% - # Should either split this up or seperately multithread the compatibility mode loader - # Or both and emit a signal that allows us to add percentages to the LoadingScreen - if GameSingleton.load_defines_compatibility_mode(compatibility_mode_paths) != OK: - push_error("Errors loading game defines!") + _load_compatibility_mode() + loading_screen.try_update_loading_screen(75, true) loading_screen.try_update_loading_screen(100) + var end := Time.get_ticks_usec() print("Loading took ", float(end - start) / 1000000, " seconds") |