mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-19 21:13:05 +01:00
Use named casts on openrct2/(util|windows|scenario|title) (#11146)
This commit is contained in:
@@ -326,7 +326,7 @@ static void scenario_week_update()
|
||||
ride_check_all_reachable();
|
||||
ride_update_favourited_stat();
|
||||
|
||||
auto water_type = (rct_water_type*)object_entry_get_chunk(OBJECT_TYPE_WATER, 0);
|
||||
auto water_type = static_cast<rct_water_type*>(object_entry_get_chunk(OBJECT_TYPE_WATER, 0));
|
||||
|
||||
if (month <= MONTH_APRIL && water_type != nullptr && water_type->flags & WATER_FLAGS_ALLOW_DUCKS)
|
||||
{
|
||||
@@ -359,7 +359,7 @@ static void scenario_update_daynight_cycle()
|
||||
|
||||
if (gScreenFlags == SCREEN_FLAGS_PLAYING && gConfigGeneral.day_night_cycle)
|
||||
{
|
||||
float monthFraction = gDateMonthTicks / (float)0x10000;
|
||||
float monthFraction = gDateMonthTicks / static_cast<float>(0x10000);
|
||||
if (monthFraction < (1 / 8.0f))
|
||||
{
|
||||
gDayNightCycle = 0.0f;
|
||||
@@ -514,7 +514,7 @@ uint32_t scenario_rand_max(uint32_t max)
|
||||
return 0;
|
||||
if ((max & (max - 1)) == 0)
|
||||
return scenario_rand() & (max - 1);
|
||||
uint32_t rand, cap = ~((uint32_t)0) - (~((uint32_t)0) % max) - 1;
|
||||
uint32_t rand, cap = ~(static_cast<uint32_t>(0)) - (~(static_cast<uint32_t>(0)) % max) - 1;
|
||||
do
|
||||
{
|
||||
rand = scenario_rand();
|
||||
@@ -825,7 +825,7 @@ static void scenario_objective_check_guests_and_rating()
|
||||
gGuestInitialHappiness = 50;
|
||||
}
|
||||
}
|
||||
else if (gScenarioCompletedCompanyValue != (money32)0x80000001)
|
||||
else if (gScenarioCompletedCompanyValue != static_cast<money32>(0x80000001))
|
||||
{
|
||||
gScenarioParkRatingWarningDays = 0;
|
||||
}
|
||||
|
||||
@@ -468,13 +468,13 @@ private:
|
||||
scenario_index_entry* GetByFilename(const utf8* filename)
|
||||
{
|
||||
const ScenarioRepository* repo = this;
|
||||
return (scenario_index_entry*)repo->GetByFilename(filename);
|
||||
return const_cast<scenario_index_entry*>(repo->GetByFilename(filename));
|
||||
}
|
||||
|
||||
scenario_index_entry* GetByPath(const utf8* path)
|
||||
{
|
||||
const ScenarioRepository* repo = this;
|
||||
return (scenario_index_entry*)repo->GetByPath(path);
|
||||
return const_cast<scenario_index_entry*>(repo->GetByPath(path));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -729,7 +729,7 @@ private:
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
fs.WriteValue<uint32_t>(HighscoreFileVersion);
|
||||
fs.WriteValue<uint32_t>((uint32_t)_highscores.size());
|
||||
fs.WriteValue<uint32_t>(static_cast<uint32_t>(_highscores.size()));
|
||||
for (size_t i = 0; i < _highscores.size(); i++)
|
||||
{
|
||||
const scenario_highscore_entry* highscore = _highscores[i];
|
||||
|
||||
@@ -377,7 +377,7 @@ namespace ScenarioSources
|
||||
{
|
||||
outDesc->title = desc->Title;
|
||||
outDesc->id = desc->Id;
|
||||
outDesc->source = (uint8_t)i;
|
||||
outDesc->source = static_cast<uint8_t>(i);
|
||||
outDesc->index = currentIndex;
|
||||
outDesc->category = desc->Category;
|
||||
return true;
|
||||
|
||||
@@ -264,7 +264,7 @@ void TitleScreen::TitleInitialise()
|
||||
while (!safeSequence)
|
||||
{
|
||||
size_t total = TitleSequenceManager::GetCount();
|
||||
random = util_rand() % (int32_t)total;
|
||||
random = util_rand() % static_cast<int32_t>(total);
|
||||
const utf8* scName = title_sequence_manager_get_name(random);
|
||||
safeSequence = true;
|
||||
if (scName == RCT1String)
|
||||
@@ -291,7 +291,7 @@ void TitleScreen::TitleInitialise()
|
||||
seqId = 0;
|
||||
}
|
||||
}
|
||||
ChangePresetSequence((int32_t)seqId);
|
||||
ChangePresetSequence(static_cast<int32_t>(seqId));
|
||||
}
|
||||
|
||||
bool TitleScreen::TryLoadSequence(bool loadPreview)
|
||||
@@ -442,7 +442,7 @@ void DrawOpenRCT2(rct_drawpixelinfo* dpi, int32_t x, int32_t y)
|
||||
gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5 - 13);
|
||||
|
||||
// Invalidate screen area
|
||||
int16_t width = (int16_t)gfx_get_string_width(buffer);
|
||||
int16_t width = static_cast<int16_t>(gfx_get_string_width(buffer));
|
||||
gfx_set_dirty_blocks(x, y, x + width, y + 30); // 30 is an arbitrary height to catch both strings
|
||||
|
||||
// Write platform information
|
||||
|
||||
@@ -88,7 +88,7 @@ TitleSequence* LoadTitleSequence(const utf8* path)
|
||||
isZip = false;
|
||||
}
|
||||
|
||||
auto commands = LegacyScriptRead((utf8*)script.data(), script.size(), saves);
|
||||
auto commands = LegacyScriptRead(reinterpret_cast<utf8*>(script.data()), script.size(), saves);
|
||||
|
||||
TitleSequence* seq = CreateTitleSequence();
|
||||
seq->Name = Path::GetFileNameWithoutExtension(path);
|
||||
@@ -174,7 +174,7 @@ void TitleSequenceCloseParkHandle(TitleSequenceParkHandle* handle)
|
||||
if (handle != nullptr)
|
||||
{
|
||||
Memory::Free(handle->HintPath);
|
||||
delete ((IStream*)handle->Stream);
|
||||
delete (static_cast<IStream*>(handle->Stream));
|
||||
Memory::Free(handle);
|
||||
}
|
||||
}
|
||||
@@ -408,7 +408,7 @@ static std::vector<TitleCommand> LegacyScriptRead(utf8* script, size_t scriptLen
|
||||
{
|
||||
if (String::Equals(part1, saves[i], true))
|
||||
{
|
||||
command.SaveIndex = (uint8_t)i;
|
||||
command.SaveIndex = static_cast<uint8_t>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -544,7 +544,7 @@ static std::vector<uint8_t> ReadScriptFile(const utf8* path)
|
||||
try
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto size = (size_t)fs.GetLength();
|
||||
auto size = static_cast<size_t>(fs.GetLength());
|
||||
result.resize(size);
|
||||
fs.Read(result.data(), size);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ size_t sawyercoding_write_chunk_buffer(uint8_t* dst_file, const uint8_t* buffer,
|
||||
// fwrite(buffer, 1, chunkHeader.length, file);
|
||||
break;
|
||||
case CHUNK_ENCODING_RLE:
|
||||
encode_buffer = (uint8_t*)malloc(0x600000);
|
||||
chunkHeader.length = (uint32_t)encode_chunk_rle(buffer, encode_buffer, chunkHeader.length);
|
||||
encode_buffer = static_cast<uint8_t*>(malloc(0x600000));
|
||||
chunkHeader.length = static_cast<uint32_t>(encode_chunk_rle(buffer, encode_buffer, chunkHeader.length));
|
||||
std::memcpy(dst_file, &chunkHeader, sizeof(sawyercoding_chunk_header));
|
||||
dst_file += sizeof(sawyercoding_chunk_header);
|
||||
std::memcpy(dst_file, encode_buffer, chunkHeader.length);
|
||||
@@ -70,10 +70,10 @@ size_t sawyercoding_write_chunk_buffer(uint8_t* dst_file, const uint8_t* buffer,
|
||||
free(encode_buffer);
|
||||
break;
|
||||
case CHUNK_ENCODING_RLECOMPRESSED:
|
||||
encode_buffer = (uint8_t*)malloc(chunkHeader.length * 2);
|
||||
encode_buffer2 = (uint8_t*)malloc(0x600000);
|
||||
chunkHeader.length = (uint32_t)encode_chunk_repeat(buffer, encode_buffer, chunkHeader.length);
|
||||
chunkHeader.length = (uint32_t)encode_chunk_rle(encode_buffer, encode_buffer2, chunkHeader.length);
|
||||
encode_buffer = static_cast<uint8_t*>(malloc(chunkHeader.length * 2));
|
||||
encode_buffer2 = static_cast<uint8_t*>(malloc(0x600000));
|
||||
chunkHeader.length = static_cast<uint32_t>(encode_chunk_repeat(buffer, encode_buffer, chunkHeader.length));
|
||||
chunkHeader.length = static_cast<uint32_t>(encode_chunk_rle(encode_buffer, encode_buffer2, chunkHeader.length));
|
||||
std::memcpy(dst_file, &chunkHeader, sizeof(sawyercoding_chunk_header));
|
||||
dst_file += sizeof(sawyercoding_chunk_header);
|
||||
std::memcpy(dst_file, encode_buffer2, chunkHeader.length);
|
||||
@@ -82,7 +82,7 @@ size_t sawyercoding_write_chunk_buffer(uint8_t* dst_file, const uint8_t* buffer,
|
||||
free(encode_buffer);
|
||||
break;
|
||||
case CHUNK_ENCODING_ROTATE:
|
||||
encode_buffer = (uint8_t*)malloc(chunkHeader.length);
|
||||
encode_buffer = static_cast<uint8_t*>(malloc(chunkHeader.length));
|
||||
std::memcpy(encode_buffer, buffer, chunkHeader.length);
|
||||
encode_chunk_rotate(encode_buffer, chunkHeader.length);
|
||||
std::memcpy(dst_file, &chunkHeader, sizeof(sawyercoding_chunk_header));
|
||||
@@ -109,14 +109,14 @@ size_t sawyercoding_decode_sc4(const uint8_t* src, uint8_t* dst, size_t length,
|
||||
size_t decodedLength = decode_chunk_rle_with_size(src, dst, length - 4, bufferLength);
|
||||
|
||||
// Decode
|
||||
for (size_t i = 0x60018; i <= std::min(decodedLength - 1, (size_t)0x1F8353); i++)
|
||||
for (size_t i = 0x60018; i <= std::min(decodedLength - 1, static_cast<size_t>(0x1F8353)); i++)
|
||||
dst[i] = dst[i] ^ 0x9C;
|
||||
|
||||
for (size_t i = 0x60018; i <= std::min(decodedLength - 1, (size_t)0x1F8350); i += 4)
|
||||
for (size_t i = 0x60018; i <= std::min(decodedLength - 1, static_cast<size_t>(0x1F8350)); i += 4)
|
||||
{
|
||||
dst[i + 1] = ror8(dst[i + 1], 3);
|
||||
|
||||
uint32_t* code = (uint32_t*)&dst[i];
|
||||
uint32_t* code = reinterpret_cast<uint32_t*>(&dst[i]);
|
||||
*code = rol32(*code, 9);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ size_t sawyercoding_encode_sv4(const uint8_t* src, uint8_t* dst, size_t length)
|
||||
|
||||
// Append checksum
|
||||
checksum = sawyercoding_calculate_checksum(dst, encodedLength);
|
||||
*((uint32_t*)&dst[encodedLength]) = checksum;
|
||||
*(reinterpret_cast<uint32_t*>(&dst[encodedLength])) = checksum;
|
||||
|
||||
return encodedLength + 4;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ size_t sawyercoding_encode_td6(const uint8_t* src, uint8_t* dst, size_t length)
|
||||
}
|
||||
checksum -= 0x1D4C1;
|
||||
|
||||
*((uint32_t*)&dst[output_length]) = checksum;
|
||||
*(reinterpret_cast<uint32_t*>(&dst[output_length])) = checksum;
|
||||
output_length += 4;
|
||||
return output_length;
|
||||
}
|
||||
@@ -164,7 +164,7 @@ size_t sawyercoding_encode_td6(const uint8_t* src, uint8_t* dst, size_t length)
|
||||
/* Based off of rct2: 0x006770C1 */
|
||||
int32_t sawyercoding_validate_track_checksum(const uint8_t* src, size_t length)
|
||||
{
|
||||
uint32_t file_checksum = *((uint32_t*)&src[length - 4]);
|
||||
uint32_t file_checksum = *(reinterpret_cast<const uint32_t*>(&src[length - 4]));
|
||||
|
||||
uint32_t checksum = 0;
|
||||
for (size_t i = 0; i < length - 4; i++)
|
||||
@@ -205,12 +205,12 @@ static size_t decode_chunk_rle(const uint8_t* src_buffer, uint8_t* dst_buffer, s
|
||||
i++;
|
||||
count = 257 - rleCodeByte;
|
||||
std::fill_n(dst, count, src_buffer[i]);
|
||||
dst = (uint8_t*)((uintptr_t)dst + count);
|
||||
dst = reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(dst) + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(dst, src_buffer + i + 1, rleCodeByte + 1);
|
||||
dst = (uint8_t*)((uintptr_t)dst + rleCodeByte + 1);
|
||||
dst = reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(dst) + rleCodeByte + 1);
|
||||
i += rleCodeByte + 1;
|
||||
}
|
||||
}
|
||||
@@ -242,14 +242,14 @@ static size_t decode_chunk_rle_with_size(const uint8_t* src_buffer, uint8_t* dst
|
||||
assert(dst + count <= dst_buffer + dstSize);
|
||||
assert(i < length);
|
||||
std::fill_n(dst, count, src_buffer[i]);
|
||||
dst = (uint8_t*)((uintptr_t)dst + count);
|
||||
dst = reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(dst) + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(dst + rleCodeByte + 1 <= dst_buffer + dstSize);
|
||||
assert(i + 1 < length);
|
||||
std::memcpy(dst, src_buffer + i + 1, rleCodeByte + 1);
|
||||
dst = (uint8_t*)((uintptr_t)dst + rleCodeByte + 1);
|
||||
dst = reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(dst) + rleCodeByte + 1);
|
||||
i += rleCodeByte + 1;
|
||||
}
|
||||
}
|
||||
@@ -337,7 +337,7 @@ static size_t encode_chunk_repeat(const uint8_t* src_buffer, uint8_t* dst_buffer
|
||||
for (size_t repeatIndex = searchIndex; repeatIndex <= searchEnd; repeatIndex++)
|
||||
{
|
||||
size_t repeatCount = 0;
|
||||
size_t maxRepeatCount = std::min(std::min((size_t)7, searchEnd - repeatIndex), length - i - 1);
|
||||
size_t maxRepeatCount = std::min(std::min(static_cast<size_t>(7), searchEnd - repeatIndex), length - i - 1);
|
||||
// maxRepeatCount should not exceed length
|
||||
assert(repeatIndex + maxRepeatCount < length);
|
||||
assert(i + maxRepeatCount < length);
|
||||
@@ -372,7 +372,7 @@ static size_t encode_chunk_repeat(const uint8_t* src_buffer, uint8_t* dst_buffer
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst_buffer++ = (uint8_t)((bestRepeatCount - 1) | ((32 - (i - bestRepeatIndex)) << 3));
|
||||
*dst_buffer++ = static_cast<uint8_t>((bestRepeatCount - 1) | ((32 - (i - bestRepeatIndex)) << 3));
|
||||
outLength++;
|
||||
i += bestRepeatCount;
|
||||
}
|
||||
@@ -400,11 +400,11 @@ int32_t sawyercoding_detect_file_type(const uint8_t* src, size_t length)
|
||||
|
||||
// Currently can't detect TD4, as the checksum is the same as SC4 (need alternative method)
|
||||
|
||||
uint32_t checksum = *((uint32_t*)&src[length - 4]);
|
||||
uint32_t checksum = *(reinterpret_cast<const uint32_t*>(&src[length - 4]));
|
||||
uint32_t actualChecksum = 0;
|
||||
for (i = 0; i < length - 4; i++)
|
||||
{
|
||||
actualChecksum = (actualChecksum & 0xFFFFFF00) | (((actualChecksum & 0xFF) + (uint8_t)src[i]) & 0xFF);
|
||||
actualChecksum = (actualChecksum & 0xFFFFFF00) | (((actualChecksum & 0xFF) + static_cast<uint8_t>(src[i])) & 0xFF);
|
||||
actualChecksum = rol32(actualChecksum, 3);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@ bool filename_valid_characters(const utf8* filename)
|
||||
utf8* path_get_directory(const utf8* path)
|
||||
{
|
||||
// Find the last slash or backslash in the path
|
||||
char* filename = (char*)strrchr(path, *PATH_SEPARATOR);
|
||||
char* filename_posix = (char*)strrchr(path, '/');
|
||||
char* filename = const_cast<char*>(strrchr(path, *PATH_SEPARATOR));
|
||||
char* filename_posix = const_cast<char*>(strrchr(path, '/'));
|
||||
filename = filename < filename_posix ? filename_posix : filename;
|
||||
|
||||
// If the path is invalid (e.g. just a file name), return NULL
|
||||
@@ -83,8 +83,8 @@ utf8* path_get_directory(const utf8* path)
|
||||
const char* path_get_filename(const utf8* path)
|
||||
{
|
||||
// Find last slash or backslash in the path
|
||||
char* filename = (char*)strrchr(path, *PATH_SEPARATOR);
|
||||
char* filename_posix = (char*)strchr(path, '/');
|
||||
char* filename = const_cast<char*>(strrchr(path, *PATH_SEPARATOR));
|
||||
char* filename_posix = const_cast<char*>(strchr(path, '/'));
|
||||
filename = filename < filename_posix ? filename_posix : filename;
|
||||
|
||||
// Checks if the path is valid (e.g. not just a file name)
|
||||
@@ -108,11 +108,11 @@ const char* path_get_extension(const utf8* path)
|
||||
const char* filename = path_get_filename(path);
|
||||
|
||||
// Try to find the most-right dot in the filename
|
||||
char* extension = (char*)strrchr(filename, '.');
|
||||
char* extension = const_cast<char*>(strrchr(filename, '.'));
|
||||
|
||||
// When no dot was found, return a pointer to the null-terminator
|
||||
if (extension == nullptr)
|
||||
extension = (char*)strrchr(filename, '\0');
|
||||
extension = const_cast<char*>(strrchr(filename, '\0'));
|
||||
|
||||
return extension;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ void path_append_extension(utf8* path, const utf8* newExtension, size_t size)
|
||||
void path_remove_extension(utf8* path)
|
||||
{
|
||||
// Find last dot in filename, and replace it with a null-terminator
|
||||
char* lastDot = (char*)strrchr(path_get_filename(path), '.');
|
||||
char* lastDot = const_cast<char*>(strrchr(path_get_filename(path), '.'));
|
||||
if (lastDot != nullptr)
|
||||
*lastDot = '\0';
|
||||
else
|
||||
@@ -166,7 +166,7 @@ int32_t bitscanforward(int32_t source)
|
||||
{
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400) // Visual Studio 2005
|
||||
DWORD i;
|
||||
uint8_t success = _BitScanForward(&i, (uint32_t)source);
|
||||
uint8_t success = _BitScanForward(&i, static_cast<uint32_t>(source));
|
||||
return success != 0 ? i : -1;
|
||||
#elif defined(__GNUC__)
|
||||
int32_t success = __builtin_ffs(source);
|
||||
@@ -200,7 +200,7 @@ static bool cpuid_x86(uint32_t* cpuid_outdata, int32_t eax)
|
||||
int ret = __get_cpuid(eax, &cpuid_outdata[0], &cpuid_outdata[1], &cpuid_outdata[2], &cpuid_outdata[3]);
|
||||
return ret == 1;
|
||||
# elif defined(OpenRCT2_CPUID_MSVC_X86)
|
||||
__cpuid((int*)cpuid_outdata, (int)eax);
|
||||
__cpuid(reinterpret_cast<int*>(cpuid_outdata), static_cast<int>(eax));
|
||||
return true;
|
||||
# else
|
||||
return false;
|
||||
@@ -369,7 +369,7 @@ utf8* safe_strtrunc(utf8* text, size_t size)
|
||||
char* ch = text;
|
||||
char* last = text;
|
||||
uint32_t codepoint;
|
||||
while ((codepoint = utf8_get_next(ch, (const utf8**)&ch)) != 0)
|
||||
while ((codepoint = utf8_get_next(ch, const_cast<const utf8**>(&ch))) != 0)
|
||||
{
|
||||
if (ch <= sourceLimit)
|
||||
{
|
||||
@@ -487,7 +487,7 @@ char* strcasestr(const char* haystack, const char* needle)
|
||||
|
||||
while (*p1 != 0 && *p2 != 0)
|
||||
{
|
||||
if (tolower((unsigned char)*p1) == tolower((unsigned char)*p2))
|
||||
if (tolower(static_cast<unsigned char>(*p1)) == tolower(static_cast<unsigned char>(*p2)))
|
||||
{
|
||||
if (r == nullptr)
|
||||
r = p1;
|
||||
@@ -499,7 +499,7 @@ char* strcasestr(const char* haystack, const char* needle)
|
||||
if (r != nullptr)
|
||||
p1 = r + 1;
|
||||
|
||||
if (tolower((unsigned char)*p1) == tolower((unsigned char)*p2))
|
||||
if (tolower(static_cast<unsigned char>(*p1)) == tolower(static_cast<unsigned char>(*p2)))
|
||||
{
|
||||
r = p1;
|
||||
p2++;
|
||||
@@ -513,13 +513,14 @@ char* strcasestr(const char* haystack, const char* needle)
|
||||
p1++;
|
||||
}
|
||||
|
||||
return *p2 == 0 ? (char*)r : nullptr;
|
||||
return *p2 == 0 ? const_cast<char*>(r) : nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool utf8_is_bom(const char* str)
|
||||
{
|
||||
return str[0] == (char)(uint8_t)0xEF && str[1] == (char)(uint8_t)0xBB && str[2] == (char)(uint8_t)0xBF;
|
||||
return str[0] == static_cast<char>(static_cast<uint8_t>(0xEF)) && str[1] == static_cast<char>(static_cast<uint8_t>(0xBB))
|
||||
&& str[2] == static_cast<char>(static_cast<uint8_t>(0xBF));
|
||||
}
|
||||
|
||||
bool str_is_null_or_empty(const char* str)
|
||||
@@ -548,23 +549,24 @@ constexpr int32_t MAX_ZLIB_REALLOC = 4 * 1024 * 1024;
|
||||
uint8_t* util_zlib_inflate(uint8_t* data, size_t data_in_size, size_t* data_out_size)
|
||||
{
|
||||
int32_t ret = Z_OK;
|
||||
uLongf out_size = (uLong)*data_out_size;
|
||||
uLongf out_size = static_cast<uLong>(*data_out_size);
|
||||
if (out_size == 0)
|
||||
{
|
||||
// Try to guesstimate the size needed for output data by applying the
|
||||
// same ratio it would take to compress data_in_size.
|
||||
out_size = (uLong)data_in_size * (uLong)data_in_size / compressBound((uLong)data_in_size);
|
||||
out_size = std::min((uLongf)MAX_ZLIB_REALLOC, out_size);
|
||||
out_size = static_cast<uLong>(data_in_size) * static_cast<uLong>(data_in_size)
|
||||
/ compressBound(static_cast<uLong>(data_in_size));
|
||||
out_size = std::min(static_cast<uLongf>(MAX_ZLIB_REALLOC), out_size);
|
||||
}
|
||||
uLongf buffer_size = out_size;
|
||||
uint8_t* buffer = (uint8_t*)malloc(buffer_size);
|
||||
uint8_t* buffer = static_cast<uint8_t*>(malloc(buffer_size));
|
||||
do
|
||||
{
|
||||
if (ret == Z_BUF_ERROR)
|
||||
{
|
||||
buffer_size *= 2;
|
||||
out_size = buffer_size;
|
||||
buffer = (uint8_t*)realloc(buffer, buffer_size);
|
||||
buffer = static_cast<uint8_t*>(realloc(buffer, buffer_size));
|
||||
}
|
||||
else if (ret == Z_STREAM_ERROR)
|
||||
{
|
||||
@@ -578,9 +580,9 @@ uint8_t* util_zlib_inflate(uint8_t* data, size_t data_in_size, size_t* data_out_
|
||||
free(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
ret = uncompress(buffer, &out_size, data, (uLong)data_in_size);
|
||||
ret = uncompress(buffer, &out_size, data, static_cast<uLong>(data_in_size));
|
||||
} while (ret != Z_OK);
|
||||
buffer = (uint8_t*)realloc(buffer, out_size);
|
||||
buffer = static_cast<uint8_t*>(realloc(buffer, out_size));
|
||||
*data_out_size = out_size;
|
||||
return buffer;
|
||||
}
|
||||
@@ -596,16 +598,16 @@ uint8_t* util_zlib_inflate(uint8_t* data, size_t data_in_size, size_t* data_out_
|
||||
uint8_t* util_zlib_deflate(const uint8_t* data, size_t data_in_size, size_t* data_out_size)
|
||||
{
|
||||
int32_t ret = Z_OK;
|
||||
uLongf out_size = (uLongf)*data_out_size;
|
||||
uLong buffer_size = compressBound((uLong)data_in_size);
|
||||
uint8_t* buffer = (uint8_t*)malloc(buffer_size);
|
||||
uLongf out_size = static_cast<uLongf>(*data_out_size);
|
||||
uLong buffer_size = compressBound(static_cast<uLong>(data_in_size));
|
||||
uint8_t* buffer = static_cast<uint8_t*>(malloc(buffer_size));
|
||||
do
|
||||
{
|
||||
if (ret == Z_BUF_ERROR)
|
||||
{
|
||||
buffer_size *= 2;
|
||||
out_size = buffer_size;
|
||||
buffer = (uint8_t*)realloc(buffer, buffer_size);
|
||||
buffer = static_cast<uint8_t*>(realloc(buffer, buffer_size));
|
||||
}
|
||||
else if (ret == Z_STREAM_ERROR)
|
||||
{
|
||||
@@ -613,10 +615,10 @@ uint8_t* util_zlib_deflate(const uint8_t* data, size_t data_in_size, size_t* dat
|
||||
free(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
ret = compress(buffer, &out_size, data, (uLong)data_in_size);
|
||||
ret = compress(buffer, &out_size, data, static_cast<uLong>(data_in_size));
|
||||
} while (ret != Z_OK);
|
||||
*data_out_size = out_size;
|
||||
buffer = (uint8_t*)realloc(buffer, *data_out_size);
|
||||
buffer = static_cast<uint8_t*>(realloc(buffer, *data_out_size));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@@ -729,8 +731,8 @@ uint8_t lerp(uint8_t a, uint8_t b, float t)
|
||||
return b;
|
||||
|
||||
int32_t range = b - a;
|
||||
int32_t amount = (int32_t)(range * t);
|
||||
return (uint8_t)(a + amount);
|
||||
int32_t amount = static_cast<int32_t>(range * t);
|
||||
return static_cast<uint8_t>(a + amount);
|
||||
}
|
||||
|
||||
float flerp(float a, float b, float f)
|
||||
@@ -751,7 +753,7 @@ uint8_t soft_light(uint8_t a, uint8_t b)
|
||||
{
|
||||
fr = (2 * fa * (1 - fb)) + (std::sqrt(fa) * ((2 * fb) - 1));
|
||||
}
|
||||
return (uint8_t)(std::clamp(fr, 0.0f, 1.0f) * 255.0f);
|
||||
return static_cast<uint8_t>(std::clamp(fr, 0.0f, 1.0f) * 255.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,7 +87,7 @@ void* Intent::GetPointerExtra(uint32_t key) const
|
||||
|
||||
auto data = _Data.at(key);
|
||||
openrct2_assert(data.type == IntentData::DT_POINTER, "Actual type doesn't match requested type");
|
||||
return (void*)data.pointerVal;
|
||||
return static_cast<void*>(data.pointerVal);
|
||||
}
|
||||
|
||||
uint32_t Intent::GetUIntExtra(uint32_t key) const
|
||||
|
||||
Reference in New Issue
Block a user