Merge pull request #15129 from ZehMatt/refactor/clang-tidy-01

Minor cleanup
This commit is contained in:
Michael Steenbeek 2021-08-02 22:04:08 +02:00 committed by GitHub
commit 3c86d56933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 45 deletions

View File

@ -14,6 +14,7 @@
#include <openrct2/config/Config.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/interface/Cursors.h>
#include <vector>
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<uint8_t> scaleDataArray(const uint8_t data[], size_t width, size_t height, size_t scale)
{
size_t length = width * height;
auto* ret = static_cast<uint8_t*>(calloc(sizeof(uint8_t), length * scale * scale));
const size_t length = width * height;
std::vector<uint8_t> 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<int>(round(scale));
const auto integer_scale = static_cast<int>(round(scale));
auto data = scaleDataArray(cursorInfo->Data, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast<size_t>(integer_scale));
auto mask = scaleDataArray(cursorInfo->Mask, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast<size_t>(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;
}

View File

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

View File

@ -41,7 +41,7 @@ namespace OpenRCT2::Ui::Windows
struct ListViewColumn
{
bool CanSort{};
ColumnSortOrder SortOrder;
ColumnSortOrder SortOrder{};
std::string Header;
std::string HeaderTooltip;
std::optional<int32_t> RatioWidth{};

View File

@ -156,6 +156,7 @@ public:
if (tileElement == nullptr)
{
Close();
return;
}
auto bannerCoords = banner->position.ToCoordsXY();

View File

@ -126,7 +126,7 @@ namespace GameActions
GameActions::Status Error = GameActions::Status::Ok;
StringVariant ErrorTitle;
StringVariant ErrorMessage;
std::array<uint8_t, 32> ErrorMessageArgs;
std::array<uint8_t, 32> ErrorMessageArgs{};
CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL };
money32 Cost = 0;
ExpenditureType Expenditure = ExpenditureType::Count;

View File

@ -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<std::string, std::string> header = {};
std::string error = "";
std::string error;
};
struct Request
{
std::string url;
std::map<std::string, std::string> header = {};
std::map<std::string, std::string> 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<void(Response& res)> fn)
{
auto thread = std::thread([=]() {
Response res;
Response res{};
try
{
res = Do(req);

View File

@ -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<Staff>();
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<uint8_t>(staff->AssignedStaffType);
if (staffNameIndex > sizeof(staffNames))
if (staffNameIndex >= std::size(_staffNames))
{
staffNameIndex = 0;
}
ft.Add<rct_string_id>(staffNames[staffNameIndex]);
ft.Add<rct_string_id>(_staffNames[staffNameIndex]);
ft.Add<uint32_t>(Id);
}
else if (gParkFlags & PARK_FLAGS_SHOW_REAL_GUEST_NAMES)