mirror of https://github.com/OpenRCT2/OpenRCT2.git
Cleanup static_cast's
Cleanup static_cast's Cleanup static_casts' Cleanup static_casts' Format Code Address requested changes Address requested changes Change uint16_t to size_t Stop undefined behaviour Address requested changes.
This commit is contained in:
parent
3247d16ed8
commit
9ab18e37a2
|
@ -21,7 +21,7 @@
|
|||
#endif
|
||||
|
||||
[[maybe_unused]] static bool _log_location_enabled = true;
|
||||
bool _log_levels[static_cast<uint8_t>(DiagnosticLevel::Count)] = {
|
||||
bool _log_levels[EnumValue(DiagnosticLevel::Count)] = {
|
||||
true, true, true, false, true,
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,7 @@ void DiagnosticLog(DiagnosticLevel diagnosticLevel, const char* format, ...)
|
|||
{
|
||||
va_list args;
|
||||
|
||||
if (!_log_levels[static_cast<uint8_t>(diagnosticLevel)])
|
||||
if (!_log_levels[EnumValue(diagnosticLevel)])
|
||||
return;
|
||||
|
||||
va_start(args, format);
|
||||
|
@ -61,7 +61,7 @@ void DiagnosticLogWithLocation(
|
|||
va_list args;
|
||||
char buf[1024];
|
||||
|
||||
if (!_log_levels[static_cast<uint8_t>(diagnosticLevel)])
|
||||
if (!_log_levels[EnumValue(diagnosticLevel)])
|
||||
return;
|
||||
|
||||
snprintf(buf, 1024, "[%s:%d (%s)]: ", file, line, function);
|
||||
|
@ -89,7 +89,7 @@ static void DiagnosticPrint(DiagnosticLevel level, const std::string& prefix, co
|
|||
void DiagnosticLog(DiagnosticLevel diagnosticLevel, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
if (_log_levels[static_cast<uint8_t>(diagnosticLevel)])
|
||||
if (_log_levels[EnumValue(diagnosticLevel)])
|
||||
{
|
||||
// Level
|
||||
auto prefix = String::StdFormat("%s: ", _level_strings[EnumValue(diagnosticLevel)]);
|
||||
|
@ -107,7 +107,7 @@ void DiagnosticLogWithLocation(
|
|||
DiagnosticLevel diagnosticLevel, const char* file, const char* function, int32_t line, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
if (_log_levels[static_cast<uint8_t>(diagnosticLevel)])
|
||||
if (_log_levels[EnumValue(diagnosticLevel)])
|
||||
{
|
||||
// Level and source code information
|
||||
std::string prefix;
|
||||
|
|
|
@ -201,7 +201,7 @@ namespace Imaging
|
|||
}
|
||||
for (size_t i = 0; i < PNG_MAX_PALETTE_LENGTH; i++)
|
||||
{
|
||||
const auto& entry = (*image.Palette)[static_cast<uint16_t>(i)];
|
||||
const auto& entry = (*image.Palette)[i];
|
||||
png_palette[i].blue = entry.Blue;
|
||||
png_palette[i].green = entry.Green;
|
||||
png_palette[i].red = entry.Red;
|
||||
|
|
|
@ -44,13 +44,13 @@ struct PaletteBGRA
|
|||
uint8_t Alpha{};
|
||||
};
|
||||
|
||||
constexpr auto PALETTE_SIZE = 256;
|
||||
constexpr auto PALETTE_SIZE = 256U;
|
||||
|
||||
struct GamePalette
|
||||
{
|
||||
PaletteBGRA Colour[PALETTE_SIZE]{};
|
||||
|
||||
PaletteBGRA& operator[](uint16_t idx)
|
||||
PaletteBGRA& operator[](size_t idx)
|
||||
{
|
||||
assert(idx < PALETTE_SIZE);
|
||||
if (idx >= PALETTE_SIZE)
|
||||
|
@ -62,7 +62,7 @@ struct GamePalette
|
|||
return Colour[idx];
|
||||
}
|
||||
|
||||
const PaletteBGRA operator[](uint16_t idx) const
|
||||
const PaletteBGRA operator[](size_t idx) const
|
||||
{
|
||||
assert(idx < PALETTE_SIZE);
|
||||
if (idx >= PALETTE_SIZE)
|
||||
|
|
|
@ -305,7 +305,7 @@ int32_t ImageImporter::GetPaletteIndex(const GamePalette& palette, int16_t* colo
|
|||
{
|
||||
if (!IsTransparentPixel(colour))
|
||||
{
|
||||
for (int32_t i = 0; i < PALETTE_SIZE; i++)
|
||||
for (uint32_t i = 0; i < PALETTE_SIZE; i++)
|
||||
{
|
||||
if (static_cast<int16_t>(palette[i].Red) == colour[0] && static_cast<int16_t>(palette[i].Green) == colour[1]
|
||||
&& static_cast<int16_t>(palette[i].Blue) == colour[2])
|
||||
|
@ -363,7 +363,7 @@ int32_t ImageImporter::GetClosestPaletteIndex(const GamePalette& palette, const
|
|||
{
|
||||
auto smallestError = static_cast<uint32_t>(-1);
|
||||
auto bestMatch = PALETTE_TRANSPARENT;
|
||||
for (int32_t x = 0; x < PALETTE_SIZE; x++)
|
||||
for (uint32_t x = 0; x < PALETTE_SIZE; x++)
|
||||
{
|
||||
if (IsChangablePixel(x))
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "../ride/TrackDesign.h"
|
||||
#include "../scenario/Scenario.h"
|
||||
#include "../ui/UiContext.h"
|
||||
#include "../util/Util.h"
|
||||
#include "../world/Climate.h"
|
||||
#include "Drawing.h"
|
||||
#include "IDrawingEngine.h"
|
||||
|
@ -66,10 +67,10 @@ void DrawWeather(DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer)
|
|||
auto weatherLevel = GetGameState().ClimateCurrent.Level;
|
||||
if (weatherLevel != WeatherLevel::None && !gTrackDesignSaveMode && !(viewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
|
||||
{
|
||||
auto drawFunc = DrawRainFunctions[static_cast<int8_t>(weatherLevel)];
|
||||
auto drawFunc = DrawRainFunctions[EnumValue(weatherLevel)];
|
||||
if (ClimateIsSnowing())
|
||||
{
|
||||
drawFunc = DrawSnowFunctions[static_cast<int8_t>(weatherLevel)];
|
||||
drawFunc = DrawSnowFunctions[EnumValue(weatherLevel)];
|
||||
}
|
||||
auto uiContext = GetContext()->GetUiContext();
|
||||
uiContext->DrawWeatherAnimation(weatherDrawer, dpi, drawFunc);
|
||||
|
|
|
@ -156,9 +156,9 @@ static uint8_t FindClosestPaletteIndex(uint8_t red, uint8_t green, uint8_t blue)
|
|||
|
||||
static void InitBlendColourMap()
|
||||
{
|
||||
for (int i = 0; i < PALETTE_SIZE; i++)
|
||||
for (size_t i = 0; i < PALETTE_SIZE; i++)
|
||||
{
|
||||
for (int j = i; j < PALETTE_SIZE; j++)
|
||||
for (size_t j = i; j < PALETTE_SIZE; j++)
|
||||
{
|
||||
uint8_t red = (gPalette[i].Red + gPalette[j].Red) / 2;
|
||||
uint8_t green = (gPalette[i].Green + gPalette[j].Green) / 2;
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace OpenRCT2::Math::Trigonometry
|
|||
|
||||
constexpr int32_t ComputeHorizontalMagnitude(int32_t length, uint8_t pitch)
|
||||
{
|
||||
return (-PitchToDirectionVectorFromGeometry[static_cast<uint8_t>(pitch)].y * length) / 256;
|
||||
return (-PitchToDirectionVectorFromGeometry[pitch].y * length) / 256;
|
||||
}
|
||||
|
||||
constexpr CoordsXY ComputeXYVector(int32_t magnitude, uint8_t yaw)
|
||||
|
|
|
@ -4823,17 +4823,17 @@ void Vehicle::UpdateRotating()
|
|||
timeToSpriteMap = Rotation3TimeToSpriteMaps[sub_state];
|
||||
}
|
||||
|
||||
int32_t time = current_time;
|
||||
uint16_t time = current_time;
|
||||
if (_vehicleBreakdown == BREAKDOWN_CONTROL_FAILURE)
|
||||
{
|
||||
time += (curRide->breakdown_sound_modifier >> 6) + 1;
|
||||
}
|
||||
time++;
|
||||
|
||||
uint8_t sprite = timeToSpriteMap[static_cast<uint32_t>(time)];
|
||||
uint8_t sprite = timeToSpriteMap[time];
|
||||
if (sprite != 0xFF)
|
||||
{
|
||||
current_time = static_cast<uint16_t>(time);
|
||||
current_time = time;
|
||||
if (sprite == Pitch)
|
||||
return;
|
||||
Pitch = sprite;
|
||||
|
|
|
@ -31742,7 +31742,7 @@ static constexpr const VehicleInfoList *TrackVehicleInfoListReverserRCRearBogie[
|
|||
};
|
||||
|
||||
// rct2: 0x008B8F30
|
||||
constexpr const VehicleInfoList * const * gTrackVehicleInfo[static_cast<uint8_t>(VehicleTrackSubposition::Count)] = {
|
||||
constexpr const VehicleInfoList * const * gTrackVehicleInfo[EnumValue(VehicleTrackSubposition::Count)] = {
|
||||
TrackVehicleInfoListDefault, // VehicleTrackSubposition::Default
|
||||
TrackVehicleInfoListChairliftGoingOut, // VehicleTrackSubposition::ChairliftGoingOut
|
||||
TrackVehicleInfoListChairliftGoingBack, // VehicleTrackSubposition::ChairliftGoingBack
|
||||
|
|
|
@ -189,8 +189,7 @@ std::vector<DukValue> ScTrackSegment::getSubpositions(uint8_t trackSubposition,
|
|||
|
||||
for (auto idx = 0; idx < size; idx++)
|
||||
{
|
||||
result.push_back(
|
||||
ToDuk<VehicleInfo>(ctx, gTrackVehicleInfo[static_cast<uint8_t>(trackSubposition)][typeAndDirection]->info[idx]));
|
||||
result.push_back(ToDuk<VehicleInfo>(ctx, gTrackVehicleInfo[trackSubposition][typeAndDirection]->info[idx]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue