Replace openrct2_assert with Guard::Assert, remove openrct2_assert

This commit is contained in:
Matthias Moninger 2023-07-02 17:42:46 +03:00 committed by GitHub
parent 379287ed0f
commit 3ef6003671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 37 additions and 53 deletions

View File

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

View File

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

View File

@ -24,14 +24,6 @@
#include <cstdlib>
#include <string>
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.";

View File

@ -15,14 +15,6 @@
#include <stdbool.h>
#include <string>
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,

View File

@ -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__

View File

@ -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<size_t>(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)

View File

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

View File

@ -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__

View File

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

View File

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

View File

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

View File

@ -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<void*>(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;
}

View File

@ -794,8 +794,8 @@ static void MapGenSmoothHeightmap(std::vector<uint8_t>& 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;

View File

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