1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Merge pull request #21468 from AaronVanGeffen/cpp20

Compile project as C++20
This commit is contained in:
Michael Steenbeek
2024-02-28 22:28:36 +01:00
committed by GitHub
10 changed files with 36 additions and 30 deletions

View File

@@ -24,7 +24,7 @@
"/Library/Frameworks"
],
"cStandard": "c11",
"cppStandard": "c++17"
"cppStandard": "c++20"
},
{
"name": "Linux",

View File

@@ -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 -Wno-deprecated-declarations")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=objc-method-access")
endif()

View File

@@ -65,7 +65,7 @@
<RuntimeLibrary Condition="'$(UseSharedLibs)'=='true'">MultiThreadedDLL</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalOptions>/utf-8 /std:c++17 /permissive- /Zc:externConstexpr</AdditionalOptions>
<AdditionalOptions>/utf-8 /std:c++20 /permissive- /Zc:externConstexpr /Zc:char8_t-</AdditionalOptions>
</ClCompile>
<Link>
<LargeAddressAware Condition="'$(Platform)'=='Win32'">true</LargeAddressAware>

View File

@@ -135,7 +135,7 @@ OpenRCT2 requires original files of RollerCoaster Tycoon 2 to play. It can be bo
<details>
<summary>Linux prerequisites</summary>
- 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)

View File

@@ -1034,18 +1034,28 @@ 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) {
if (result->Error == GameActions::Status::Ok)
{
OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position);
Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position);
}
auto* self = static_cast<FootpathWindow*>(WindowFindByClass(WindowClass::Footpath));
if (self == nullptr)
{
return;
}
if (result->Error == GameActions::Status::Ok)
{
if (gFootpathConstructSlope == 0)
{
_footpathConstructValidDirections = INVALID_DIRECTION;
self->_footpathConstructValidDirections = INVALID_DIRECTION;
}
else
{
_footpathConstructValidDirections = _footpathConstructDirection;
self->_footpathConstructValidDirections = self->_footpathConstructDirection;
}
if (gFootpathGroundFlags & ELEMENT_IS_UNDERGROUND)
@@ -1062,7 +1072,7 @@ private:
gFootpathConstructFromPosition.z += PATH_HEIGHT_STEP;
}
}
WindowFootpathSetEnabledAndPressedWidgets();
self->WindowFootpathSetEnabledAndPressedWidgets();
});
GameActions::Execute(&footpathPlaceAction);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -3230,9 +3230,10 @@ public:
// Draw an overlay if clearance checks are disabled
if (gCheatsDisableClearanceChecks)
{
auto colour = static_cast<colour_t>(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<int32_t>(NetworkGetNumVisiblePlayers());
DrawTextBasic(
dpi, screenPos + ScreenCoordsXY{ 23, 1 }, STR_COMMA16, ft,
{ COLOUR_WHITE | COLOUR_FLAG_OUTLINE, TextAlignment::RIGHT });
auto colour = static_cast<colour_t>(EnumValue(COLOUR_WHITE) | EnumValue(COLOUR_FLAG_OUTLINE));
DrawTextBasic(dpi, screenPos + ScreenCoordsXY{ 23, 1 }, STR_COMMA16, ft, { colour, TextAlignment::RIGHT });
}
}
};

View File

@@ -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)
{

View File

@@ -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<uint8_t>(COLOUR_FLAG_TRANSLUCENT))