From 9ef8d6da421399e69a687bcaf3a596702ce27009 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Sun, 7 Jun 2020 23:18:11 +0200 Subject: [PATCH] Convert most remaining C-style casts to C++-style ones (#11867) --- src/openrct2-ui/interface/Widget.cpp | 2 +- src/openrct2-ui/scripting/CustomWindow.cpp | 2 +- src/openrct2/Context.cpp | 3 +- src/openrct2/FileClassifier.cpp | 4 +-- src/openrct2/Game.cpp | 3 +- src/openrct2/PlatformEnvironment.cpp | 31 ++++++++++--------- src/openrct2/PlatformEnvironment.h | 4 +-- src/openrct2/actions/RideDemolishAction.hpp | 2 +- src/openrct2/core/File.cpp | 2 +- src/openrct2/core/Http.cURL.cpp | 6 ++-- src/openrct2/core/IStream.hpp | 5 ++- src/openrct2/core/Memory.hpp | 14 ++++----- src/openrct2/core/Numerics.hpp | 4 +-- src/openrct2/core/Random.hpp | 2 +- src/openrct2/core/String.cpp | 4 +-- src/openrct2/core/ZipAndroid.cpp | 2 +- src/openrct2/drawing/Drawing.String.cpp | 12 +++---- src/openrct2/drawing/ImageImporter.cpp | 2 +- src/openrct2/drawing/ScrollingText.cpp | 4 +-- src/openrct2/drawing/TTFSDLPort.cpp | 12 ++++--- src/openrct2/interface/Chat.cpp | 10 +++--- src/openrct2/interface/InteractiveConsole.cpp | 11 ++++--- src/openrct2/interface/Viewport.cpp | 7 +++-- .../localisation/ConversionTables.cpp | 4 +-- src/openrct2/localisation/Language.cpp | 2 +- src/openrct2/localisation/Localisation.cpp | 6 ++-- src/openrct2/localisation/UTF8.cpp | 2 +- src/openrct2/network/Network.cpp | 8 +++-- src/openrct2/network/NetworkPacket.h | 2 +- src/openrct2/network/Socket.cpp | 4 +-- src/openrct2/object/ImageTable.cpp | 2 +- src/openrct2/object/ObjectJsonHelpers.h | 2 +- src/openrct2/object/ObjectList.cpp | 4 +-- src/openrct2/object/ObjectManager.cpp | 6 ++-- src/openrct2/object/ObjectRepository.cpp | 9 +++--- src/openrct2/paint/Paint.cpp | 4 +-- src/openrct2/paint/sprite/Paint.Sprite.cpp | 8 ++--- .../paint/tile_element/Paint.LargeScenery.cpp | 6 ++-- src/openrct2/rct12/RCT12.h | 5 +-- src/openrct2/rct2/S6Exporter.cpp | 2 +- src/openrct2/scripting/ScObject.hpp | 2 +- src/openrct2/scripting/ScriptEngine.cpp | 3 +- src/openrct2/world/TileElement.h | 4 +-- 43 files changed, 126 insertions(+), 107 deletions(-) diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 251da4fd97..fb5d2c1533 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -452,7 +452,7 @@ static std::pair widget_get_stringid_and_args(const rct_wi else { stringId = STR_STRING; - formatArgs = (void*)&widget->string; + formatArgs = reinterpret_cast(widget->string); } } return std::make_pair(stringId, formatArgs); diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index b7dac7135b..02a8f7ed42 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -840,7 +840,7 @@ namespace OpenRCT2::Ui::Windows else if (desc.Type == "dropdown") { widget.type = WWT_DROPDOWN; - if (desc.SelectedIndex >= 0 && (size_t)desc.SelectedIndex < desc.Items.size()) + if (desc.SelectedIndex >= 0 && static_cast(desc.SelectedIndex) < desc.Items.size()) { widget.string = const_cast(desc.Items[desc.SelectedIndex].c_str()); } diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index a00e49f0a5..4fcfd1e40c 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -637,8 +637,7 @@ namespace OpenRCT2 // which the window function doesn't like auto intent = Intent(WC_OBJECT_LOAD_ERROR); intent.putExtra(INTENT_EXTRA_PATH, path); - // TODO: CAST-IMPROVEMENT-NEEDED - intent.putExtra(INTENT_EXTRA_LIST, (void*)e.MissingObjects.data()); + intent.putExtra(INTENT_EXTRA_LIST, const_cast(e.MissingObjects.data())); intent.putExtra(INTENT_EXTRA_LIST_COUNT, static_cast(e.MissingObjects.size())); auto windowManager = _uiContext->GetWindowManager(); diff --git a/src/openrct2/FileClassifier.cpp b/src/openrct2/FileClassifier.cpp index 42b956eb66..9db7d0eeea 100644 --- a/src/openrct2/FileClassifier.cpp +++ b/src/openrct2/FileClassifier.cpp @@ -95,7 +95,7 @@ static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result) uint64_t originalPosition = stream->GetPosition(); try { - size_t dataLength = (size_t)stream->GetLength(); + size_t dataLength = static_cast(stream->GetLength()); auto deleter_lambda = [dataLength](uint8_t* ptr) { Memory::FreeArray(ptr, dataLength); }; std::unique_ptr data(stream->ReadArray(dataLength), deleter_lambda); stream->SetPosition(originalPosition); @@ -132,7 +132,7 @@ static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result) uint64_t originalPosition = stream->GetPosition(); try { - size_t dataLength = (size_t)stream->GetLength(); + size_t dataLength = static_cast(stream->GetLength()); auto deleter_lambda = [dataLength](uint8_t* ptr) { Memory::FreeArray(ptr, dataLength); }; std::unique_ptr data(stream->ReadArray(dataLength), deleter_lambda); stream->SetPosition(originalPosition); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 5c6234d795..da24842e4f 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -683,8 +683,7 @@ void save_game_as() static int32_t compare_autosave_file_paths(const void* a, const void* b) { - // TODO: CAST-IMPROVEMENT-NEEDED - return strcmp(*(char**)a, *(char**)b); + return strcmp(static_cast(a), static_cast(b)); } static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processLandscapeFolder) diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 4b25f4de76..5e9898c2ac 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -26,7 +26,7 @@ private: public: explicit PlatformEnvironment(DIRBASE_VALUES basePaths) { - for (int32_t i = 0; i < DIRBASE_COUNT; i++) + for (size_t i = 0; i < DIRBASE_COUNT; i++) { _basePath[i] = basePaths[i]; } @@ -124,35 +124,38 @@ std::unique_ptr OpenRCT2::CreatePlatformEnvironment() // Set default paths std::string basePaths[DIRBASE_COUNT]; - basePaths[(size_t)DIRBASE::OPENRCT2] = Platform::GetInstallPath(); - basePaths[(size_t)DIRBASE::USER] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_DATA), subDirectory); - basePaths[(size_t)DIRBASE::CONFIG] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CONFIG), subDirectory); - basePaths[(size_t)DIRBASE::CACHE] = Path::Combine(Platform::GetFolderPath(SPECIAL_FOLDER::USER_CACHE), subDirectory); - basePaths[(size_t)DIRBASE::DOCUMENTATION] = Platform::GetDocsPath(); + basePaths[static_cast(DIRBASE::OPENRCT2)] = Platform::GetInstallPath(); + basePaths[static_cast(DIRBASE::USER)] = Path::Combine( + Platform::GetFolderPath(SPECIAL_FOLDER::USER_DATA), subDirectory); + basePaths[static_cast(DIRBASE::CONFIG)] = Path::Combine( + Platform::GetFolderPath(SPECIAL_FOLDER::USER_CONFIG), subDirectory); + basePaths[static_cast(DIRBASE::CACHE)] = Path::Combine( + Platform::GetFolderPath(SPECIAL_FOLDER::USER_CACHE), subDirectory); + basePaths[static_cast(DIRBASE::DOCUMENTATION)] = Platform::GetDocsPath(); // Override paths that have been specified via the command line if (!String::IsNullOrEmpty(gCustomRCT1DataPath)) { - basePaths[(size_t)DIRBASE::RCT1] = gCustomRCT1DataPath; + basePaths[static_cast(DIRBASE::RCT1)] = gCustomRCT1DataPath; } if (!String::IsNullOrEmpty(gCustomRCT2DataPath)) { - basePaths[(size_t)DIRBASE::RCT2] = gCustomRCT2DataPath; + basePaths[static_cast(DIRBASE::RCT2)] = gCustomRCT2DataPath; } if (!String::IsNullOrEmpty(gCustomOpenrctDataPath)) { - basePaths[(size_t)DIRBASE::OPENRCT2] = gCustomOpenrctDataPath; + basePaths[static_cast(DIRBASE::OPENRCT2)] = gCustomOpenrctDataPath; } if (!String::IsNullOrEmpty(gCustomUserDataPath)) { - basePaths[(size_t)DIRBASE::USER] = gCustomUserDataPath; - basePaths[(size_t)DIRBASE::CONFIG] = gCustomUserDataPath; - basePaths[(size_t)DIRBASE::CACHE] = gCustomUserDataPath; + basePaths[static_cast(DIRBASE::USER)] = gCustomUserDataPath; + basePaths[static_cast(DIRBASE::CONFIG)] = gCustomUserDataPath; + basePaths[static_cast(DIRBASE::CACHE)] = gCustomUserDataPath; } - if (basePaths[(size_t)DIRBASE::DOCUMENTATION].empty()) + if (basePaths[static_cast(DIRBASE::DOCUMENTATION)].empty()) { - basePaths[(size_t)DIRBASE::DOCUMENTATION] = basePaths[static_cast(DIRBASE::OPENRCT2)]; + basePaths[static_cast(DIRBASE::DOCUMENTATION)] = basePaths[static_cast(DIRBASE::OPENRCT2)]; } auto env = OpenRCT2::CreatePlatformEnvironment(basePaths); diff --git a/src/openrct2/PlatformEnvironment.h b/src/openrct2/PlatformEnvironment.h index a7024e2921..8b95f6ae75 100644 --- a/src/openrct2/PlatformEnvironment.h +++ b/src/openrct2/PlatformEnvironment.h @@ -16,7 +16,7 @@ namespace OpenRCT2 { - enum class DIRBASE : int32_t + enum class DIRBASE : size_t { RCT1, // Base directory for original RollerCoaster Tycoon 1 content. RCT2, // Base directory for original RollerCoaster Tycoon 2 content. @@ -26,7 +26,7 @@ namespace OpenRCT2 CACHE, // Base directory for OpenRCT2 cache files. DOCUMENTATION, // Base directory for OpenRCT2 doc files. }; - constexpr int32_t DIRBASE_COUNT = 7; + constexpr size_t DIRBASE_COUNT = 7; using DIRBASE_VALUES = std::string[DIRBASE_COUNT]; enum class DIRID diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index 07314d1037..789c6d23bf 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -305,7 +305,7 @@ private: if (it.element->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; - if (it.element->AsTrack()->GetRideIndex() != (ride_id_t)_rideIndex) + if (it.element->AsTrack()->GetRideIndex() != static_cast(_rideIndex)) continue; auto location = CoordsXYZD( diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index 4f8a8648ba..21ff19c8e0 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -60,7 +60,7 @@ namespace File } fs.seekg(0, std::ios::end); - auto fsize = (size_t)fs.tellg(); + auto fsize = static_cast(fs.tellg()); if (fsize > SIZE_MAX) { std::string message = String::StdFormat( diff --git a/src/openrct2/core/Http.cURL.cpp b/src/openrct2/core/Http.cURL.cpp index 3a1f690851..8af20a3b39 100644 --- a/src/openrct2/core/Http.cURL.cpp +++ b/src/openrct2/core/Http.cURL.cpp @@ -99,7 +99,7 @@ namespace Http curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); curl_easy_setopt(curl, CURLOPT_READDATA, &wt); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)wt.sizeleft); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, static_cast(wt.sizeleft)); } if (req.forceIPv4) @@ -114,9 +114,9 @@ namespace Http curl_easy_setopt(curl, CURLOPT_URL, req.url.c_str()); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&res); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast(&res)); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback); - curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void*)&res); + curl_easy_setopt(curl, CURLOPT_HEADERDATA, static_cast(&res)); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true); curl_easy_setopt(curl, CURLOPT_USERAGENT, OPENRCT2_USER_AGENT); diff --git a/src/openrct2/core/IStream.hpp b/src/openrct2/core/IStream.hpp index d17e089a01..b062a0e5a9 100644 --- a/src/openrct2/core/IStream.hpp +++ b/src/openrct2/core/IStream.hpp @@ -226,7 +226,10 @@ private: public: explicit vector_streambuf(const std::vector& vec) { - this->setg((char*)vec.data(), (char*)vec.data(), (char*)(vec.data() + vec.size())); + this->setg( + reinterpret_cast(const_cast(vec.data())), + reinterpret_cast(const_cast(vec.data())), + reinterpret_cast(const_cast(vec.data() + vec.size()))); } }; diff --git a/src/openrct2/core/Memory.hpp b/src/openrct2/core/Memory.hpp index c2096c876b..891b0d751c 100644 --- a/src/openrct2/core/Memory.hpp +++ b/src/openrct2/core/Memory.hpp @@ -23,21 +23,21 @@ namespace Memory { template static T* Allocate() { - T* result = (T*)malloc(sizeof(T)); + T* result = static_cast(malloc(sizeof(T))); Guard::ArgumentNotNull(result, "Failed to allocate %zu bytes for %s", sizeof(T), typeid(T).name()); return result; } template static T* Allocate(size_t size) { - T* result = (T*)malloc(size); + T* result = static_cast(malloc(size)); Guard::ArgumentNotNull(result, "Failed to allocate %zu bytes for %s", size, typeid(T).name()); return result; } template static T* AllocateArray(size_t count) { - T* result = (T*)malloc(count * sizeof(T)); + T* result = static_cast(malloc(count * sizeof(T))); Guard::ArgumentNotNull(result, "Failed to allocate array of %zu * %s (%zu bytes)", count, typeid(T).name(), sizeof(T)); return result; } @@ -47,11 +47,11 @@ namespace Memory T* result; if (ptr == nullptr) { - result = (T*)malloc(size); + result = static_cast(malloc(size)); } else { - result = (T*)realloc((void*)ptr, size); + result = static_cast(realloc(reinterpret_cast(ptr), size)); } Guard::ArgumentNotNull(result, "Failed to reallocate %x (%s) to have %zu bytes", ptr, typeid(T).name(), size); return result; @@ -62,11 +62,11 @@ namespace Memory T* result; if (ptr == nullptr) { - result = (T*)malloc(count * sizeof(T)); + result = static_cast(malloc(count * sizeof(T))); } else { - result = (T*)realloc((void*)ptr, count * sizeof(T)); + result = static_cast(realloc(reinterpret_cast(ptr), count * sizeof(T))); } Guard::ArgumentNotNull( result, "Failed to reallocate array at %x (%s) to have %zu entries", ptr, typeid(T).name(), count); diff --git a/src/openrct2/core/Numerics.hpp b/src/openrct2/core/Numerics.hpp index e699e0c8a0..dd7fa85275 100644 --- a/src/openrct2/core/Numerics.hpp +++ b/src/openrct2/core/Numerics.hpp @@ -27,7 +27,7 @@ namespace Numerics { static_assert(std::is_unsigned<_UIntType>::value, "result_type must be an unsigned integral type"); using limits = typename std::numeric_limits<_UIntType>; - return (((_UIntType)(x) << shift) | ((_UIntType)(x) >> (limits::digits - shift))); + return ((static_cast<_UIntType>(x) << shift) | (static_cast<_UIntType>(x) >> (limits::digits - shift))); } /** @@ -53,7 +53,7 @@ namespace Numerics { static_assert(std::is_unsigned<_UIntType>::value, "result_type must be an unsigned integral type"); using limits = std::numeric_limits<_UIntType>; - return (((_UIntType)(x) >> shift) | ((_UIntType)(x) << (limits::digits - shift))); + return ((static_cast<_UIntType>(x) >> shift) | (static_cast<_UIntType>(x) << (limits::digits - shift))); } /** diff --git a/src/openrct2/core/Random.hpp b/src/openrct2/core/Random.hpp index cdca9daa73..b8e3c9dd4a 100644 --- a/src/openrct2/core/Random.hpp +++ b/src/openrct2/core/Random.hpp @@ -62,7 +62,7 @@ namespace Random template void generate(_TIt begin, _TIt end) const { - std::copy_n(v.begin(), std::min((size_t)(end - begin), N), begin); + std::copy_n(v.begin(), std::min(static_cast(end - begin), N), begin); } constexpr size_t size() const diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index a4efe37907..c2c940337a 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -454,7 +454,7 @@ namespace String utf8* SkipBOM(utf8* buffer) { - return const_cast(SkipBOM((const utf8*)buffer)); + return const_cast(SkipBOM(static_cast(buffer))); } const utf8* SkipBOM(const utf8* buffer) @@ -474,7 +474,7 @@ namespace String codepoint_t GetNextCodepoint(utf8* ptr, utf8** nextPtr) { - return GetNextCodepoint((const utf8*)ptr, (const utf8**)nextPtr); + return GetNextCodepoint(static_cast(ptr), const_cast(nextPtr)); } codepoint_t GetNextCodepoint(const utf8* ptr, const utf8** nextPtr) diff --git a/src/openrct2/core/ZipAndroid.cpp b/src/openrct2/core/ZipAndroid.cpp index f39978b715..a7e3afdf23 100644 --- a/src/openrct2/core/ZipAndroid.cpp +++ b/src/openrct2/core/ZipAndroid.cpp @@ -59,7 +59,7 @@ public: jclass zipClass = env->GetObjectClass(_zip); jmethodID fileCountMethod = env->GetMethodID(zipClass, "getNumFiles", "()I"); - return (size_t)env->CallIntMethod(_zip, fileCountMethod); + return static_cast(env->CallIntMethod(_zip, fileCountMethod)); } std::string GetFileName(size_t index) const override diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index a12b69732a..b939830698 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -46,7 +46,7 @@ int32_t gfx_get_string_width_new_lined(utf8* text) int32_t codepoint; int32_t maxWidth = 0; - while ((codepoint = utf8_get_next(ch, (const utf8**)&nextCh)) != 0) + while ((codepoint = utf8_get_next(ch, const_cast(&nextCh))) != 0) { if (codepoint == FORMAT_NEWLINE || codepoint == FORMAT_NEWLINE_SMALLER) { @@ -102,7 +102,7 @@ int32_t gfx_clip_string(utf8* text, int32_t width) utf8* nextCh = text; utf8* clipCh = text; int32_t codepoint; - while ((codepoint = utf8_get_next(ch, (const utf8**)&nextCh)) != 0) + while ((codepoint = utf8_get_next(ch, const_cast(&nextCh))) != 0) { if (utf8_is_format_code(codepoint)) { @@ -176,7 +176,7 @@ int32_t gfx_wrap_string(utf8* text, int32_t width, int32_t* outNumLines, int32_t utf8* nextCh; int32_t codepoint; int32_t numCharactersOnLine = 0; - while ((codepoint = utf8_get_next(ch, (const utf8**)&nextCh)) != 0) + while ((codepoint = utf8_get_next(ch, const_cast(&nextCh))) != 0) { if (codepoint == ' ') { @@ -313,7 +313,7 @@ void draw_string_centred_raw(rct_drawpixelinfo* dpi, int32_t x, int32_t y, int32 { ScreenCoordsXY screenCoords(dpi->x, dpi->y); gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; - gfx_draw_string(dpi, (char*)"", COLOUR_BLACK, screenCoords); + gfx_draw_string(dpi, "", COLOUR_BLACK, screenCoords); screenCoords = { x, y }; gCurrentFontFlags = 0; @@ -429,7 +429,7 @@ void gfx_draw_string_centred_wrapped_partial( ScreenCoordsXY screenCoords(dpi->x, dpi->y); gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; - gfx_draw_string(dpi, (char*)"", colour, screenCoords); + gfx_draw_string(dpi, "", colour, screenCoords); format_string(buffer, 256, format, args); gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; @@ -448,7 +448,7 @@ void gfx_draw_string_centred_wrapped_partial( utf8* ch = buffer; utf8* nextCh; int32_t codepoint; - while ((codepoint = utf8_get_next(ch, (const utf8**)&nextCh)) != 0) + while ((codepoint = utf8_get_next(ch, const_cast(&nextCh))) != 0) { if (!utf8_is_format_code(codepoint)) { diff --git a/src/openrct2/drawing/ImageImporter.cpp b/src/openrct2/drawing/ImageImporter.cpp index 65d99de5e8..2e771c005b 100644 --- a/src/openrct2/drawing/ImageImporter.cpp +++ b/src/openrct2/drawing/ImageImporter.cpp @@ -142,7 +142,7 @@ std::tuple ImageImporter::EncodeRLE(const int32_t* pixels, uint32 { yOffsets[y] = static_cast(dst - buffer); - auto previousCode = (RLECode*)nullptr; + auto previousCode = static_cast(nullptr); auto currentCode = reinterpret_cast(dst); dst += 2; diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index efb08e1040..686287cf1b 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -1497,7 +1497,7 @@ static void scrolling_text_set_bitmap_for_sprite( utf8* ch = text; while (true) { - uint32_t codepoint = utf8_get_next(ch, (const utf8**)&ch); + uint32_t codepoint = utf8_get_next(ch, const_cast(&ch)); // If at the end of the string loop back to the start if (codepoint == 0) @@ -1567,7 +1567,7 @@ static void scrolling_text_set_bitmap_for_ttf( utf8* dstCh = text; utf8* ch = text; int32_t codepoint; - while ((codepoint = utf8_get_next(ch, (const utf8**)&ch)) != 0) + while ((codepoint = utf8_get_next(ch, const_cast(&ch))) != 0) { if (utf8_is_format_code(codepoint)) { diff --git a/src/openrct2/drawing/TTFSDLPort.cpp b/src/openrct2/drawing/TTFSDLPort.cpp index 7be6922cf3..9b058d93b4 100644 --- a/src/openrct2/drawing/TTFSDLPort.cpp +++ b/src/openrct2/drawing/TTFSDLPort.cpp @@ -1,3 +1,7 @@ +// Adapted from freetype.h in order to avoid C-style casts. + +#define FT_LOAD_TARGET_ALT(x) (static_cast((x)&15) << 16) + /** * The following code is from SDL2_ttf (2 Jan 2017). * Taking just what was needed for OpenRCT2 with all SDL2 calls @@ -1530,9 +1534,9 @@ TTFSurface* TTF_RenderUTF8_Shaded(TTF_Font* font, const char* text, [[maybe_unus void TTF_SetFontHinting(TTF_Font* font, int hinting) { if (hinting == TTF_HINTING_LIGHT) - font->hinting = FT_LOAD_TARGET_LIGHT; + font->hinting = FT_LOAD_TARGET_ALT(FT_RENDER_MODE_LIGHT); else if (hinting == TTF_HINTING_MONO) - font->hinting = FT_LOAD_TARGET_MONO; + font->hinting = FT_LOAD_TARGET_ALT(FT_RENDER_MODE_MONO); else if (hinting == TTF_HINTING_NONE) font->hinting = FT_LOAD_NO_HINTING; else @@ -1543,9 +1547,9 @@ void TTF_SetFontHinting(TTF_Font* font, int hinting) int TTF_GetFontHinting(const TTF_Font* font) { - if (font->hinting == FT_LOAD_TARGET_LIGHT) + if (font->hinting == FT_LOAD_TARGET_ALT(FT_RENDER_MODE_LIGHT)) return TTF_HINTING_LIGHT; - else if (font->hinting == FT_LOAD_TARGET_MONO) + else if (font->hinting == FT_LOAD_TARGET_ALT(FT_RENDER_MODE_MONO)) return TTF_HINTING_MONO; else if (font->hinting == FT_LOAD_NO_HINTING) return TTF_HINTING_NONE; diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index 25ede91aba..a1ffe5dedc 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -102,7 +102,7 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor) // Draw chat window if (gChatOpen) { - inputLineHeight = chat_string_wrapped_get_height((void*)&inputLine, _chatWidth - 10); + inputLineHeight = chat_string_wrapped_get_height(static_cast(&inputLine), _chatWidth - 10); _chatTop -= inputLineHeight; for (int32_t i = 0; i < CHAT_HISTORY_SIZE; i++) @@ -114,7 +114,7 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor) safe_strcpy(lineBuffer, chat_history_get(i), sizeof(lineBuffer)); - int32_t lineHeight = chat_string_wrapped_get_height((void*)&lineCh, _chatWidth - 10); + int32_t lineHeight = chat_string_wrapped_get_height(static_cast(&lineCh), _chatWidth - 10); _chatTop -= (lineHeight + 5); } @@ -157,7 +157,7 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor) safe_strcpy(lineBuffer, chat_history_get(i), sizeof(lineBuffer)); - stringHeight = chat_history_draw_string(dpi, (void*)&lineCh, ScreenCoordsXY(x, y), _chatWidth - 10) + 5; + stringHeight = chat_history_draw_string(dpi, static_cast(&lineCh), ScreenCoordsXY(x, y), _chatWidth - 10) + 5; gfx_set_dirty_blocks(x, y - stringHeight, x + _chatWidth, y + 20); if ((y - stringHeight) < 50) @@ -177,7 +177,7 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor) lineCh = lineBuffer; inputLineHeight = gfx_draw_string_left_wrapped( - dpi, (void*)&lineCh, x, y + 3, _chatWidth - 10, STR_STRING, TEXT_COLOUR_255); + dpi, static_cast(&lineCh), x, y + 3, _chatWidth - 10, STR_STRING, TEXT_COLOUR_255); gfx_set_dirty_blocks(x, y, x + _chatWidth, y + inputLineHeight + 15); // TODO: Show caret if the input text has multiple lines @@ -281,7 +281,7 @@ int32_t chat_history_draw_string(rct_drawpixelinfo* dpi, void* args, const Scree gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; - gfx_draw_string(dpi, (char*)"", TEXT_COLOUR_255, { dpi->x, dpi->y }); + gfx_draw_string(dpi, "", TEXT_COLOUR_255, { dpi->x, dpi->y }); char* buffer = gCommonStringFormatBuffer; format_string(buffer, 256, STR_STRING, args); diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 9acc3d9307..0de3373f0d 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -737,7 +737,7 @@ static int32_t cc_set(InteractiveConsole& console, const arguments_t& argv) if (argv[0] == "money" && invalidArguments(&invalidArgs, double_valid[0])) { - money32 money = MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100); + money32 money = MONEY(static_cast(double_val[0]), (static_cast(double_val[0] * 100)) % 100); if (gCash != money) { auto setCheatAction = SetCheatAction(CheatType::SetMoney, money); @@ -772,7 +772,8 @@ static int32_t cc_set(InteractiveConsole& console, const arguments_t& argv) else if (argv[0] == "guest_initial_cash" && invalidArguments(&invalidArgs, double_valid[0])) { gGuestInitialCash = std::clamp( - MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(0, 0), MONEY(1000, 0)); + MONEY(static_cast(double_val[0]), (static_cast(double_val[0] * 100)) % 100), MONEY(0, 0), + MONEY(1000, 0)); console.Execute("get guest_initial_cash"); } else if (argv[0] == "guest_initial_happiness" && invalidArguments(&invalidArgs, int_valid[0])) @@ -848,13 +849,15 @@ static int32_t cc_set(InteractiveConsole& console, const arguments_t& argv) else if (argv[0] == "land_rights_cost" && invalidArguments(&invalidArgs, double_valid[0])) { gLandPrice = std::clamp( - MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(0, 0), MONEY(200, 0)); + MONEY(static_cast(double_val[0]), (static_cast(double_val[0] * 100)) % 100), MONEY(0, 0), + MONEY(200, 0)); console.Execute("get land_rights_cost"); } else if (argv[0] == "construction_rights_cost" && invalidArguments(&invalidArgs, double_valid[0])) { gConstructionRightsPrice = std::clamp( - MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(0, 0), MONEY(200, 0)); + MONEY(static_cast(double_val[0]), (static_cast(double_val[0] * 100)) % 100), MONEY(0, 0), + MONEY(200, 0)); console.Execute("get construction_rights_cost"); } else if (argv[0] == "climate") diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 9147b6bd92..3841874ad1 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -828,11 +828,14 @@ static void record_session(const paint_session* session, std::vectorPaintStructs) { - ps.basic.next_quadrant_ps = (paint_struct*)(ps.basic.next_quadrant_ps ? int(ps.basic.next_quadrant_ps - &session->PaintStructs[0].basic) : std::size(session->PaintStructs)); + ps.basic.next_quadrant_ps = reinterpret_cast( + ps.basic.next_quadrant_ps ? int(ps.basic.next_quadrant_ps - &session->PaintStructs[0].basic) + : std::size(session->PaintStructs)); } for (auto& quad : session_copy->Quadrants) { - quad = (paint_struct*)(quad ? int(quad - &session->PaintStructs[0].basic) : std::size(session->Quadrants)); + quad = reinterpret_cast( + quad ? int(quad - &session->PaintStructs[0].basic) : std::size(session->Quadrants)); } } diff --git a/src/openrct2/localisation/ConversionTables.cpp b/src/openrct2/localisation/ConversionTables.cpp index 1667546744..5079c082c2 100644 --- a/src/openrct2/localisation/ConversionTables.cpp +++ b/src/openrct2/localisation/ConversionTables.cpp @@ -101,8 +101,8 @@ const encoding_convert_entry RCT2ToUnicodeTable[] = static int32_t encoding_search_compare(const void *pKey, const void *pEntry) { - uint16_t key = *((uint16_t*)pKey); - encoding_convert_entry *entry = (encoding_convert_entry*)pEntry; + const uint16_t key = *reinterpret_cast(pKey); + const encoding_convert_entry *entry = static_cast(pEntry); if (key < entry->code) return -1; if (key > entry->code) return 1; return 0; diff --git a/src/openrct2/localisation/Language.cpp b/src/openrct2/localisation/Language.cpp index b430b4deb3..850b4a1478 100644 --- a/src/openrct2/localisation/Language.cpp +++ b/src/openrct2/localisation/Language.cpp @@ -139,7 +139,7 @@ std::string language_convert_string_to_tokens(const std::string_view& s) auto readPtr = input.c_str(); while (true) { - char32_t code = utf8_get_next(readPtr, (const utf8**)&readPtr); + char32_t code = utf8_get_next(readPtr, const_cast(&readPtr)); if (code == 0) { break; diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index f9fea148ab..45206c7c0b 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -1088,7 +1088,7 @@ static void format_string_code(uint32_t format_code, char** dest, size_t* size, *args += sizeof(uintptr_t); if (value != 0) - format_append_string(dest, size, (char*)value); + format_append_string(dest, size, reinterpret_cast(value)); break; case FORMAT_MONTHYEAR: // Pop argument @@ -1318,7 +1318,7 @@ void format_string(utf8* dest, size_t size, rct_string_id format, const void* ar utf8* end = dest; size_t left = size; - format_string_part(&end, &left, format, (char**)&args); + format_string_part(&end, &left, format, reinterpret_cast(const_cast(&args))); if (left == 0) { // Replace last character with null terminator @@ -1353,7 +1353,7 @@ void format_string_raw(utf8* dest, size_t size, const utf8* src, const void* arg utf8* end = dest; size_t left = size; - format_string_part_from_raw(&end, &left, src, (char**)&args); + format_string_part_from_raw(&end, &left, src, reinterpret_cast(const_cast(&args))); if (left == 0) { // Replace last character with null terminator diff --git a/src/openrct2/localisation/UTF8.cpp b/src/openrct2/localisation/UTF8.cpp index 6251d313af..62cd3e278d 100644 --- a/src/openrct2/localisation/UTF8.cpp +++ b/src/openrct2/localisation/UTF8.cpp @@ -179,7 +179,7 @@ void utf8_remove_formatting(utf8* string, bool allowColours) while (true) { - char32_t code = utf8_get_next(readPtr, (const utf8**)&readPtr); + char32_t code = utf8_get_next(readPtr, const_cast(&readPtr)); if (code == 0) { diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 6c07be316e..25fda484c5 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -1442,7 +1442,7 @@ void Network::Client_Send_AUTH( packet->WriteString(name.c_str()); packet->WriteString(password.c_str()); packet->WriteString(pubkey.c_str()); - assert(signature.size() <= (size_t)UINT32_MAX); + assert(signature.size() <= static_cast(UINT32_MAX)); *packet << static_cast(signature.size()); packet->Write(signature.data(), signature.size()); _serverConnection->AuthStatus = NETWORK_AUTH_REQUESTED; @@ -2611,7 +2611,9 @@ void Network::Client_Handle_GAMESTATE(NetworkConnection& connection, NetworkPack const uint8_t* data = packet.Read(dataSize); _serverGameState.Write(data, dataSize); - log_verbose("Received Game State %.02f%%", ((float)_serverGameState.GetLength() / (float)totalSize) * 100.0f); + log_verbose( + "Received Game State %.02f%%", + (static_cast(_serverGameState.GetLength()) / static_cast(totalSize)) * 100.0f); if (_serverGameState.GetLength() == totalSize) { @@ -2850,7 +2852,7 @@ void Network::Client_Handle_MAP([[maybe_unused]] NetworkConnection& connection, intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void { gNetwork.Close(); }); context_open_intent(&intent); - std::memcpy(&chunk_buffer[offset], (void*)packet.Read(chunksize), chunksize); + std::memcpy(&chunk_buffer[offset], const_cast(static_cast(packet.Read(chunksize))), chunksize); if (offset + chunksize == size) { // Allow queue processing of game actions again. diff --git a/src/openrct2/network/NetworkPacket.h b/src/openrct2/network/NetworkPacket.h index bd05ea34fa..d2cc58cbfd 100644 --- a/src/openrct2/network/NetworkPacket.h +++ b/src/openrct2/network/NetworkPacket.h @@ -58,7 +58,7 @@ public: template NetworkPacket& operator<<(T value) { T swapped = ByteSwapBE(value); - uint8_t* bytes = (uint8_t*)&swapped; + uint8_t* bytes = reinterpret_cast(&swapped); Data->insert(Data->end(), bytes, bytes + sizeof(value)); return *this; } diff --git a/src/openrct2/network/Socket.cpp b/src/openrct2/network/Socket.cpp index 7c192084ef..430ad7afe9 100644 --- a/src/openrct2/network/Socket.cpp +++ b/src/openrct2/network/Socket.cpp @@ -109,11 +109,11 @@ public: { if (_address.sa_family == AF_INET) { - return ((sockaddr_in*)&_address)->sin_port; + return reinterpret_cast(&_address)->sin_port; } else { - return ((sockaddr_in6*)&_address)->sin6_port; + return reinterpret_cast(&_address)->sin6_port; } } diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index 9b2f1eb944..3c8a11608c 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -64,7 +64,7 @@ void ImageTable::Read(IReadObjectContext* context, IStream* stream) rct_g1_element g1Element; uintptr_t imageDataOffset = static_cast(stream->ReadValue()); - g1Element.offset = (uint8_t*)(imageDataBase + imageDataOffset); + g1Element.offset = reinterpret_cast(imageDataBase + imageDataOffset); g1Element.width = stream->ReadValue(); g1Element.height = stream->ReadValue(); diff --git a/src/openrct2/object/ObjectJsonHelpers.h b/src/openrct2/object/ObjectJsonHelpers.h index 6f97a4791b..506966fb02 100644 --- a/src/openrct2/object/ObjectJsonHelpers.h +++ b/src/openrct2/object/ObjectJsonHelpers.h @@ -44,7 +44,7 @@ namespace ObjectJsonHelpers { if (GetBoolean(obj, item.first)) { - flags = (T)(flags | item.second); + flags = static_cast(flags | item.second); } } return flags; diff --git a/src/openrct2/object/ObjectList.cpp b/src/openrct2/object/ObjectList.cpp index 6f723484fe..ed788bfc1f 100644 --- a/src/openrct2/object/ObjectList.cpp +++ b/src/openrct2/object/ObjectList.cpp @@ -59,8 +59,8 @@ int32_t object_entry_group_encoding[] = { bool object_entry_is_empty(const rct_object_entry* entry) { uint64_t a, b; - std::memcpy(&a, (uint8_t*)entry, 8); - std::memcpy(&b, (uint8_t*)entry + 8, 8); + std::memcpy(&a, reinterpret_cast(entry), 8); + std::memcpy(&b, reinterpret_cast(entry) + 8, 8); if (a == 0xFFFFFFFFFFFFFFFF && b == 0xFFFFFFFFFFFFFFFF) return true; diff --git a/src/openrct2/object/ObjectManager.cpp b/src/openrct2/object/ObjectManager.cpp index 0b7548258a..42a458fd9d 100644 --- a/src/openrct2/object/ObjectManager.cpp +++ b/src/openrct2/object/ObjectManager.cpp @@ -722,14 +722,14 @@ void* object_manager_get_loaded_object_by_index(size_t index) { auto& objectManager = OpenRCT2::GetContext()->GetObjectManager(); Object* loadedObject = objectManager.GetLoadedObject(index); - return (void*)loadedObject; + return static_cast(loadedObject); } void* object_manager_get_loaded_object(const rct_object_entry* entry) { auto& objectManager = OpenRCT2::GetContext()->GetObjectManager(); Object* loadedObject = objectManager.GetLoadedObject(entry); - return (void*)loadedObject; + return static_cast(loadedObject); } ObjectEntryIndex object_manager_get_loaded_object_entry_index(const void* loadedObject) @@ -744,7 +744,7 @@ void* object_manager_load_object(const rct_object_entry* entry) { auto& objectManager = OpenRCT2::GetContext()->GetObjectManager(); Object* loadedObject = objectManager.LoadObject(entry); - return (void*)loadedObject; + return static_cast(loadedObject); } void object_manager_unload_objects(const rct_object_entry* entries, size_t count) diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 9673f276a7..e7dd39e33d 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -523,7 +523,8 @@ private: chunkHeader.encoding = object_entry_group_encoding[objectType]; chunkHeader.length = static_cast(dataSize); uint8_t* encodedDataBuffer = Memory::Allocate(0x600000); - size_t encodedDataSize = sawyercoding_write_chunk_buffer(encodedDataBuffer, (uint8_t*)data, chunkHeader); + size_t encodedDataSize = sawyercoding_write_chunk_buffer( + encodedDataBuffer, reinterpret_cast(data), chunkHeader); // Save to file try @@ -691,7 +692,7 @@ void* object_repository_load_object(const rct_object_entry* objectEntry) object->Load(); } } - return (void*)object; + return static_cast(object); } void scenario_translate(scenario_index_entry* scenarioEntry) @@ -786,7 +787,7 @@ bool object_entry_compare(const rct_object_entry* a, const rct_object_entry* b) int32_t object_calculate_checksum(const rct_object_entry* entry, const void* data, size_t dataLength) { - const uint8_t* entryBytePtr = (uint8_t*)entry; + const uint8_t* entryBytePtr = reinterpret_cast(entry); uint32_t checksum = 0xF369A75B; checksum ^= entryBytePtr[0]; @@ -797,7 +798,7 @@ int32_t object_calculate_checksum(const rct_object_entry* entry, const void* dat checksum = rol32(checksum, 11); } - uint8_t* dataBytes = (uint8_t*)data; + const uint8_t* dataBytes = reinterpret_cast(data); const size_t dataLength32 = dataLength - (dataLength & 31); for (size_t i = 0; i < 32; i++) { diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 0a43281a34..aa01e05902 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -150,7 +150,7 @@ static paint_struct* sub_9819_c( ps->var_29 = 0; ps->map_x = session->MapPosition.x; ps->map_y = session->MapPosition.y; - ps->tileElement = (TileElement*)session->CurrentlyDrawnItem; + ps->tileElement = reinterpret_cast(const_cast(session->CurrentlyDrawnItem)); return ps; } @@ -817,7 +817,7 @@ paint_struct* sub_98196C( ps->var_29 = 0; ps->map_x = session->MapPosition.x; ps->map_y = session->MapPosition.y; - ps->tileElement = (TileElement*)session->CurrentlyDrawnItem; + ps->tileElement = reinterpret_cast(const_cast(session->CurrentlyDrawnItem)); session->LastRootPS = ps; diff --git a/src/openrct2/paint/sprite/Paint.Sprite.cpp b/src/openrct2/paint/sprite/Paint.Sprite.cpp index db532c200a..96bbb251f0 100644 --- a/src/openrct2/paint/sprite/Paint.Sprite.cpp +++ b/src/openrct2/paint/sprite/Paint.Sprite.cpp @@ -58,7 +58,7 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t { if (spr->generic.Is()) { - Peep* peep = (Peep*)spr; + const Peep* peep = reinterpret_cast(spr); if (!(peep->type == PEEP_TYPE_STAFF && peep->staff_type == STAFF_TYPE_HANDYMAN)) { continue; @@ -111,7 +111,7 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t switch (spr->generic.sprite_identifier) { case SPRITE_IDENTIFIER_VEHICLE: - vehicle_paint(session, (Vehicle*)spr, image_direction); + vehicle_paint(session, reinterpret_cast(spr), image_direction); #ifdef __ENABLE_LIGHTFX__ if (lightfx_for_vehicles_is_available()) { @@ -120,13 +120,13 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t #endif break; case SPRITE_IDENTIFIER_PEEP: - peep_paint(session, (Peep*)spr, image_direction); + peep_paint(session, reinterpret_cast(spr), image_direction); break; case SPRITE_IDENTIFIER_MISC: misc_paint(session, spr, image_direction); break; case SPRITE_IDENTIFIER_LITTER: - litter_paint(session, (Litter*)spr, image_direction); + litter_paint(session, reinterpret_cast(spr), image_direction); break; default: assert(false); diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 84fd4d45cd..3071607c4a 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -103,7 +103,7 @@ static void large_scenery_sign_fit_text(const utf8* str, rct_large_scenery_text* safe_strcpy(fitStr, str, bufLen); int32_t w = 0; uint32_t codepoint; - while (w <= text->max_width && (codepoint = utf8_get_next(fitStrEnd, (const utf8**)&fitStrEnd)) != 0) + while (w <= text->max_width && (codepoint = utf8_get_next(fitStrEnd, const_cast(&fitStrEnd))) != 0) { if (height) { @@ -356,7 +356,7 @@ void large_scenery_paint(paint_session* session, uint8_t direction, uint16_t hei utf8* spacesrc = nullptr; utf8* spacedst = nullptr; int32_t w = 0; - uint32_t codepoint = utf8_get_next(src, (const utf8**)&src); + uint32_t codepoint = utf8_get_next(src, const_cast(&src)); do { w += large_scenery_sign_get_glyph(text, codepoint)->width; @@ -367,7 +367,7 @@ void large_scenery_paint(paint_session* session, uint8_t direction, uint16_t hei } } while (w <= text->max_width && (dst = utf8_write_codepoint(dst, codepoint)) != nullptr && (srcold = src) != nullptr - && (codepoint = utf8_get_next(src, (const utf8**)&src)) != '\0'); + && (codepoint = utf8_get_next(src, const_cast(&src))) != '\0'); src = srcold; if (spacesrc && codepoint) { diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index 8f9a3717a2..0028a93bfe 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -280,8 +280,9 @@ struct RCT12TileElement : public RCT12TileElementBase uint8_t pad_04[4]; template TType* as() const { - // TODO: CAST-IMPROVEMENT-NEEDED - return static_cast(GetType()) == TClass ? (TType*)this : nullptr; + return static_cast(GetType()) == TClass + ? reinterpret_cast(const_cast(this)) + : nullptr; } RCT12SurfaceElement* AsSurface() const diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 5b9a96cff0..f6ec9d49d6 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -178,7 +178,7 @@ void S6Exporter::Export() const rct_object_entry* entry = get_loaded_object_entry(i); void* entryData = get_loaded_object_chunk(i); // RCT2 uses (void *)-1 to mark NULL. Make sure it's written in a vanilla-compatible way. - if (entryData == nullptr || entryData == (void*)-1) + if (entryData == nullptr || entryData == reinterpret_cast(-1)) { std::memset(&_s6.objects[i], 0xFF, sizeof(rct_object_entry)); } diff --git a/src/openrct2/scripting/ScObject.hpp b/src/openrct2/scripting/ScObject.hpp index 57570219f2..24bee9d53a 100644 --- a/src/openrct2/scripting/ScObject.hpp +++ b/src/openrct2/scripting/ScObject.hpp @@ -836,7 +836,7 @@ namespace OpenRCT2::Scripting { for (size_t i = 0; i < std::size(entry->vehicles); i++) { - result.push_back(std::make_shared((OBJECT_TYPE)_type, _index, i)); + result.push_back(std::make_shared(static_cast(_type), _index, i)); } } return result; diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 0971b73de8..875ff98136 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -1095,7 +1095,8 @@ void ScriptEngine::LoadSharedStorage() if (File::Exists(path)) { auto data = File::ReadAllBytes(path); - auto result = DuktapeTryParseJson(_context, std::string_view((const char*)data.data(), data.size())); + auto result = DuktapeTryParseJson( + _context, std::string_view(reinterpret_cast(data.data()), data.size())); if (result) { _sharedStorage = std::move(*result); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index f94cc4b86c..68b014db14 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -105,8 +105,8 @@ struct TileElement : public TileElementBase template TType* as() const { - // TODO: CAST-IMPROVEMENT-NEEDED - return static_cast(GetType()) == TClass ? (TType*)this : nullptr; + return static_cast(GetType()) == TClass ? reinterpret_cast(const_cast(this)) + : nullptr; } public: