From 3ef6003671756093218a893ad0ed3377aeb32c04 Mon Sep 17 00:00:00 2001 From: Matthias Moninger <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 2 Jul 2023 17:42:46 +0300 Subject: [PATCH] Replace openrct2_assert with Guard::Assert, remove openrct2_assert --- src/openrct2-ui/windows/LoadSave.cpp | 6 +++--- src/openrct2-ui/windows/TileInspector.cpp | 22 +++++++++++----------- src/openrct2/core/Guard.cpp | 8 -------- src/openrct2/core/Guard.hpp | 8 -------- src/openrct2/drawing/AVX2Drawing.cpp | 2 +- src/openrct2/drawing/Drawing.Sprite.cpp | 8 ++++---- src/openrct2/drawing/Drawing.cpp | 2 +- src/openrct2/drawing/SSE41Drawing.cpp | 2 +- src/openrct2/entity/EntityRegistry.cpp | 2 +- src/openrct2/entity/Peep.cpp | 6 +++--- src/openrct2/util/Util.cpp | 2 +- src/openrct2/windows/Intent.cpp | 10 +++++----- src/openrct2/world/MapGen.cpp | 8 ++++---- src/openrct2/world/TileInspector.cpp | 4 ++-- 14 files changed, 37 insertions(+), 53 deletions(-) diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 8ea848eb20..ac49ba3b02 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -221,7 +221,7 @@ static const char* GetFilterPatternByType(const int32_t type, const bool isSave) return "*.bmp;*.png"; default: - openrct2_assert(true, "Unsupported load/save directory type."); + Guard::Fail("Unsupported load/save directory type."); } return ""; @@ -1077,12 +1077,12 @@ WindowBase* WindowLoadsaveOpen( break; case LOADSAVETYPE_HEIGHTMAP: - openrct2_assert(!isSave, "Cannot save images through loadsave window"); + Guard::Assert(!isSave, "Cannot save images through loadsave window"); w->widgets[WIDX_TITLE].text = STR_FILE_DIALOG_TITLE_LOAD_HEIGHTMAP; break; default: - openrct2_assert(true, "Unsupported load/save type: %d", type & 0x0F); + Guard::Fail("Unsupported load/save type: %d", type & 0x0F); break; } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 00c14bd6df..c448098e51 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -925,7 +925,7 @@ public: TileElement* const tileElement = GetSelectedElement(); if (tileInspectorPage == TileInspectorPage::Wall) { - openrct2_assert(tileElement->GetType() == TileElementType::Wall, "Element is not a wall"); + Guard::Assert(tileElement->GetType() == TileElementType::Wall, "Element is not a wall"); if (widgetIndex == WIDX_WALL_DROPDOWN_SLOPE_BUTTON) WallSetSlope(windowTileInspectorSelectedIndex, dropdownIndex); } @@ -1800,14 +1800,14 @@ private: void RemoveElement(int32_t elementIndex) { - openrct2_assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); + Guard::Assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); auto modifyTile = TileModifyAction(_toolMap, TileModifyType::AnyRemove, elementIndex); GameActions::Execute(&modifyTile); } void RotateElement(int32_t elementIndex) { - openrct2_assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); + Guard::Assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); auto modifyTile = TileModifyAction(_toolMap, TileModifyType::AnyRotate, elementIndex); GameActions::Execute(&modifyTile); } @@ -1826,7 +1826,7 @@ private: void SortElements() { - openrct2_assert(_tileSelected, "No tile selected"); + Guard::Assert(_tileSelected, "No tile selected"); auto modifyTile = TileModifyAction(_toolMap, TileModifyType::AnySort); GameActions::Execute(&modifyTile); } @@ -1890,8 +1890,8 @@ private: void PathToggleEdge(int32_t elementIndex, int32_t cornerIndex) { - openrct2_assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); - openrct2_assert(cornerIndex >= 0 && cornerIndex < 8, "cornerIndex out of range"); + Guard::Assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); + Guard::Assert(cornerIndex >= 0 && cornerIndex < 8, "cornerIndex out of range"); auto modifyTile = TileModifyAction(_toolMap, TileModifyType::PathToggleEdge, elementIndex, cornerIndex); GameActions::Execute(&modifyTile); } @@ -1906,7 +1906,7 @@ private: void WallSetSlope(int32_t elementIndex, int32_t slopeValue) { // Make sure only the correct bits are set - openrct2_assert((slopeValue & 3) == slopeValue, "slopeValue doesn't match its mask"); + Guard::Assert((slopeValue & 3) == slopeValue, "slopeValue doesn't match its mask"); auto modifyTile = TileModifyAction(_toolMap, TileModifyType::WallSetSlope, elementIndex, slopeValue); GameActions::Execute(&modifyTile); } @@ -1946,7 +1946,7 @@ private: void QuarterTileSet(int32_t elementIndex, const int32_t quarterIndex) { // quarterIndex is widget index relative to WIDX_SCENERY_CHECK_QUARTER_N, so a value from 0-3 - openrct2_assert(quarterIndex >= 0 && quarterIndex < 4, "quarterIndex out of range"); + Guard::Assert(quarterIndex >= 0 && quarterIndex < 4, "quarterIndex out of range"); auto modifyTile = TileModifyAction( _toolMap, TileModifyType::ScenerySetQuarterLocation, elementIndex, (quarterIndex - GetCurrentRotation()) & 3); GameActions::Execute(&modifyTile); @@ -1962,7 +1962,7 @@ private: void BannerToggleBlock(int32_t elementIndex, int32_t edgeIndex) { - openrct2_assert(edgeIndex >= 0 && edgeIndex < 4, "edgeIndex out of range"); + Guard::Assert(edgeIndex >= 0 && edgeIndex < 4, "edgeIndex out of range"); // Make edgeIndex abstract edgeIndex = (edgeIndex - GetCurrentRotation()) & 3; auto modifyTile = TileModifyAction(_toolMap, TileModifyType::BannerToggleBlockingEdge, elementIndex, edgeIndex); @@ -1971,14 +1971,14 @@ private: void ToggleInvisibility(int32_t elementIndex) { - openrct2_assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); + Guard::Assert(elementIndex >= 0 && elementIndex < windowTileInspectorElementCount, "elementIndex out of range"); auto modifyTile = TileModifyAction(_toolMap, TileModifyType::AnyToggleInvisilibity, elementIndex); GameActions::Execute(&modifyTile); } TileElement* GetSelectedElement() { - openrct2_assert( + Guard::Assert( windowTileInspectorSelectedIndex >= 0 && windowTileInspectorSelectedIndex < windowTileInspectorElementCount, "Selected list item out of range"); return MapGetFirstElementAt(_toolMap) + windowTileInspectorSelectedIndex; diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 72433fc238..6855092868 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -24,14 +24,6 @@ #include #include -void openrct2_assert_fwd(bool expression, const char* message, ...) -{ - va_list va; - va_start(va, message); - Guard::Assert_VA(expression, message, va); - va_end(va); -} - namespace Guard { constexpr const utf8* ASSERTION_MESSAGE = "An assertion failed, please report this to the OpenRCT2 developers."; diff --git a/src/openrct2/core/Guard.hpp b/src/openrct2/core/Guard.hpp index 58d4b3d690..5e9432a903 100644 --- a/src/openrct2/core/Guard.hpp +++ b/src/openrct2/core/Guard.hpp @@ -15,14 +15,6 @@ #include #include -void openrct2_assert_fwd(bool expression, const char* message, ...); - -#define openrct2_assert(expr, msg, ...) \ - if (!(expr)) \ - { \ - openrct2_assert_fwd((expr), msg, ##__VA_ARGS__); \ - } - enum class ASSERT_BEHAVIOUR { ABORT, diff --git a/src/openrct2/drawing/AVX2Drawing.cpp b/src/openrct2/drawing/AVX2Drawing.cpp index f83a210494..ded3d4a36a 100644 --- a/src/openrct2/drawing/AVX2Drawing.cpp +++ b/src/openrct2/drawing/AVX2Drawing.cpp @@ -52,7 +52,7 @@ void MaskAvx2( int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap) { - openrct2_assert(false, "AVX2 function called on a CPU that doesn't support AVX2"); + Guard::Fail("AVX2 function called on a CPU that doesn't support AVX2"); } #endif // __AVX2__ diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index d98fed7f14..1f325e52f3 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -699,7 +699,7 @@ const G1Element* GfxGetG1Element(const ImageId imageId) const G1Element* GfxGetG1Element(ImageIndex image_id) { - openrct2_assert(!gOpenRCT2NoGraphics, "GfxGetG1Element called on headless instance"); + Guard::Assert(!gOpenRCT2NoGraphics, "GfxGetG1Element called on headless instance"); auto offset = static_cast(image_id); if (offset == 0x7FFFF || offset == ImageIndexUndefined) @@ -768,9 +768,9 @@ void GfxSetG1Element(ImageIndex imageId, const G1Element* g1) || (imageId >= SPR_SCROLLING_TEXT_START && imageId < SPR_SCROLLING_TEXT_END); #ifdef DEBUG - openrct2_assert(!gOpenRCT2NoGraphics, "GfxSetG1Element called on headless instance"); - openrct2_assert(isValid || isTemp, "GfxSetG1Element called with unexpected image id"); - openrct2_assert(g1 != nullptr, "g1 was nullptr"); + Guard::Assert(!gOpenRCT2NoGraphics, "GfxSetG1Element called on headless instance"); + Guard::Assert(isValid || isTemp, "GfxSetG1Element called with unexpected image id"); + Guard::Assert(g1 != nullptr, "g1 was nullptr"); #endif if (g1 != nullptr) diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 5b46494e2c..649271c30f 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -787,7 +787,7 @@ void LoadPalette() if (water_type != nullptr) { - openrct2_assert(water_type->image_id != 0xFFFFFFFF, "Failed to load water palette"); + Guard::Assert(water_type->image_id != 0xFFFFFFFF, "Failed to load water palette"); palette = water_type->image_id; } diff --git a/src/openrct2/drawing/SSE41Drawing.cpp b/src/openrct2/drawing/SSE41Drawing.cpp index 8e24a80e2b..6d5204780c 100644 --- a/src/openrct2/drawing/SSE41Drawing.cpp +++ b/src/openrct2/drawing/SSE41Drawing.cpp @@ -66,7 +66,7 @@ void MaskSse4_1( int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap) { - openrct2_assert(false, "SSE 4.1 function called on a CPU that doesn't support SSE 4.1"); + Guard::Fail("SSE 4.1 function called on a CPU that doesn't support SSE 4.1"); } #endif // __SSE4_1__ diff --git a/src/openrct2/entity/EntityRegistry.cpp b/src/openrct2/entity/EntityRegistry.cpp index 16ccc85db9..c8af092eb1 100644 --- a/src/openrct2/entity/EntityRegistry.cpp +++ b/src/openrct2/entity/EntityRegistry.cpp @@ -130,7 +130,7 @@ EntityBase* GetEntity(EntityId entityIndex) { return nullptr; } - openrct2_assert(entityIndex.ToUnderlying() < MAX_ENTITIES, "Tried getting entity %u", entityIndex.ToUnderlying()); + Guard::Assert(entityIndex.ToUnderlying() < MAX_ENTITIES, "Tried getting entity %u", entityIndex.ToUnderlying()); return TryGetEntity(entityIndex); } diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 9b49091334..a409438715 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -362,7 +362,7 @@ PeepActionSpriteType Peep::GetActionSpriteType() return PeepActionToSpriteTypeMap[EnumValue(Action)]; } - openrct2_assert( + Guard::Assert( EnumValue(Action) >= std::size(PeepActionToSpriteTypeMap) && Action < PeepActionType::Idle, "Invalid peep action %u", EnumValue(Action)); return PeepActionSpriteType::None; @@ -2640,7 +2640,7 @@ void IncrementGuestsInPark() } else { - openrct2_assert(false, "Attempt to increment guests in park above max value (65535)."); + Guard::Fail("Attempt to increment guests in park above max value (65535)."); } } @@ -2652,7 +2652,7 @@ void IncrementGuestsHeadingForPark() } else { - openrct2_assert(false, "Attempt to increment guests heading for park above max value (65535)."); + Guard::Fail("Attempt to increment guests heading for park above max value (65535)."); } } diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 7979d9a75f..833913f432 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -186,7 +186,7 @@ static int32_t BitCountPopcnt(uint32_t source) #elif defined(OpenRCT2_CPUID_MSVC_X86) return _mm_popcnt_u32(source); #else - openrct2_assert(false, "bitcount_popcnt() called, without support compiled in"); + Guard::Fail("bitcount_popcnt() called, without support compiled in"); return INT_MAX; #endif } diff --git a/src/openrct2/windows/Intent.cpp b/src/openrct2/windows/Intent.cpp index 614113ba6f..5fa865c573 100644 --- a/src/openrct2/windows/Intent.cpp +++ b/src/openrct2/windows/Intent.cpp @@ -106,7 +106,7 @@ void* Intent::GetPointerExtra(uint32_t key) const } auto data = _Data.at(key); - openrct2_assert(data.type == IntentData::DataType::Pointer, "Actual type doesn't match requested type"); + Guard::Assert(data.type == IntentData::DataType::Pointer, "Actual type doesn't match requested type"); return static_cast(data.pointerVal); } @@ -118,7 +118,7 @@ uint32_t Intent::GetUIntExtra(uint32_t key) const } auto data = _Data.at(key); - openrct2_assert(data.type == IntentData::DataType::Int, "Actual type doesn't match requested type"); + Guard::Assert(data.type == IntentData::DataType::Int, "Actual type doesn't match requested type"); return data.intVal.unsignedInt; } @@ -130,7 +130,7 @@ int32_t Intent::GetSIntExtra(uint32_t key) const } auto data = _Data.at(key); - openrct2_assert(data.type == IntentData::DataType::Int, "Actual type doesn't match requested type"); + Guard::Assert(data.type == IntentData::DataType::Int, "Actual type doesn't match requested type"); return data.intVal.signedInt; } @@ -142,7 +142,7 @@ std::string Intent::GetStringExtra(uint32_t key) const } auto data = _Data.at(key); - openrct2_assert(data.type == IntentData::DataType::String, "Actual type doesn't match requested type"); + Guard::Assert(data.type == IntentData::DataType::String, "Actual type doesn't match requested type"); return data.stringVal; } @@ -154,6 +154,6 @@ close_callback Intent::GetCloseCallbackExtra(uint32_t key) const } auto data = _Data.at(key); - openrct2_assert(data.type == IntentData::DataType::CloseCallback, "Actual type doesn't match requested type"); + Guard::Assert(data.type == IntentData::DataType::CloseCallback, "Actual type doesn't match requested type"); return data.closeCallbackVal; } diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 4ad42f8377..5a74d19e6c 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -794,8 +794,8 @@ static void MapGenSmoothHeightmap(std::vector& src, int32_t strength) void MapGenGenerateFromHeightmap(MapGenSettings* settings) { - openrct2_assert(!_heightMapData.mono_bitmap.empty(), "No height map loaded"); - openrct2_assert(settings->simplex_high != settings->simplex_low, "Low and high setting cannot be the same"); + Guard::Assert(!_heightMapData.mono_bitmap.empty(), "No height map loaded"); + Guard::Assert(settings->simplex_high != settings->simplex_low, "Low and high setting cannot be the same"); // Make a copy of the original height map that we can edit auto dest = _heightMapData.mono_bitmap; @@ -835,8 +835,8 @@ void MapGenGenerateFromHeightmap(MapGenSettings* settings) } } - openrct2_assert(maxValue > minValue, "Input range is invalid"); - openrct2_assert(settings->simplex_high > settings->simplex_low, "Output range is invalid"); + Guard::Assert(maxValue > minValue, "Input range is invalid"); + Guard::Assert(settings->simplex_high > settings->simplex_low, "Output range is invalid"); const uint8_t rangeIn = maxValue - minValue; const uint8_t rangeOut = settings->simplex_high - settings->simplex_low; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 0275e5cf6e..d3a2e0a095 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -839,7 +839,7 @@ namespace OpenRCT2::TileInspector // track_remove returns here on failure, not sure when this would ever be hit. Only thing I can think of is // for when you decrease the map size. - openrct2_assert(MapGetSurfaceElementAt(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5); + Guard::Assert(MapGetSurfaceElementAt(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5); MapInvalidateTileFull(elem); @@ -923,7 +923,7 @@ namespace OpenRCT2::TileInspector // track_remove returns here on failure, not sure when this would ever be hit. Only thing I can think of is // for when you decrease the map size. - openrct2_assert(MapGetSurfaceElementAt(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5); + Guard::Assert(MapGetSurfaceElementAt(elem) != nullptr, "No surface at %d,%d", elem.x >> 5, elem.y >> 5); MapInvalidateTileFull(elem);