From 0c0b10fc09416030ddd3f2a28113800d18c8ae0f Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 15:32:38 +0100 Subject: [PATCH 01/11] Compile OpenRCT2 using C++20 --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82476ec069..cc13916c54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ endif () include(CheckCXXCompilerFlag) include(GNUInstallDirs) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}") @@ -277,6 +277,9 @@ if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244") # C4244: 'conversion_type': conversion from 'type1' to 'type2', possible loss of data set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068") # C4068: unknown pragma + # Enable char8_t<->char conversion :( + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:char8_t-") + add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_SCL_SECURE_NO_WARNINGS) if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") @@ -331,6 +334,9 @@ else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas -Wno-missing-braces -Wno-comment -Wnonnull -Wno-unused-parameter -Wno-attributes") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG=${DEBUG_LEVEL}") + # Enable char8_t<->char conversion :( + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-char8_t") + if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=objc-method-access") endif() From 530ec9a6f779eb914238d4c3fcb27412524c7d33 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 15:38:51 +0100 Subject: [PATCH 02/11] Remove never-set COLOUR_FLAG_8 constant The definition is also outside the boundaries of a uint8_t, so its existence is a bit odd. --- src/openrct2/drawing/Rect.cpp | 13 ++----------- src/openrct2/interface/Colour.h | 3 +-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/openrct2/drawing/Rect.cpp b/src/openrct2/drawing/Rect.cpp index 747731e84d..e9044dd5b3 100644 --- a/src/openrct2/drawing/Rect.cpp +++ b/src/openrct2/drawing/Rect.cpp @@ -30,18 +30,9 @@ void GfxFillRectInset(DrawPixelInfo& dpi, const ScreenRect& rect, int32_t colour const auto leftBottom = ScreenCoordsXY{ rect.GetLeft(), rect.GetBottom() }; const auto rightTop = ScreenCoordsXY{ rect.GetRight(), rect.GetTop() }; const auto rightBottom = ScreenCoordsXY{ rect.GetRight(), rect.GetBottom() }; - if (colour & (COLOUR_FLAG_TRANSLUCENT | COLOUR_FLAG_8)) + if (colour & COLOUR_FLAG_TRANSLUCENT) { - TranslucentWindowPalette palette; - if (colour & COLOUR_FLAG_8) - { - // TODO: This can't be added up - // palette = NOT_TRANSLUCENT(colour); - assert(false); - return; - } - - palette = TranslucentWindowPalettes[BASE_COLOUR(colour)]; + auto palette = TranslucentWindowPalettes[BASE_COLOUR(colour)]; if (flags & INSET_RECT_FLAG_BORDER_NONE) { diff --git a/src/openrct2/interface/Colour.h b/src/openrct2/interface/Colour.h index 2f5d90bfb2..9a47f2a7cb 100644 --- a/src/openrct2/interface/Colour.h +++ b/src/openrct2/interface/Colour.h @@ -212,12 +212,11 @@ constexpr uint8_t COLOUR_NUM_NORMAL = 54; #define TEXT_COLOUR_254 (254) #define TEXT_COLOUR_255 (255) -enum +enum : colour_t { COLOUR_FLAG_OUTLINE = (1 << 5), COLOUR_FLAG_INSET = (1 << 6), // 64, 0x40 COLOUR_FLAG_TRANSLUCENT = (1 << 7), - COLOUR_FLAG_8 = (1 << 8) }; #define TRANSLUCENT(x) ((x) | static_cast(COLOUR_FLAG_TRANSLUCENT)) From ffcb2b8c828e9c41bc81403c84c44684de8b844e Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 16:55:53 +0100 Subject: [PATCH 03/11] Fix or-ing different enumeration types warning --- src/openrct2-ui/windows/TopToolbar.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 44b2c8d3b4..93043edaf0 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -3230,9 +3230,10 @@ public: // Draw an overlay if clearance checks are disabled if (gCheatsDisableClearanceChecks) { + auto colour = static_cast(EnumValue(COLOUR_DARK_ORANGE) | EnumValue(COLOUR_FLAG_OUTLINE)); DrawTextBasic( dpi, screenPos + ScreenCoordsXY{ 26, 2 }, STR_OVERLAY_CLEARANCE_CHECKS_DISABLED, {}, - { COLOUR_DARK_ORANGE | COLOUR_FLAG_OUTLINE, TextAlignment::RIGHT }); + { colour, TextAlignment::RIGHT }); } } @@ -3295,9 +3296,8 @@ public: // Draw number of players. auto ft = Formatter(); ft.Add(NetworkGetNumVisiblePlayers()); - DrawTextBasic( - dpi, screenPos + ScreenCoordsXY{ 23, 1 }, STR_COMMA16, ft, - { COLOUR_WHITE | COLOUR_FLAG_OUTLINE, TextAlignment::RIGHT }); + auto colour = static_cast(EnumValue(COLOUR_WHITE) | EnumValue(COLOUR_FLAG_OUTLINE)); + DrawTextBasic(dpi, screenPos + ScreenCoordsXY{ 23, 1 }, STR_COMMA16, ft, { colour, TextAlignment::RIGHT }); } } }; From da0bbb2019fa44eee8686091212ad93b54341caf Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 17:20:05 +0100 Subject: [PATCH 04/11] Mark GuestList::FilterArguments comparisons const --- src/openrct2-ui/windows/GuestList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index c60d455790..1871352059 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -104,11 +104,11 @@ private: return firstStrId; } - bool operator==(const FilterArguments& other) + bool operator==(const FilterArguments& other) const { return std::memcmp(args, other.args, sizeof(args)) == 0; } - bool operator!=(const FilterArguments& other) + bool operator!=(const FilterArguments& other) const { return !(*this == other); } From 989a4dddbde8fa396671ed3abe3959c5b6dddd61 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 17:22:25 +0100 Subject: [PATCH 05/11] Mark ObjectLoadError::DownloadStatusInfo comparisons const --- src/openrct2-ui/windows/ObjectLoadError.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/windows/ObjectLoadError.cpp b/src/openrct2-ui/windows/ObjectLoadError.cpp index cd7669f95d..b3ce56655a 100644 --- a/src/openrct2-ui/windows/ObjectLoadError.cpp +++ b/src/openrct2-ui/windows/ObjectLoadError.cpp @@ -42,11 +42,11 @@ private: size_t Count{}; size_t Total{}; - bool operator==(const DownloadStatusInfo& rhs) + bool operator==(const DownloadStatusInfo& rhs) const { return Name == rhs.Name && Source == rhs.Source && Count == rhs.Count && Total == rhs.Total; } - bool operator!=(const DownloadStatusInfo& rhs) + bool operator!=(const DownloadStatusInfo& rhs) const { return !(*this == rhs); } From 19171f7eef4767defe2b62117d50d926de1e9017 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 19:41:45 +0100 Subject: [PATCH 06/11] Update Visual Studio properties for C++20 too --- openrct2.common.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openrct2.common.props b/openrct2.common.props index ecb0b4a280..a884253606 100644 --- a/openrct2.common.props +++ b/openrct2.common.props @@ -65,7 +65,7 @@ MultiThreadedDLL true true - /utf-8 /std:c++17 /permissive- /Zc:externConstexpr + /utf-8 /std:c++20 /permissive- /Zc:externConstexpr /Zc:char8_t- true From 8bf848582b300bd449ba6eb941989a5547860e64 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 21:33:00 +0100 Subject: [PATCH 07/11] Add -Wno-deprecated-declarations to suppress fs::u8path warnings --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc13916c54..7c551951e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,7 +335,7 @@ else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG=${DEBUG_LEVEL}") # Enable char8_t<->char conversion :( - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-char8_t") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-char8_t -Wno-deprecated-declarations") if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=objc-method-access") From 6edcd6d7a06203dcb293f95f1857b31b6b53fb11 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 22:16:06 +0100 Subject: [PATCH 08/11] Avoid implicit capture of `this` in Footpath window --- src/openrct2-ui/windows/Footpath.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index e23000c078..d7d1f412eb 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -1034,18 +1034,25 @@ private: auto footpathPlaceAction = FootpathPlaceAction( footpathLoc, slope, type, gFootpathSelection.Railings, _footpathConstructDirection, constructFlags); - footpathPlaceAction.SetCallback([=](const GameAction* ga, const GameActions::Result* result) { + + footpathPlaceAction.SetCallback([footpathLoc](const GameAction* ga, const GameActions::Result* result) { + auto* self = static_cast(WindowFindByClass(WindowClass::Footpath)); + if (self == nullptr) + { + return; + } + if (result->Error == GameActions::Status::Ok) { OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); if (gFootpathConstructSlope == 0) { - _footpathConstructValidDirections = INVALID_DIRECTION; + self->_footpathConstructValidDirections = INVALID_DIRECTION; } else { - _footpathConstructValidDirections = _footpathConstructDirection; + self->_footpathConstructValidDirections = self->_footpathConstructDirection; } if (gFootpathGroundFlags & ELEMENT_IS_UNDERGROUND) @@ -1062,7 +1069,7 @@ private: gFootpathConstructFromPosition.z += PATH_HEIGHT_STEP; } } - WindowFootpathSetEnabledAndPressedWidgets(); + self->WindowFootpathSetEnabledAndPressedWidgets(); }); GameActions::Execute(&footpathPlaceAction); } From 2d52f5b98295eb467940e5cafd08cfea73416670 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Feb 2024 22:26:43 +0100 Subject: [PATCH 09/11] Play footpath placement sound even if footpath window is absent --- src/openrct2-ui/windows/Footpath.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index d7d1f412eb..d24ffce194 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -1036,6 +1036,11 @@ private: footpathLoc, slope, type, gFootpathSelection.Railings, _footpathConstructDirection, constructFlags); footpathPlaceAction.SetCallback([footpathLoc](const GameAction* ga, const GameActions::Result* result) { + if (result->Error == GameActions::Status::Ok) + { + Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); + } + auto* self = static_cast(WindowFindByClass(WindowClass::Footpath)); if (self == nullptr) { @@ -1044,8 +1049,6 @@ private: if (result->Error == GameActions::Status::Ok) { - OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); - if (gFootpathConstructSlope == 0) { self->_footpathConstructValidDirections = INVALID_DIRECTION; From c2730bc12d890212eba1158d8056e6546a07e7b1 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Wed, 28 Feb 2024 21:57:08 +0100 Subject: [PATCH 10/11] Update readme to require C++20 support --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index bb732bb78c..b71aa9ed44 100644 --- a/readme.md +++ b/readme.md @@ -135,7 +135,7 @@ OpenRCT2 requires original files of RollerCoaster Tycoon 2 to play. It can be bo
Linux prerequisites - - gcc (>= 7.1) or clang (>= 8.0.0) (for C++17 support) + - gcc (>= 8.0) or clang (>= 10.0) (for C++20 support) - sdl2 (only for UI client) - freetype (can be disabled) - fontconfig (can be disabled) From a3eea76fa07264c5ce9c97d8ab767ff545f43eb5 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Wed, 28 Feb 2024 21:57:38 +0100 Subject: [PATCH 11/11] Update cppStandard in .vscode properties --- .vscode/c_cpp_properties.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index b30e36997a..f3909d6159 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -24,7 +24,7 @@ "/Library/Frameworks" ], "cStandard": "c11", - "cppStandard": "c++17" + "cppStandard": "c++20" }, { "name": "Linux",