mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #15129 from ZehMatt/refactor/clang-tidy-01
Minor cleanup
This commit is contained in:
commit
3c86d56933
|
@ -14,6 +14,7 @@
|
||||||
#include <openrct2/config/Config.h>
|
#include <openrct2/config/Config.h>
|
||||||
#include <openrct2/core/Guard.hpp>
|
#include <openrct2/core/Guard.hpp>
|
||||||
#include <openrct2/interface/Cursors.h>
|
#include <openrct2/interface/Cursors.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using namespace OpenRCT2::Ui;
|
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;
|
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;
|
size_t position = y * width + x;
|
||||||
data[position / 8] |= (1 << (7 - (position % 8)));
|
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++)
|
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;
|
const size_t length = width * height;
|
||||||
auto* ret = static_cast<uint8_t*>(calloc(sizeof(uint8_t), length * scale * scale));
|
|
||||||
|
std::vector<uint8_t> res;
|
||||||
|
res.resize(length * scale * scale);
|
||||||
|
|
||||||
for (size_t y = 0; y < height * 8; y++)
|
for (size_t y = 0; y < height * 8; y++)
|
||||||
{
|
{
|
||||||
for (size_t x = 0; x < width; x++)
|
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)
|
if (!value)
|
||||||
continue;
|
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* CursorRepository::Create(const CursorData* cursorInfo, uint8_t scale)
|
||||||
{
|
{
|
||||||
SDL_Cursor* cursor;
|
const auto integer_scale = static_cast<int>(round(scale));
|
||||||
|
|
||||||
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 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));
|
auto mask = scaleDataArray(cursorInfo->Mask, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast<size_t>(integer_scale));
|
||||||
|
|
||||||
cursor = SDL_CreateCursor(
|
auto* cursor = SDL_CreateCursor(
|
||||||
data, mask, BASE_CURSOR_WIDTH * integer_scale, BASE_CURSOR_HEIGHT * integer_scale,
|
data.data(), mask.data(), BASE_CURSOR_WIDTH * integer_scale, BASE_CURSOR_HEIGHT * integer_scale,
|
||||||
cursorInfo->HotSpot.X * integer_scale, cursorInfo->HotSpot.Y * integer_scale);
|
cursorInfo->HotSpot.X * integer_scale, cursorInfo->HotSpot.Y * integer_scale);
|
||||||
|
|
||||||
free(data);
|
|
||||||
free(mask);
|
|
||||||
|
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,11 +68,11 @@ namespace OpenRCT2::Audio
|
||||||
|
|
||||||
bool LoadWAV(SDL_RWops* rw)
|
bool LoadWAV(SDL_RWops* rw)
|
||||||
{
|
{
|
||||||
const uint32_t DATA = 0x61746164;
|
constexpr uint32_t DATA = 0x61746164;
|
||||||
const uint32_t FMT = 0x20746D66;
|
constexpr uint32_t FMT = 0x20746D66;
|
||||||
const uint32_t RIFF = 0x46464952;
|
constexpr uint32_t RIFF = 0x46464952;
|
||||||
const uint32_t WAVE = 0x45564157;
|
constexpr uint32_t WAVE = 0x45564157;
|
||||||
const uint16_t pcmformat = 0x0001;
|
constexpr uint16_t pcmformat = 0x0001;
|
||||||
|
|
||||||
Unload();
|
Unload();
|
||||||
|
|
||||||
|
@ -152,10 +152,10 @@ namespace OpenRCT2::Audio
|
||||||
{
|
{
|
||||||
return subchunkSize;
|
return subchunkSize;
|
||||||
}
|
}
|
||||||
const uint32_t FACT = 0x74636166;
|
constexpr uint32_t FACT = 0x74636166;
|
||||||
const uint32_t LIST = 0x5453494c;
|
constexpr uint32_t LIST = 0x5453494c;
|
||||||
const uint32_t BEXT = 0x74786562;
|
constexpr uint32_t BEXT = 0x74786562;
|
||||||
const uint32_t JUNK = 0x4B4E554A;
|
constexpr uint32_t JUNK = 0x4B4E554A;
|
||||||
while (subchunkId == FACT || subchunkId == LIST || subchunkId == BEXT || subchunkId == JUNK)
|
while (subchunkId == FACT || subchunkId == LIST || subchunkId == BEXT || subchunkId == JUNK)
|
||||||
{
|
{
|
||||||
SDL_RWseek(rw, subchunkSize, RW_SEEK_CUR);
|
SDL_RWseek(rw, subchunkSize, RW_SEEK_CUR);
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace OpenRCT2::Ui::Windows
|
||||||
struct ListViewColumn
|
struct ListViewColumn
|
||||||
{
|
{
|
||||||
bool CanSort{};
|
bool CanSort{};
|
||||||
ColumnSortOrder SortOrder;
|
ColumnSortOrder SortOrder{};
|
||||||
std::string Header;
|
std::string Header;
|
||||||
std::string HeaderTooltip;
|
std::string HeaderTooltip;
|
||||||
std::optional<int32_t> RatioWidth{};
|
std::optional<int32_t> RatioWidth{};
|
||||||
|
|
|
@ -156,6 +156,7 @@ public:
|
||||||
if (tileElement == nullptr)
|
if (tileElement == nullptr)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
auto bannerCoords = banner->position.ToCoordsXY();
|
auto bannerCoords = banner->position.ToCoordsXY();
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ namespace GameActions
|
||||||
GameActions::Status Error = GameActions::Status::Ok;
|
GameActions::Status Error = GameActions::Status::Ok;
|
||||||
StringVariant ErrorTitle;
|
StringVariant ErrorTitle;
|
||||||
StringVariant ErrorMessage;
|
StringVariant ErrorMessage;
|
||||||
std::array<uint8_t, 32> ErrorMessageArgs;
|
std::array<uint8_t, 32> ErrorMessageArgs{};
|
||||||
CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL };
|
CoordsXYZ Position = { LOCATION_NULL, LOCATION_NULL, LOCATION_NULL };
|
||||||
money32 Cost = 0;
|
money32 Cost = 0;
|
||||||
ExpenditureType Expenditure = ExpenditureType::Count;
|
ExpenditureType Expenditure = ExpenditureType::Count;
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace Http
|
||||||
{
|
{
|
||||||
enum class Status
|
enum class Status
|
||||||
{
|
{
|
||||||
|
Invalid = 0,
|
||||||
Ok = 200,
|
Ok = 200,
|
||||||
NotFound = 404
|
NotFound = 404
|
||||||
};
|
};
|
||||||
|
@ -35,20 +36,20 @@ namespace Http
|
||||||
|
|
||||||
struct Response
|
struct Response
|
||||||
{
|
{
|
||||||
Status status;
|
Status status{};
|
||||||
std::string content_type;
|
std::string content_type;
|
||||||
std::string body = "";
|
std::string body;
|
||||||
std::map<std::string, std::string> header = {};
|
std::map<std::string, std::string> header = {};
|
||||||
std::string error = "";
|
std::string error;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Request
|
struct Request
|
||||||
{
|
{
|
||||||
std::string url;
|
std::string url;
|
||||||
std::map<std::string, std::string> header = {};
|
std::map<std::string, std::string> header;
|
||||||
Method method = Method::GET;
|
Method method = Method::GET;
|
||||||
std::string body = "";
|
std::string body;
|
||||||
bool forceIPv4 = false;
|
bool forceIPv4{};
|
||||||
};
|
};
|
||||||
|
|
||||||
Response Do(const Request& req);
|
Response Do(const Request& req);
|
||||||
|
@ -56,7 +57,7 @@ namespace Http
|
||||||
inline void DoAsync(const Request& req, std::function<void(Response& res)> fn)
|
inline void DoAsync(const Request& req, std::function<void(Response& res)> fn)
|
||||||
{
|
{
|
||||||
auto thread = std::thread([=]() {
|
auto thread = std::thread([=]() {
|
||||||
Response res;
|
Response res{};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
res = Do(req);
|
res = Do(req);
|
||||||
|
|
|
@ -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
|
void Peep::FormatNameTo(Formatter& ft) const
|
||||||
{
|
{
|
||||||
if (Name == nullptr)
|
if (Name == nullptr)
|
||||||
|
@ -1467,20 +1474,13 @@ void Peep::FormatNameTo(Formatter& ft) const
|
||||||
auto* staff = As<Staff>();
|
auto* staff = As<Staff>();
|
||||||
if (staff != nullptr)
|
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);
|
auto staffNameIndex = static_cast<uint8_t>(staff->AssignedStaffType);
|
||||||
if (staffNameIndex > sizeof(staffNames))
|
if (staffNameIndex >= std::size(_staffNames))
|
||||||
{
|
{
|
||||||
staffNameIndex = 0;
|
staffNameIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ft.Add<rct_string_id>(staffNames[staffNameIndex]);
|
ft.Add<rct_string_id>(_staffNames[staffNameIndex]);
|
||||||
ft.Add<uint32_t>(Id);
|
ft.Add<uint32_t>(Id);
|
||||||
}
|
}
|
||||||
else if (gParkFlags & PARK_FLAGS_SHOW_REAL_GUEST_NAMES)
|
else if (gParkFlags & PARK_FLAGS_SHOW_REAL_GUEST_NAMES)
|
||||||
|
|
Loading…
Reference in New Issue