diff --git a/src/openrct2-ui/CursorRepository.cpp b/src/openrct2-ui/CursorRepository.cpp index 6fab01a596..4c703a1089 100644 --- a/src/openrct2-ui/CursorRepository.cpp +++ b/src/openrct2-ui/CursorRepository.cpp @@ -14,6 +14,7 @@ #include #include #include +#include using namespace OpenRCT2::Ui; @@ -45,19 +46,19 @@ void CursorRepository::SetCurrentCursor(CursorID cursorId) } } -static bool getBit(const uint8_t* data, size_t x, size_t y, size_t width) +static bool getBit(const uint8_t data[], size_t x, size_t y, size_t width) noexcept { - size_t position = y * width + x; + const size_t position = y * width + x; return (data[position / 8] & (1 << (7 - (x % 8)))) != 0; } -static void setBit(uint8_t* data, size_t x, size_t y, size_t width) +static void setBit(uint8_t data[], size_t x, size_t y, size_t width) noexcept { size_t position = y * width + x; data[position / 8] |= (1 << (7 - (position % 8))); } -static void drawRect(uint8_t* data, size_t x, size_t y, size_t width, size_t scale) +static void drawRect(uint8_t data[], size_t x, size_t y, size_t width, size_t scale) noexcept { for (size_t outY = (y * scale); outY < ((1 + y) * scale); outY++) { @@ -68,42 +69,39 @@ static void drawRect(uint8_t* data, size_t x, size_t y, size_t width, size_t sca } } -static uint8_t* scaleDataArray(const uint8_t data[], size_t width, size_t height, size_t scale) +static std::vector scaleDataArray(const uint8_t data[], size_t width, size_t height, size_t scale) { - size_t length = width * height; - auto* ret = static_cast(calloc(sizeof(uint8_t), length * scale * scale)); + const size_t length = width * height; + + std::vector res; + res.resize(length * scale * scale); for (size_t y = 0; y < height * 8; y++) { for (size_t x = 0; x < width; x++) { - bool value = getBit(data, x, y, width); + const bool value = getBit(data, x, y, width); if (!value) continue; - drawRect(ret, x, y, width, scale); + drawRect(res.data(), x, y, width, scale); } } - return ret; + return res; } SDL_Cursor* CursorRepository::Create(const CursorData* cursorInfo, uint8_t scale) { - SDL_Cursor* cursor; - - auto integer_scale = static_cast(round(scale)); + const auto integer_scale = static_cast(round(scale)); auto data = scaleDataArray(cursorInfo->Data, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast(integer_scale)); auto mask = scaleDataArray(cursorInfo->Mask, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast(integer_scale)); - cursor = SDL_CreateCursor( - data, mask, BASE_CURSOR_WIDTH * integer_scale, BASE_CURSOR_HEIGHT * integer_scale, + auto* cursor = SDL_CreateCursor( + data.data(), mask.data(), BASE_CURSOR_WIDTH * integer_scale, BASE_CURSOR_HEIGHT * integer_scale, cursorInfo->HotSpot.X * integer_scale, cursorInfo->HotSpot.Y * integer_scale); - free(data); - free(mask); - return cursor; } diff --git a/src/openrct2-ui/audio/FileAudioSource.cpp b/src/openrct2-ui/audio/FileAudioSource.cpp index 60f4087b25..b26257fc64 100644 --- a/src/openrct2-ui/audio/FileAudioSource.cpp +++ b/src/openrct2-ui/audio/FileAudioSource.cpp @@ -68,11 +68,11 @@ namespace OpenRCT2::Audio bool LoadWAV(SDL_RWops* rw) { - const uint32_t DATA = 0x61746164; - const uint32_t FMT = 0x20746D66; - const uint32_t RIFF = 0x46464952; - const uint32_t WAVE = 0x45564157; - const uint16_t pcmformat = 0x0001; + constexpr uint32_t DATA = 0x61746164; + constexpr uint32_t FMT = 0x20746D66; + constexpr uint32_t RIFF = 0x46464952; + constexpr uint32_t WAVE = 0x45564157; + constexpr uint16_t pcmformat = 0x0001; Unload(); @@ -152,10 +152,10 @@ namespace OpenRCT2::Audio { return subchunkSize; } - const uint32_t FACT = 0x74636166; - const uint32_t LIST = 0x5453494c; - const uint32_t BEXT = 0x74786562; - const uint32_t JUNK = 0x4B4E554A; + constexpr uint32_t FACT = 0x74636166; + constexpr uint32_t LIST = 0x5453494c; + constexpr uint32_t BEXT = 0x74786562; + constexpr uint32_t JUNK = 0x4B4E554A; while (subchunkId == FACT || subchunkId == LIST || subchunkId == BEXT || subchunkId == JUNK) { SDL_RWseek(rw, subchunkSize, RW_SEEK_CUR); diff --git a/src/openrct2-ui/scripting/CustomListView.h b/src/openrct2-ui/scripting/CustomListView.h index 093148cd58..43eb9edb4d 100644 --- a/src/openrct2-ui/scripting/CustomListView.h +++ b/src/openrct2-ui/scripting/CustomListView.h @@ -41,7 +41,7 @@ namespace OpenRCT2::Ui::Windows struct ListViewColumn { bool CanSort{}; - ColumnSortOrder SortOrder; + ColumnSortOrder SortOrder{}; std::string Header; std::string HeaderTooltip; std::optional RatioWidth{}; diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index 28836b9741..f6efda0d8c 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -156,6 +156,7 @@ public: if (tileElement == nullptr) { Close(); + return; } auto bannerCoords = banner->position.ToCoordsXY(); diff --git a/src/openrct2/actions/GameAction.h b/src/openrct2/actions/GameAction.h index 04ac4b2b36..856470f356 100644 --- a/src/openrct2/actions/GameAction.h +++ b/src/openrct2/actions/GameAction.h @@ -126,7 +126,7 @@ namespace GameActions GameActions::Status Error = GameActions::Status::Ok; StringVariant ErrorTitle; StringVariant ErrorMessage; - std::array ErrorMessageArgs; + std::array ErrorMessageArgs{}; CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL }; money32 Cost = 0; ExpenditureType Expenditure = ExpenditureType::Count; diff --git a/src/openrct2/core/Http.h b/src/openrct2/core/Http.h index 873d9b7e5e..e593518d3d 100644 --- a/src/openrct2/core/Http.h +++ b/src/openrct2/core/Http.h @@ -22,6 +22,7 @@ namespace Http { enum class Status { + Invalid = 0, Ok = 200, NotFound = 404 }; @@ -35,20 +36,20 @@ namespace Http struct Response { - Status status; + Status status{}; std::string content_type; - std::string body = ""; + std::string body; std::map header = {}; - std::string error = ""; + std::string error; }; struct Request { std::string url; - std::map header = {}; + std::map header; Method method = Method::GET; - std::string body = ""; - bool forceIPv4 = false; + std::string body; + bool forceIPv4{}; }; Response Do(const Request& req); @@ -56,7 +57,7 @@ namespace Http inline void DoAsync(const Request& req, std::function fn) { auto thread = std::thread([=]() { - Response res; + Response res{}; try { res = Do(req); diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 6e7fff074e..36f9f1e6a8 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1460,6 +1460,13 @@ void Peep::FormatActionTo(Formatter& ft) const } } +static constexpr const rct_string_id _staffNames[] = { + STR_HANDYMAN_X, + STR_MECHANIC_X, + STR_SECURITY_GUARD_X, + STR_ENTERTAINER_X, +}; + void Peep::FormatNameTo(Formatter& ft) const { if (Name == nullptr) @@ -1467,20 +1474,13 @@ void Peep::FormatNameTo(Formatter& ft) const auto* staff = As(); if (staff != nullptr) { - static constexpr const rct_string_id staffNames[] = { - STR_HANDYMAN_X, - STR_MECHANIC_X, - STR_SECURITY_GUARD_X, - STR_ENTERTAINER_X, - }; - auto staffNameIndex = static_cast(staff->AssignedStaffType); - if (staffNameIndex > sizeof(staffNames)) + if (staffNameIndex >= std::size(_staffNames)) { staffNameIndex = 0; } - ft.Add(staffNames[staffNameIndex]); + ft.Add(_staffNames[staffNameIndex]); ft.Add(Id); } else if (gParkFlags & PARK_FLAGS_SHOW_REAL_GUEST_NAMES)