From 7b0275003406ebe1aabaa5e9a96bb5554d54c9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 21:10:56 +0100 Subject: [PATCH 01/12] ENABLE_CCACHE option is available for all platforms --- CMakeLists.txt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f04a3a2c5..5d2ce2a29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,10 +79,19 @@ if(NOT APPLE_IOS AND NOT ANDROID) option(ENABLE_MONOLITHIC_INSTALL "Install everything in single directory on Linux and Mac" OFF) endif() -# On Linux, use -DCMAKE_CXX_COMPILER_LAUNCHER=ccache instead. -# The XCode and MSVC builds each require some more configuration, which is enabled by the following option: -if(MSVC OR (CMAKE_GENERATOR STREQUAL "Xcode")) - option(ENABLE_CCACHE "Speed up recompilation by caching previous compilations" OFF) +option(ENABLE_CCACHE "Speed up recompilation by caching previous compilations" OFF) +if(ENABLE_CCACHE) + find_program(CCACHE ccache) + if(CCACHE-NOTFOUND) + message(FATAL_ERROR "'ccache' could not be found; install it or set ENABLE_CCACHE=OFF.") + endif() +endif() + +# On Linux, use ccache via CMAKE_CXX_COMPILER_LAUNCHER. +# The XCode and MSVC builds each require some more configuration further down. +if(ENABLE_CCACHE AND LINUX) + set(CMAKE_C_COMPILER_LAUNCHER "ccache") + set(CMAKE_CXX_COMPILER_LAUNCHER "ccache") endif() if(ENABLE_CCACHE AND (CMAKE_GENERATOR STREQUAL "Xcode")) From fce3b5b83c634cf8c16185e18d71dcb72bd8a9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 21:12:52 +0100 Subject: [PATCH 02/12] Remove redundant find_program and if(CCACHE) - if ENABLE_CCACHE is set and the generation hasn't already failed then CCACHE is guaranteed to be set and point to a ccache binary. --- CMakeLists.txt | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d2ce2a29..8827a968e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,21 +95,18 @@ if(ENABLE_CCACHE AND LINUX) endif() if(ENABLE_CCACHE AND (CMAKE_GENERATOR STREQUAL "Xcode")) - find_program(CCACHE ccache REQUIRED) - if(CCACHE) - # https://stackoverflow.com/a/36515503/2278742 - # Set up wrapper scripts - configure_file(xcode/launch-c.in xcode/launch-c) - configure_file(xcode/launch-cxx.in xcode/launch-cxx) - execute_process(COMMAND chmod a+rx - "${CMAKE_BINARY_DIR}/xcode/launch-c" - "${CMAKE_BINARY_DIR}/xcode/launch-cxx") - # Set Xcode project attributes to route compilation through our scripts - set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/xcode/launch-c") - set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/xcode/launch-cxx") - set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/xcode/launch-c") - set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/xcode/launch-cxx") - endif() + # https://stackoverflow.com/a/36515503/2278742 + # Set up wrapper scripts + configure_file(xcode/launch-c.in xcode/launch-c) + configure_file(xcode/launch-cxx.in xcode/launch-cxx) + execute_process(COMMAND chmod a+rx + "${CMAKE_BINARY_DIR}/xcode/launch-c" + "${CMAKE_BINARY_DIR}/xcode/launch-cxx") + # Set Xcode project attributes to route compilation through our scripts + set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/xcode/launch-c") + set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/xcode/launch-cxx") + set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/xcode/launch-c") + set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/xcode/launch-cxx") endif() # Allow to pass package name from Travis CI @@ -275,19 +272,16 @@ if(MINGW OR MSVC) if(MSVC) if(ENABLE_CCACHE) # https://github.com/ccache/ccache/discussions/1154#discussioncomment-3611387 - find_program(CCACHE ccache REQUIRED) - if (CCACHE) - file(COPY_FILE - ${CCACHE} ${CMAKE_BINARY_DIR}/cl.exe - ONLY_IF_DIFFERENT) + file(COPY_FILE + ${CCACHE} ${CMAKE_BINARY_DIR}/cl.exe + ONLY_IF_DIFFERENT) - set(CMAKE_VS_GLOBALS - "CLToolExe=cl.exe" - "CLToolPath=${CMAKE_BINARY_DIR}" - "TrackFileAccess=false" - "UseMultiToolTask=true" - ) - endif() + set(CMAKE_VS_GLOBALS + "CLToolExe=cl.exe" + "CLToolPath=${CMAKE_BINARY_DIR}" + "TrackFileAccess=false" + "UseMultiToolTask=true" + ) endif() add_definitions(-DBOOST_ALL_NO_LIB) From 2569e1c661f4d2992ef598d334c60c059bd6661e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 21:13:41 +0100 Subject: [PATCH 03/12] Update documentation to suggest using option ENABLE_CCACHE instead of directly setting CMAKE_C(XX)_COMPILER_LAUNCHER --- docs/developers/Building_Android.md | 2 +- docs/developers/Building_Linux.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developers/Building_Android.md b/docs/developers/Building_Android.md index ef0c2c909..fee0024a4 100644 --- a/docs/developers/Building_Android.md +++ b/docs/developers/Building_Android.md @@ -62,7 +62,7 @@ Building for Android is a 2-step process. First, native C++ code is compiled to This is a traditional CMake project, you can build it from command line or some IDE. You're not required to pass any custom options (except Conan toolchain file), defaults are already good. If you wish to use your own CMake presets, inherit them from our `build-with-conan` preset. Example: ``` -cmake -S . -B ../build -G Ninja -D CMAKE_BUILD_TYPE=Debug -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER_LAUNCHER=ccache --toolchain ... +cmake -S . -B ../build -G Ninja -D CMAKE_BUILD_TYPE=Debug -D ENABLE_CCACHE:BOOL=ON --toolchain ... cmake --build ../build ``` diff --git a/docs/developers/Building_Linux.md b/docs/developers/Building_Linux.md index 5bd2f871c..4190ad49b 100644 --- a/docs/developers/Building_Linux.md +++ b/docs/developers/Building_Linux.md @@ -76,7 +76,7 @@ cmake ../vcmi **Notice**: The ../vcmi/ is not a typo, it will place makefile scripts into the build dir as the build dir is your working dir when calling CMake. ## To use ccache: -`cmake ../vcmi -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D CMAKE_C_COMPILER_LAUNCHER=ccache` +`cmake ../vcmi -D ENABLE_CCACHE:BOOL=ON` ## Trigger build From 9001124c3ad2690d6a3d00c3d7559eea0673e1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 21:14:00 +0100 Subject: [PATCH 04/12] Add linux-gcc-release-ccache and linux-clang-release-ccache --- CMakePresets.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/CMakePresets.json b/CMakePresets.json index d96a905b0..255347cd6 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -65,6 +65,15 @@ "CMAKE_CXX_COMPILER": "/usr/bin/clang++" } }, + { + "name": "linux-clang-release-ccache", + "displayName": "Clang x86_64-pc-linux-gnu with ccache", + "description": "VCMI Linux Clang with ccache", + "inherits": "linux-release", + "cacheVariables": { + "ENABLE_CCACHE": "ON" + } + }, { "name": "linux-gcc-release", "displayName": "GCC x86_64-pc-linux-gnu", @@ -76,6 +85,15 @@ "CMAKE_CXX_COMPILER": "/usr/bin/g++" } }, + { + "name": "linux-gcc-release-ccache", + "displayName": "GCC x86_64-pc-linux-gnu with ccache", + "description": "VCMI Linux GCC with ccache", + "inherits": "linux-release", + "cacheVariables": { + "ENABLE_CCACHE": "ON" + } + }, { "name": "linux-gcc-debug", "displayName": "GCC x86_64-pc-linux-gnu (debug)", @@ -284,6 +302,11 @@ "configurePreset": "linux-clang-release", "inherits": "default-release" }, + { + "name": "linux-clang-release-ccache", + "configurePreset": "linux-clang-release-ccache", + "inherits": "linux-clang-release" + }, { "name": "linux-clang-test", "configurePreset": "linux-clang-test", @@ -299,6 +322,11 @@ "configurePreset": "linux-gcc-release", "inherits": "default-release" }, + { + "name": "linux-gcc-release-ccache", + "configurePreset": "linux-gcc-release-ccache", + "inherits": "linux-gcc-release" + }, { "name": "linux-gcc-debug", "configurePreset": "linux-gcc-debug", From 721c189b2020abaa509a6720df4dabe087cb6559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 21:17:56 +0100 Subject: [PATCH 05/12] Replace direct usage of CMAKE_CXX_COMPILER_LAUNCHER with ENABLE_CCACHE in CI --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index ac20a6aea..219754038 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -244,7 +244,7 @@ jobs: - name: CMake Preset with ccache run: | - cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache --preset ${{ matrix.preset }} + cmake -DENABLE_CCACHE:BOOL=ON --preset ${{ matrix.preset }} - name: Build Preset run: | From 406d136cdcf97e1e8b830168d4cbd01bb5af1c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 22:24:58 +0100 Subject: [PATCH 06/12] Fixes warnings about possibly dangling references --- AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp | 11 +++++------ AI/VCAI/Pathfinding/AINodeStorage.cpp | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp index 1ee4e57f5..472719004 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp @@ -265,10 +265,11 @@ uint64_t DangerHitMapAnalyzer::enemyCanKillOurHeroesAlongThePath(const AIPath & { int3 tile = path.targetTile(); int turn = path.turn(); - const HitMapNode & info = hitMap[tile.x][tile.y][tile.z]; + const auto & fastestDanger = hitMap[tile.x][tile.y][tile.z].fastestDanger; + const auto & maximumDanger = hitMap[tile.x][tile.y][tile.z].fastestDanger; - return (info.fastestDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, info.fastestDanger.danger)) - || (info.maximumDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, info.maximumDanger.danger)); + return (fastestDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, fastestDanger.danger)) + || (maximumDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, maximumDanger.danger)); } const HitMapNode & DangerHitMapAnalyzer::getObjectThreat(const CGObjectInstance * obj) const @@ -280,9 +281,7 @@ const HitMapNode & DangerHitMapAnalyzer::getObjectThreat(const CGObjectInstance const HitMapNode & DangerHitMapAnalyzer::getTileThreat(const int3 & tile) const { - const HitMapNode & info = hitMap[tile.x][tile.y][tile.z]; - - return info; + return hitMap[tile.x][tile.y][tile.z]; } const std::set empty = {}; diff --git a/AI/VCAI/Pathfinding/AINodeStorage.cpp b/AI/VCAI/Pathfinding/AINodeStorage.cpp index 8e7bc4a8b..f0bb91c9c 100644 --- a/AI/VCAI/Pathfinding/AINodeStorage.cpp +++ b/AI/VCAI/Pathfinding/AINodeStorage.cpp @@ -321,9 +321,7 @@ bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNode bool AINodeStorage::isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const { - const AIPathNode & node = nodes[layer][pos.z][pos.x][pos.y][0]; - - return node.action != EPathNodeAction::UNKNOWN; + return nodes[layer][pos.z][pos.x][pos.y][0].action != EPathNodeAction::UNKNOWN; } std::vector AINodeStorage::getChainInfo(const int3 & pos, bool isOnLand) const From 01f602ab9246a157db8df75fba7c4ea2753b7e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 22:25:29 +0100 Subject: [PATCH 07/12] Fixes warning about usage of unused variable --- lib/mapObjects/CGPandoraBox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mapObjects/CGPandoraBox.cpp b/lib/mapObjects/CGPandoraBox.cpp index 750ac50fe..627ad8637 100644 --- a/lib/mapObjects/CGPandoraBox.cpp +++ b/lib/mapObjects/CGPandoraBox.cpp @@ -226,7 +226,7 @@ void CGPandoraBox::serializeJsonOptions(JsonSerializeFormat & handler) handler.serializeInt("experience", vinfo.reward.heroExperience, 0); handler.serializeInt("mana", vinfo.reward.manaDiff, 0); - int val; + int val = 0; handler.serializeInt("morale", val, 0); if(val) vinfo.reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::MORALE, BonusSource::OBJECT_INSTANCE, val, BonusSourceID(id)); From 61314a36f6b199693ee06ccd237b31fbfe72e31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Wed, 27 Dec 2023 22:35:43 +0100 Subject: [PATCH 08/12] Fix copy-paste mistake --- AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp index 472719004..6cda0e7f3 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp @@ -266,7 +266,7 @@ uint64_t DangerHitMapAnalyzer::enemyCanKillOurHeroesAlongThePath(const AIPath & int3 tile = path.targetTile(); int turn = path.turn(); const auto & fastestDanger = hitMap[tile.x][tile.y][tile.z].fastestDanger; - const auto & maximumDanger = hitMap[tile.x][tile.y][tile.z].fastestDanger; + const auto & maximumDanger = hitMap[tile.x][tile.y][tile.z].maximumDanger; return (fastestDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, fastestDanger.danger)) || (maximumDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, maximumDanger.danger)); From 25be15a0231b7e7a179c701f52151cc9dbc6e520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Fri, 29 Dec 2023 21:54:58 +0100 Subject: [PATCH 09/12] Use 'REQUIRED' instead of custom error message when ccache is not found --- CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8827a968e..32e78e58d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,10 +81,7 @@ endif() option(ENABLE_CCACHE "Speed up recompilation by caching previous compilations" OFF) if(ENABLE_CCACHE) - find_program(CCACHE ccache) - if(CCACHE-NOTFOUND) - message(FATAL_ERROR "'ccache' could not be found; install it or set ENABLE_CCACHE=OFF.") - endif() + find_program(CCACHE ccache REQUIRED) endif() # On Linux, use ccache via CMAKE_CXX_COMPILER_LAUNCHER. From 88ec4fa0e7fd97a9add0bdfa701b0bc9669f0713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Fri, 29 Dec 2023 23:12:06 +0100 Subject: [PATCH 10/12] Use getTileThreat-helper instead of directly accessing hitMap with tile coordinates --- AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp index 6cda0e7f3..a5e7981b8 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp @@ -265,11 +265,11 @@ uint64_t DangerHitMapAnalyzer::enemyCanKillOurHeroesAlongThePath(const AIPath & { int3 tile = path.targetTile(); int turn = path.turn(); - const auto & fastestDanger = hitMap[tile.x][tile.y][tile.z].fastestDanger; - const auto & maximumDanger = hitMap[tile.x][tile.y][tile.z].maximumDanger; - return (fastestDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, fastestDanger.danger)) - || (maximumDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, maximumDanger.danger)); + auto& info = getTileThreat(tile); + + return (info.fastestDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, info.fastestDanger.danger)) + || (info.maximumDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, info.maximumDanger.danger)); } const HitMapNode & DangerHitMapAnalyzer::getObjectThreat(const CGObjectInstance * obj) const From daf9f9f7f5252e6f93fd2fb63ed61f82be1b6cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Thor=C3=A9n?= Date: Sat, 30 Dec 2023 11:01:21 +0100 Subject: [PATCH 11/12] Re-add const that was erronously removed with 88ec4fa Co-authored-by: Andrey Filipenkov --- AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp index a5e7981b8..ef8c24d17 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp @@ -266,7 +266,7 @@ uint64_t DangerHitMapAnalyzer::enemyCanKillOurHeroesAlongThePath(const AIPath & int3 tile = path.targetTile(); int turn = path.turn(); - auto& info = getTileThreat(tile); + const auto& info = getTileThreat(tile); return (info.fastestDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, info.fastestDanger.danger)) || (info.maximumDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, info.maximumDanger.danger)); From 76388d60854afd59cd52166da9f203b3a80eedbb Mon Sep 17 00:00:00 2001 From: kdmcser Date: Mon, 1 Jan 2024 04:27:48 +0800 Subject: [PATCH 12/12] Update Chinese translation (#3410) * Update Chinese translate --- Mods/vcmi/config/vcmi/chinese.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Mods/vcmi/config/vcmi/chinese.json b/Mods/vcmi/config/vcmi/chinese.json index 7cbc532fb..ec09e8faa 100644 --- a/Mods/vcmi/config/vcmi/chinese.json +++ b/Mods/vcmi/config/vcmi/chinese.json @@ -54,6 +54,8 @@ "vcmi.radialWheel.moveDown" : "下移", "vcmi.radialWheel.moveBottom" : "移到底端", + "vcmi.spellBook.search" : "搜索中...", + "vcmi.mainMenu.serverConnecting" : "连接中...", "vcmi.mainMenu.serverAddressEnter" : "使用地址:", "vcmi.mainMenu.serverConnectionFailed" : "连接失败", @@ -69,6 +71,7 @@ "vcmi.lobby.noPreview" : "无地上部分", "vcmi.lobby.noUnderground" : "无地下部分", + "vcmi.client.errors.missingCampaigns" : "{找不到数据文件}\n\n没有找到战役数据文件!你可能使用了不完整或损坏的英雄无敌3数据文件,请重新安装数据文件。", "vcmi.server.errors.existingProcess" : "一个VCMI进程已经在运行,启动新进程前请结束它。", "vcmi.server.errors.modsToEnable" : "{需要启用的mod列表}", "vcmi.server.errors.modsToDisable" : "{需要禁用的mod列表}", @@ -302,7 +305,6 @@ "vcmi.optionsTab.simturns.months.1" : " %d 月", "vcmi.optionsTab.simturns.months.2" : " %d 月", - // Custom victory conditions for H3 campaigns and HotA maps "vcmi.map.victoryCondition.daysPassed.toOthers" : "敌人依然存活至今,你失败了!", "vcmi.map.victoryCondition.daysPassed.toSelf" : "祝贺你,你依然存活,取得了胜利!",