From 291022316a4a3c742be92abd0d2b94256df60143 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sun, 3 Dec 2023 12:33:37 -0500 Subject: Update to Godot 4.2 Stable Release Fix compiledb Fix memory leak caused by LoadLocalisation::add_message's translations static variable --- .github/workflows/builds.yml | 2 +- README.md | 4 ++-- SConstruct | 10 +++++----- extension/src/openvic-extension/singletons/GameSingleton.cpp | 5 ++++- .../src/openvic-extension/singletons/LoadLocalisation.cpp | 1 - .../src/openvic-extension/singletons/LoadLocalisation.hpp | 4 +++- game/bin/openvic.gdextension | 3 ++- game/project.godot | 2 +- godot-cpp | 2 +- 9 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 6702d90..efa5c85 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -4,7 +4,7 @@ on: [push, pull_request] env: GODOT_BASE_DOWNLOAD_URL: https://github.com/godotengine/godot - GODOT_VERSION: 4.1.3 + GODOT_VERSION: 4.2 GODOT_VERSION_TYPE: stable OPENVIC_BASE_BRANCH: master diff --git a/README.md b/README.md index f5141ab..ec35c67 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Main Repo for the OpenVic Project For detailed instructions, view the Contributor Quickstart Guide [here](docs/contribution-quickstart-guide.md) ## System Requirements -* [Godot 4.1.3](https://github.com/godotengine/godot/releases/tag/4.1.3-stable) +* [Godot 4.2](https://github.com/godotengine/godot/releases/tag/4.2-stable) * [scons](https://scons.org/) See [System Requirements](docs/contribution/system-requirements.md). @@ -21,7 +21,7 @@ See [Cloning](docs/contribution/cloning.md). ## [Godot Documentation](https://docs.godotengine.org/en/latest/) ## Build/Run Instructions -1. Install [Godot 4.1.3](https://github.com/godotengine/godot/releases/tag/4.1.3-stable) and [scons](https://scons.org/) for your system. +1. Install [Godot 4.2](https://github.com/godotengine/godot/releases/tag/4.2-stable) and [scons](https://scons.org/) for your system. 2. Run the command `git submodule update --init --recursive` to retrieve all related submodules. 3. Run `scons` in the project root, you should see a libopenvic file in `game/bin/openvic`. 4. Open with Godot 4, click import and navigate to the `game` directory. diff --git a/SConstruct b/SConstruct index f6ed7f6..bcb477a 100644 --- a/SConstruct +++ b/SConstruct @@ -12,19 +12,15 @@ env = SConscript("scripts/SConstruct") env.PrependENVPath("PATH", os.getenv("PATH")) -OLD_ARGS = ARGUMENTS.copy() -ARGUMENTS["compiledb"] = False opts = env.SetupOptions() env.FinalizeOptions() -ARGUMENTS = OLD_ARGS # Needs Clone, else godot-cpp builds using our modified environment variables. eg: godot-cpp builds on C++20 OLD_ARGS = SCons.Script.ARGUMENTS.copy() SCons.Script.ARGUMENTS["use_static_cpp"] = env["use_static_cpp"] SCons.Script.ARGUMENTS["disable_exceptions"] = env["disable_exceptions"] -if ARGUMENTS.get("compiledb", False): - SCons.Script.ARGUMENTS["compiledb"] = True +SCons.Script.ARGUMENTS["compiledb_file"] = 'godot-cpp/compile_commands.json' godot_env = SConscript("godot-cpp/SConstruct") SCons.Script.ARGUMENTS = OLD_ARGS @@ -91,4 +87,8 @@ if "env" in locals(): # FIXME: This method mixes both cosmetic progress stuff and cache handling... env.show_progress(env) +# Add compiledb if the option is set +if env.get("compiledb", False): + default_args += ["compiledb"] + Default(*default_args) diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index db3dd3f..4a80eb9 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -1,5 +1,7 @@ #include "GameSingleton.hpp" +#include + #include #include #include @@ -553,7 +555,8 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi UtilityFunctions::push_error("Failed to hardcoded defines!"); err = FAILED; } - if (!dataloader.load_localisation_files(LoadLocalisation::add_message)) { + 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; } diff --git a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp index 96c67e8..3da8bc8 100644 --- a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp +++ b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp @@ -135,7 +135,6 @@ Error LoadLocalisation::load_localisation_dir(String const& dir_path) const { return err; } bool LoadLocalisation::add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation) { - static Ref translations[Dataloader::_LocaleCount] = { nullptr }; Ref& translation = translations[locale]; if (translation.is_null()) { translation = _singleton->_get_translation(Dataloader::locale_names[locale]); diff --git a/extension/src/openvic-extension/singletons/LoadLocalisation.hpp b/extension/src/openvic-extension/singletons/LoadLocalisation.hpp index b093fdf..aeee076 100644 --- a/extension/src/openvic-extension/singletons/LoadLocalisation.hpp +++ b/extension/src/openvic-extension/singletons/LoadLocalisation.hpp @@ -10,6 +10,8 @@ namespace OpenVic { static inline LoadLocalisation* _singleton = nullptr; + godot::Ref translations[Dataloader::_LocaleCount]; + godot::Error _load_file(godot::String const& file_path, godot::Ref translation) const; godot::Ref _get_translation(godot::String const& locale) const; @@ -26,6 +28,6 @@ namespace OpenVic { godot::Error load_locale_dir(godot::String const& dir_path, godot::String const& locale) const; godot::Error load_localisation_dir(godot::String const& dir_path) const; - static bool add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation); + bool add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation); }; } diff --git a/game/bin/openvic.gdextension b/game/bin/openvic.gdextension index 9b8af8f..5a4271b 100644 --- a/game/bin/openvic.gdextension +++ b/game/bin/openvic.gdextension @@ -1,7 +1,8 @@ [configuration] entry_symbol = "openvic_library_init" -compatibility_minimum = 4.1 +compatibility_minimum = 4.2 +reloadable = true [libraries] diff --git a/game/project.godot b/game/project.godot index ead3c6b..940c340 100644 --- a/game/project.godot +++ b/game/project.godot @@ -14,7 +14,7 @@ config/name="OpenVic" config/description="A faithful recreation of Victoria 2: Heart of Darkness with a focus on enhancing performance, multiplayer stability, and modability for modern machines." run/main_scene="res://src/Game/GameStart.tscn" config/use_custom_user_dir=true -config/features=PackedStringArray("4.1", "Forward Plus") +config/features=PackedStringArray("4.2", "Forward Plus") boot_splash/bg_color=Color(0, 0, 0, 0) boot_splash/show_image=false boot_splash/image="res://splash_assets/splash_image.png" diff --git a/godot-cpp b/godot-cpp index 06a6e37..54136ee 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit 06a6e378bd347e6c01bd0de9ef7661835e29623e +Subproject commit 54136ee8357c5140a3775c54f08db5f7deda2058 -- cgit v1.2.3-56-ga3b1