From 2bb3a3427430f56c87b168c609bc385005db5378 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 28 Mar 2020 09:00:33 -0300 Subject: [PATCH 1/5] Convert C-style pointer casts to named casts --- src/openrct2-ui/audio/AudioMixer.cpp | 14 +++++++------- .../engines/HardwareDisplayDrawingEngine.cpp | 6 +++--- src/openrct2-ui/interface/Widget.cpp | 10 +++++----- src/openrct2-ui/windows/Changelog.cpp | 2 +- src/openrct2-ui/windows/EditorObjectSelection.cpp | 2 +- src/openrct2-ui/windows/EditorObjectiveOptions.cpp | 2 +- src/openrct2-ui/windows/Multiplayer.cpp | 2 +- src/openrct2-ui/windows/Themes.cpp | 3 ++- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index 3295cc7c50..23be6e9215 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -330,7 +330,7 @@ namespace OpenRCT2::Audio // Finally mix on to destination buffer size_t dstLength = std::min(length, bufferLen); - SDL_MixAudioFormat(data, (const uint8_t*)buffer, _format.format, (uint32_t)dstLength, mixVolume); + SDL_MixAudioFormat(data, static_cast(buffer), _format.format, (uint32_t)dstLength, mixVolume); channel->UpdateOldVolume(); } @@ -357,7 +357,7 @@ namespace OpenRCT2::Audio uint32_t inLen = srcSamples; uint32_t outLen = dstSamples; speex_resampler_process_interleaved_int( - resampler, (const spx_int16_t*)srcBuffer, &inLen, (spx_int16_t*)_effectBuffer.data(), &outLen); + resampler, static_cast(srcBuffer), &inLen, (spx_int16_t*)_effectBuffer.data(), &outLen); return outLen * byteRate; } @@ -369,10 +369,10 @@ namespace OpenRCT2::Audio switch (_format.format) { case AUDIO_S16SYS: - EffectPanS16(channel, (int16_t*)buffer, (int32_t)(len / sampleSize)); + EffectPanS16(channel, static_cast(buffer), (int32_t)(len / sampleSize)); break; case AUDIO_U8: - EffectPanU8(channel, (uint8_t*)buffer, (int32_t)(len / sampleSize)); + EffectPanU8(channel, static_cast(buffer), (int32_t)(len / sampleSize)); break; } } @@ -417,10 +417,10 @@ namespace OpenRCT2::Audio switch (_format.format) { case AUDIO_S16SYS: - EffectFadeS16((int16_t*)buffer, fadeLength, startVolume, endVolume); + EffectFadeS16(static_cast(buffer), fadeLength, startVolume, endVolume); break; case AUDIO_U8: - EffectFadeU8((uint8_t*)buffer, fadeLength, startVolume, endVolume); + EffectFadeU8(static_cast(buffer), fadeLength, startVolume, endVolume); break; } } @@ -494,7 +494,7 @@ namespace OpenRCT2::Audio { size_t reqConvertBufferCapacity = len * cvt->len_mult; _convertBuffer.resize(reqConvertBufferCapacity); - std::copy_n((const uint8_t*)src, len, _convertBuffer.data()); + std::copy_n(static_cast(src), len, _convertBuffer.data()); cvt->len = (int32_t)len; cvt->buf = (uint8_t*)_convertBuffer.data(); diff --git a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp index 8365a9f789..a474d9d124 100644 --- a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp @@ -264,7 +264,7 @@ private: int32_t padding = pitch - (width * 4); if (pitch == width * 4) { - uint32_t* dst = (uint32_t*)pixels; + uint32_t* dst = static_cast(pixels); for (int32_t i = width * height; i > 0; i--) { *dst++ = palette[*src++]; @@ -274,7 +274,7 @@ private: { if (pitch == (width * 2) + padding) { - uint16_t* dst = (uint16_t*)pixels; + uint16_t* dst = static_cast(pixels); for (int32_t y = height; y > 0; y--) { for (int32_t x = width; x > 0; x--) @@ -288,7 +288,7 @@ private: } else if (pitch == width + padding) { - uint8_t* dst = (uint8_t*)pixels; + uint8_t* dst = static_cast(pixels); for (int32_t y = height; y > 0; y--) { for (int32_t x = width; x > 0; x--) diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index 8f42b52c20..c8d640d7c1 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -603,7 +603,7 @@ static void widget_checkbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg if (widget_is_pressed(w, widgetIndex)) { gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; - gfx_draw_string(dpi, (char*)CheckBoxMarkString, NOT_TRANSLUCENT(colour), l, yMid - 5); + gfx_draw_string(dpi, static_cast(CheckBoxMarkString), NOT_TRANSLUCENT(colour), l, yMid - 5); } // draw the text @@ -701,7 +701,7 @@ static void widget_hscrollbar_draw( uint8_t flags = (scroll->flags & HSCROLLBAR_LEFT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0; gfx_fill_rect_inset(dpi, l, t, l + 9, b, colour, flags); - gfx_draw_string(dpi, (char*)BlackLeftArrowString, COLOUR_BLACK, l + 1, t); + gfx_draw_string(dpi, static_cast(BlackLeftArrowString), COLOUR_BLACK, l + 1, t); } // Thumb @@ -718,7 +718,7 @@ static void widget_hscrollbar_draw( uint8_t flags = (scroll->flags & HSCROLLBAR_RIGHT_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0; gfx_fill_rect_inset(dpi, r - 9, t, r, b, colour, flags); - gfx_draw_string(dpi, (char*)BlackRightArrowString, COLOUR_BLACK, r - 6, t); + gfx_draw_string(dpi, static_cast(BlackRightArrowString), COLOUR_BLACK, r - 6, t); } } @@ -737,7 +737,7 @@ static void widget_vscrollbar_draw( // Up button gfx_fill_rect_inset( dpi, l, t, r, t + 9, colour, ((scroll->flags & VSCROLLBAR_UP_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0)); - gfx_draw_string(dpi, (char*)BlackUpArrowString, COLOUR_BLACK, l + 1, t - 1); + gfx_draw_string(dpi, static_cast(BlackUpArrowString), COLOUR_BLACK, l + 1, t - 1); // Thumb gfx_fill_rect_inset( @@ -747,7 +747,7 @@ static void widget_vscrollbar_draw( // Down button gfx_fill_rect_inset( dpi, l, b - 9, r, b, colour, ((scroll->flags & VSCROLLBAR_DOWN_PRESSED) ? INSET_RECT_FLAG_BORDER_INSET : 0)); - gfx_draw_string(dpi, (char*)BlackDownArrowString, COLOUR_BLACK, l + 1, b - 9); + gfx_draw_string(dpi, static_cast(BlackDownArrowString), COLOUR_BLACK, l + 1, b - 9); } /** diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 31264ed571..329dd0b616 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -199,7 +199,7 @@ static void window_changelog_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, if (y + lineHeight < dpi->y || y >= dpi->y + dpi->height) continue; - gfx_draw_string(dpi, (char*)line, w->colours[0], x, y); + gfx_draw_string(dpi, static_cast(line), w->colours[0], x, y); } } diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 2c2fccc1c7..dd6218cc52 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -1147,7 +1147,7 @@ static void window_editor_object_selection_scrollpaint(rct_window* w, rct_drawpi if (*listItem.flags & (OBJECT_SELECTION_FLAG_IN_USE | OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED)) colour2 |= COLOUR_FLAG_INSET; - gfx_draw_string(dpi, (char*)CheckBoxMarkString, colour2, x, y); + gfx_draw_string(dpi, static_cast(CheckBoxMarkString), colour2, x, y); } x = gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER ? 0 : 15; diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index 636d7b7e0f..82562ab705 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -1175,7 +1175,7 @@ static void window_editor_objective_options_rides_scrollpaint(rct_window* w, rct { gCurrentFontSpriteBase = stringId == STR_WINDOW_COLOUR_2_STRINGID ? FONT_SPRITE_BASE_MEDIUM_EXTRA_DARK : FONT_SPRITE_BASE_MEDIUM_DARK; - gfx_draw_string(dpi, (char*)CheckBoxMarkString, w->colours[1] & 0x7F, 2, y); + gfx_draw_string(dpi, static_cast(CheckBoxMarkString), w->colours[1] & 0x7F, 2, y); } // Ride name diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index ce16d1a59f..22927b155c 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -756,7 +756,7 @@ static void window_multiplayer_groups_mouseup(rct_window* w, rct_widgetindex wid case WIDX_RENAME_GROUP:; int32_t groupIndex = network_get_group_index(_selectedGroup); const utf8* groupName = network_get_group_name(groupIndex); - window_text_input_raw_open(w, widgetIndex, STR_GROUP_NAME, STR_ENTER_NEW_NAME_FOR_THIS_GROUP, (utf8*)groupName, 32); + window_text_input_raw_open(w, widgetIndex, STR_GROUP_NAME, STR_ENTER_NEW_NAME_FOR_THIS_GROUP, groupName, 32); break; } } diff --git a/src/openrct2-ui/windows/Themes.cpp b/src/openrct2-ui/windows/Themes.cpp index 6483fadc5a..53d955b5ab 100644 --- a/src/openrct2-ui/windows/Themes.cpp +++ b/src/openrct2-ui/windows/Themes.cpp @@ -921,7 +921,8 @@ void window_themes_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t sc { gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_DARK; gfx_draw_string( - dpi, (char*)CheckBoxMarkString, w->colours[1] & 0x7F, _button_offset_x + 12 * j, y + _check_offset_y); + dpi, static_cast(CheckBoxMarkString), w->colours[1] & 0x7F, _button_offset_x + 12 * j, + y + _check_offset_y); } } } From bb052a784a57ec26d5033083fdf42f729c08a7cb Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 28 Mar 2020 15:09:18 -0300 Subject: [PATCH 2/5] Use named casts in openrct2-ui/audio/AudioMixer --- src/openrct2-ui/audio/AudioMixer.cpp | 63 +++++++++++++++------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index 23be6e9215..a3974a02e7 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -74,7 +74,7 @@ namespace OpenRCT2::Audio want.samples = 2048; want.callback = [](void* arg, uint8_t* dst, int32_t length) -> void { auto mixer = static_cast(arg); - mixer->GetNextAudioChunk(dst, (size_t)length); + mixer->GetNextAudioChunk(dst, static_cast(length)); }; want.userdata = this; @@ -167,7 +167,7 @@ namespace OpenRCT2::Audio IAudioSource* source = _musicSources[pathId]; if (source == nullptr) { - const utf8* path = context_get_path_legacy((int32_t)pathId); + const utf8* path = context_get_path_legacy(static_cast(pathId)); source = AudioSource::CreateMemoryFromWAV(path, &_format); if (source == nullptr) { @@ -258,7 +258,7 @@ namespace OpenRCT2::Audio void MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t length) { int32_t byteRate = _format.GetByteRate(); - int32_t numSamples = (int32_t)(length / byteRate); + int32_t numSamples = static_cast(length / byteRate); double rate = 1; if (_format.format == AUDIO_S16SYS) { @@ -283,8 +283,8 @@ namespace OpenRCT2::Audio } // Read raw PCM from channel - int32_t readSamples = (int32_t)(numSamples * rate); - size_t readLength = (size_t)(readSamples / cvt.len_ratio) * byteRate; + int32_t readSamples = static_cast(numSamples * rate); + size_t readLength = static_cast(readSamples / cvt.len_ratio) * byteRate; _channelBuffer.resize(readLength); size_t bytesRead = channel->Read(_channelBuffer.data(), readLength); @@ -312,7 +312,7 @@ namespace OpenRCT2::Audio // Apply effects if (rate != 1) { - int32_t inRate = (int32_t)(bufferLen / byteRate); + int32_t inRate = static_cast(bufferLen / byteRate); int32_t outRate = numSamples; if (bytesRead != readLength) { @@ -320,7 +320,8 @@ namespace OpenRCT2::Audio outRate = _format.freq * (1 / rate); } _effectBuffer.resize(length); - bufferLen = ApplyResample(channel, buffer, (int32_t)(bufferLen / byteRate), numSamples, inRate, outRate); + bufferLen = ApplyResample( + channel, buffer, static_cast(bufferLen / byteRate), numSamples, inRate, outRate); buffer = _effectBuffer.data(); } @@ -330,7 +331,8 @@ namespace OpenRCT2::Audio // Finally mix on to destination buffer size_t dstLength = std::min(length, bufferLen); - SDL_MixAudioFormat(data, static_cast(buffer), _format.format, (uint32_t)dstLength, mixVolume); + SDL_MixAudioFormat( + data, static_cast(buffer), _format.format, static_cast(dstLength), mixVolume); channel->UpdateOldVolume(); } @@ -357,7 +359,8 @@ namespace OpenRCT2::Audio uint32_t inLen = srcSamples; uint32_t outLen = dstSamples; speex_resampler_process_interleaved_int( - resampler, static_cast(srcBuffer), &inLen, (spx_int16_t*)_effectBuffer.data(), &outLen); + resampler, static_cast(srcBuffer), &inLen, + reinterpret_cast(_effectBuffer.data()), &outLen); return outLen * byteRate; } @@ -369,10 +372,10 @@ namespace OpenRCT2::Audio switch (_format.format) { case AUDIO_S16SYS: - EffectPanS16(channel, static_cast(buffer), (int32_t)(len / sampleSize)); + EffectPanS16(channel, static_cast(buffer), static_cast(len / sampleSize)); break; case AUDIO_U8: - EffectPanU8(channel, static_cast(buffer), (int32_t)(len / sampleSize)); + EffectPanU8(channel, static_cast(buffer), static_cast(len / sampleSize)); break; } } @@ -399,21 +402,21 @@ namespace OpenRCT2::Audio break; } - int32_t startVolume = (int32_t)(channel->GetOldVolume() * volumeAdjust); - int32_t endVolume = (int32_t)(channel->GetVolume() * volumeAdjust); + int32_t startVolume = static_cast(channel->GetOldVolume() * volumeAdjust); + int32_t endVolume = static_cast(channel->GetVolume() * volumeAdjust); if (channel->IsStopping()) { endVolume = 0; } - int32_t mixVolume = (int32_t)(channel->GetVolume() * volumeAdjust); + int32_t mixVolume = static_cast(channel->GetVolume() * volumeAdjust); if (startVolume != endVolume) { // Set to max since we are adjusting the volume ourselves mixVolume = MIXER_VOLUME_MAX; // Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes - int32_t fadeLength = (int32_t)len / _format.BytesPerSample(); + int32_t fadeLength = static_cast(len) / _format.BytesPerSample(); switch (_format.format) { case AUDIO_S16SYS: @@ -437,8 +440,8 @@ namespace OpenRCT2::Audio for (int32_t i = 0; i < length * 2; i += 2) { - data[i] = (int16_t)(data[i] * volumeL); - data[i + 1] = (int16_t)(data[i + 1] * volumeR); + data[i] = static_cast(data[i] * volumeL); + data[i + 1] = static_cast(data[i + 1] * volumeR); volumeL += d_left; volumeR += d_right; } @@ -453,9 +456,9 @@ namespace OpenRCT2::Audio for (int32_t i = 0; i < length * 2; i += 2) { - float t = (float)i / (length * 2); - data[i] = (uint8_t)(data[i] * ((1.0 - t) * oldVolumeL + t * volumeL)); - data[i + 1] = (uint8_t)(data[i + 1] * ((1.0 - t) * oldVolumeR + t * volumeR)); + float t = static_cast(i) / (length * 2); + data[i] = static_cast(data[i] * ((1.0 - t) * oldVolumeL + t * volumeL)); + data[i + 1] = static_cast(data[i + 1] * ((1.0 - t) * oldVolumeR + t * volumeR)); } } @@ -463,12 +466,12 @@ namespace OpenRCT2::Audio { static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2"); - float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME; - float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME; + float startvolume_f = static_cast(startvolume) / SDL_MIX_MAXVOLUME; + float endvolume_f = static_cast(endvolume) / SDL_MIX_MAXVOLUME; for (int32_t i = 0; i < length; i++) { - float t = (float)i / length; - data[i] = (int16_t)(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); + float t = static_cast(i) / length; + data[i] = static_cast(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); } } @@ -476,12 +479,12 @@ namespace OpenRCT2::Audio { static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2"); - float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME; - float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME; + float startvolume_f = static_cast(startvolume) / SDL_MIX_MAXVOLUME; + float endvolume_f = static_cast(endvolume) / SDL_MIX_MAXVOLUME; for (int32_t i = 0; i < length; i++) { - float t = (float)i / length; - data[i] = (uint8_t)(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); + float t = static_cast(i) / length; + data[i] = static_cast(data[i] * ((1 - t) * startvolume_f + t * endvolume_f)); } } @@ -496,8 +499,8 @@ namespace OpenRCT2::Audio _convertBuffer.resize(reqConvertBufferCapacity); std::copy_n(static_cast(src), len, _convertBuffer.data()); - cvt->len = (int32_t)len; - cvt->buf = (uint8_t*)_convertBuffer.data(); + cvt->len = static_cast(len); + cvt->buf = static_cast(_convertBuffer.data()); if (SDL_ConvertAudio(cvt) >= 0) { result = true; From fe6ff2ac94b8112215c1b647c132c51faad7e4c9 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 28 Mar 2020 15:16:02 -0300 Subject: [PATCH 3/5] Use named casts in openrct2-ui/audio/AudioChannel.cpp --- src/openrct2-ui/audio/AudioChannel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/audio/AudioChannel.cpp b/src/openrct2-ui/audio/AudioChannel.cpp index be7c09d1c4..c0675804fb 100644 --- a/src/openrct2-ui/audio/AudioChannel.cpp +++ b/src/openrct2-ui/audio/AudioChannel.cpp @@ -176,12 +176,12 @@ namespace OpenRCT2::Audio if (_pan <= 0.5) { _volume_l = 1.0; - _volume_r = (float)(1.0 / attenuation); + _volume_r = static_cast(1.0 / attenuation); } else { _volume_r = 1.0; - _volume_l = (float)(1.0 / attenuation); + _volume_l = static_cast(1.0 / attenuation); } } @@ -260,7 +260,7 @@ namespace OpenRCT2::Audio size_t readLen = _source->Read(dst, _offset, bytesToRead); if (readLen > 0) { - dst = (void*)((uintptr_t)dst + readLen); + dst = reinterpret_cast(reinterpret_cast(dst) + readLen); bytesToRead -= readLen; bytesRead += readLen; _offset += readLen; From 57886ad0c73e3d41f8878ab96d2808fd9839febb Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 28 Mar 2020 15:19:48 -0300 Subject: [PATCH 4/5] Use named casts in openrct2-ui/audio/ --- src/openrct2-ui/audio/FileAudioSource.cpp | 2 +- src/openrct2-ui/audio/MemoryAudioSource.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2-ui/audio/FileAudioSource.cpp b/src/openrct2-ui/audio/FileAudioSource.cpp index f623cfcb22..a4ad9952ed 100644 --- a/src/openrct2-ui/audio/FileAudioSource.cpp +++ b/src/openrct2-ui/audio/FileAudioSource.cpp @@ -51,7 +51,7 @@ namespace OpenRCT2::Audio int64_t currentPosition = SDL_RWtell(_rw); if (currentPosition != -1) { - size_t bytesToRead = (size_t)std::min(len, _dataLength - offset); + size_t bytesToRead = static_cast(std::min(len, _dataLength - offset)); int64_t dataOffset = _dataBegin + offset; if (currentPosition != dataOffset) { diff --git a/src/openrct2-ui/audio/MemoryAudioSource.cpp b/src/openrct2-ui/audio/MemoryAudioSource.cpp index 693f159275..8dec0bcc17 100644 --- a/src/openrct2-ui/audio/MemoryAudioSource.cpp +++ b/src/openrct2-ui/audio/MemoryAudioSource.cpp @@ -57,12 +57,12 @@ namespace OpenRCT2::Audio size_t bytesToRead = 0; if (offset < _length) { - bytesToRead = (size_t)std::min(len, _length - offset); + bytesToRead = static_cast(std::min(len, _length - offset)); auto src = GetData(); if (src != nullptr) { - std::copy_n(src + offset, bytesToRead, (uint8_t*)dst); + std::copy_n(src + offset, bytesToRead, reinterpret_cast(dst)); } } return bytesToRead; @@ -164,7 +164,7 @@ namespace OpenRCT2::Audio auto src = GetData(); auto cvtBuffer = std::vector(_length * cvt.len_mult); std::copy_n(src, _length, cvtBuffer.data()); - cvt.len = (int32_t)_length; + cvt.len = static_cast(_length); cvt.buf = cvtBuffer.data(); if (SDL_ConvertAudio(&cvt) >= 0) { From abfd41c35f9aca269fbb92adb5d95184e7172baa Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 28 Mar 2020 15:59:50 -0300 Subject: [PATCH 5/5] Use named casts in openrct2-ui/drawing --- src/openrct2-ui/drawing/BitmapReader.cpp | 6 +-- .../drawing/engines/DrawingEngineFactory.hpp | 2 +- .../engines/HardwareDisplayDrawingEngine.cpp | 25 ++++++----- .../drawing/engines/SoftwareDrawingEngine.cpp | 4 +- .../engines/opengl/ApplyPaletteShader.cpp | 8 ++-- .../opengl/ApplyTransparencyShader.cpp | 6 ++- .../drawing/engines/opengl/DrawLineShader.cpp | 25 +++++++---- .../drawing/engines/opengl/DrawRectShader.cpp | 45 ++++++++++++------- .../engines/opengl/OpenGLDrawingEngine.cpp | 20 ++++----- .../engines/opengl/OpenGLFramebuffer.cpp | 2 +- .../engines/opengl/OpenGLShaderProgram.cpp | 4 +- .../drawing/engines/opengl/TextureCache.cpp | 6 +-- .../drawing/engines/opengl/TextureCache.h | 14 +++--- 13 files changed, 96 insertions(+), 71 deletions(-) diff --git a/src/openrct2-ui/drawing/BitmapReader.cpp b/src/openrct2-ui/drawing/BitmapReader.cpp index 820e782ae4..712d2ad3d7 100644 --- a/src/openrct2-ui/drawing/BitmapReader.cpp +++ b/src/openrct2-ui/drawing/BitmapReader.cpp @@ -24,7 +24,7 @@ static std::vector ReadToVector(std::istream& stream) auto size = stream.tellg(); result.resize(size); stream.seekg(0, std::ios_base::beg); - stream.read((char*)result.data(), size); + stream.read(reinterpret_cast(result.data()), size); } return result; } @@ -34,7 +34,7 @@ static std::vector ReadToVector(std::istream& stream) static Image ReadBitmap(std::istream& istream, IMAGE_FORMAT format) { auto buffer = ReadToVector(istream); - auto sdlStream = SDL_RWFromConstMem(buffer.data(), (int)buffer.size()); + auto sdlStream = SDL_RWFromConstMem(buffer.data(), static_cast(buffer.size())); auto bitmap = SDL_LoadBMP_RW(sdlStream, 1); if (bitmap != nullptr) { @@ -59,7 +59,7 @@ static Image ReadBitmap(std::istream& istream, IMAGE_FORMAT format) std::fill(image.Pixels.begin(), image.Pixels.end(), 0xFF); // Copy pixels over - auto src = (const uint8_t*)bitmap->pixels; + auto src = static_cast(bitmap->pixels); auto dst = image.Pixels.data(); if (numChannels == 4) { diff --git a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp index f78083a076..22fbdbba07 100644 --- a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp +++ b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp @@ -33,7 +33,7 @@ namespace OpenRCT2 std::unique_ptr Create( DRAWING_ENGINE_TYPE type, const std::shared_ptr& uiContext) override { - switch ((int32_t)type) + switch (static_cast(type)) { case DRAWING_ENGINE_SOFTWARE: return CreateSoftwareDrawingEngine(uiContext); diff --git a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp index a474d9d124..c3fe0a2b5b 100644 --- a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp @@ -57,7 +57,7 @@ public: : X8DrawingEngine(uiContext) , _uiContext(uiContext) { - _window = (SDL_Window*)_uiContext->GetWindow(); + _window = static_cast(_uiContext->GetWindow()); } ~HardwareDisplayDrawingEngine() override @@ -221,7 +221,8 @@ private: else #endif { - CopyBitsToTexture(_screenTexture, _bits, (int32_t)_width, (int32_t)_height, _paletteHWMapped); + CopyBitsToTexture( + _screenTexture, _bits, static_cast(_width), static_cast(_height), _paletteHWMapped); } if (smoothNN) { @@ -279,11 +280,11 @@ private: { for (int32_t x = width; x > 0; x--) { - const uint8_t lower = *(uint8_t*)(&palette[*src++]); - const uint8_t upper = *(uint8_t*)(&palette[*src++]); + const uint8_t lower = *reinterpret_cast(&palette[*src++]); + const uint8_t upper = *reinterpret_cast(&palette[*src++]); *dst++ = (lower << 8) | upper; } - dst = (uint16_t*)(((uint8_t*)dst) + padding); + dst = reinterpret_cast(reinterpret_cast(dst) + padding); } } else if (pitch == width + padding) @@ -293,7 +294,7 @@ private: { for (int32_t x = width; x > 0; x--) { - *dst++ = *(uint8_t*)(&palette[*src++]); + *dst++ = *reinterpret_cast(&palette[*src++]); } dst += padding; } @@ -352,13 +353,13 @@ private: auto timeLeft = GetDirtyVisualTime(x, y); if (timeLeft > 0) { - uint8_t alpha = (uint8_t)(timeLeft * 5 / 2); + uint8_t alpha = static_cast(timeLeft * 5 / 2); SDL_Rect ddRect; - ddRect.x = (int32_t)(x * _dirtyGrid.BlockWidth * scaleX); - ddRect.y = (int32_t)(y * _dirtyGrid.BlockHeight * scaleY); - ddRect.w = (int32_t)(_dirtyGrid.BlockWidth * scaleX); - ddRect.h = (int32_t)(_dirtyGrid.BlockHeight * scaleY); + ddRect.x = static_cast(x * _dirtyGrid.BlockWidth * scaleX); + ddRect.y = static_cast(y * _dirtyGrid.BlockHeight * scaleY); + ddRect.w = static_cast(_dirtyGrid.BlockWidth * scaleX); + ddRect.h = static_cast(_dirtyGrid.BlockHeight * scaleY); SDL_SetRenderDrawColor(_sdlRenderer, 255, 255, 255, alpha); SDL_RenderFillRect(_sdlRenderer, &ddRect); @@ -369,7 +370,7 @@ private: void ReadCentrePixel(uint32_t* pixel) { - SDL_Rect centrePixelRegion = { (int32_t)(_width / 2), (int32_t)(_height / 2), 1, 1 }; + SDL_Rect centrePixelRegion = { static_cast(_width / 2), static_cast(_height / 2), 1, 1 }; SDL_RenderReadPixels(_sdlRenderer, ¢rePixelRegion, SDL_PIXELFORMAT_RGBA8888, pixel, sizeof(uint32_t)); } diff --git a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp index 4ef671c301..f7fe303956 100644 --- a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp @@ -37,7 +37,7 @@ public: : X8DrawingEngine(uiContext) , _uiContext(uiContext) { - _window = (SDL_Window*)_uiContext->GetWindow(); + _window = static_cast(_uiContext->GetWindow()); } ~SoftwareDrawingEngine() override @@ -113,7 +113,7 @@ private: } // Copy pixels from the virtual screen buffer to the surface - std::copy_n(_bits, _surface->pitch * _surface->h, (uint8_t*)_surface->pixels); + std::copy_n(_bits, _surface->pitch * _surface->h, static_cast(_surface->pixels)); // Unlock the surface if (SDL_MUSTLOCK(_surface)) diff --git a/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp b/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp index 6ee690e44a..572f55ba4d 100644 --- a/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp @@ -39,9 +39,11 @@ ApplyPaletteShader::ApplyPaletteShader() glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW); glBindVertexArray(_vao); - glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position)); glVertexAttribPointer( - vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate)); + vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, position))); + glVertexAttribPointer( + vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), + reinterpret_cast(offsetof(VDStruct, texturecoordinate))); glEnableVertexAttribArray(vPosition); glEnableVertexAttribArray(vTextureCoordinate); @@ -72,7 +74,7 @@ void ApplyPaletteShader::SetTexture(GLuint texture) void ApplyPaletteShader::SetPalette(const vec4* glPalette) { - glUniform4fv(uPalette, 256, (const GLfloat*)glPalette); + glUniform4fv(uPalette, 256, reinterpret_cast(glPalette)); } void ApplyPaletteShader::Draw() diff --git a/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp b/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp index 5eb10a33bd..ea9d4600cd 100644 --- a/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp @@ -39,9 +39,11 @@ ApplyTransparencyShader::ApplyTransparencyShader() glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW); glBindVertexArray(_vao); - glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position)); glVertexAttribPointer( - vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate)); + vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, position))); + glVertexAttribPointer( + vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), + reinterpret_cast(offsetof(VDStruct, texturecoordinate))); glEnableVertexAttribArray(vPosition); glEnableVertexAttribArray(vTextureCoordinate); diff --git a/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp b/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp index 19cba2d1e2..cb0e953dd4 100644 --- a/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp @@ -39,16 +39,23 @@ DrawLineShader::DrawLineShader() glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW); glBindVertexArray(_vao); - glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0])); - glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1])); - glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2])); - glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3])); + glVertexAttribPointer( + vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[0]))); + glVertexAttribPointer( + vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[1]))); + glVertexAttribPointer( + vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[2]))); + glVertexAttribPointer( + vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[3]))); glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); - glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, clip)); - glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, bounds)); - glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, colour)); - glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, depth)); + glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, clip))); + glVertexAttribIPointer( + vBounds, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, bounds))); + glVertexAttribIPointer( + vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, colour))); + glVertexAttribIPointer( + vDepth, 1, GL_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, depth))); glEnableVertexAttribArray(vVertMat + 0); glEnableVertexAttribArray(vVertMat + 1); @@ -98,7 +105,7 @@ void DrawLineShader::DrawInstances(const LineCommandBatch& instances) glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); glBufferData(GL_ARRAY_BUFFER, sizeof(DrawLineCommand) * instances.size(), instances.data(), GL_STREAM_DRAW); - glDrawArraysInstanced(GL_LINES, 0, 2, (GLsizei)instances.size()); + glDrawArraysInstanced(GL_LINES, 0, 2, static_cast(instances.size())); } #endif /* DISABLE_OPENGL */ diff --git a/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp b/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp index c2bf52ec31..2ba7f5a1be 100644 --- a/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp @@ -41,26 +41,39 @@ DrawRectShader::DrawRectShader() glBindVertexArray(_vao); - glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0])); - glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1])); - glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2])); - glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3])); - glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, vec)); + glVertexAttribPointer( + vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[0]))); + glVertexAttribPointer( + vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[1]))); + glVertexAttribPointer( + vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[2]))); + glVertexAttribPointer( + vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[3]))); + glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, vec))); glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); - glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, clip)); + glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, clip))); glVertexAttribIPointer( - vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourAtlas)); + vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand), + reinterpret_cast(offsetof(DrawRectCommand, texColourAtlas))); glVertexAttribPointer( - vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourBounds)); - glVertexAttribIPointer(vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskAtlas)); + vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), + reinterpret_cast(offsetof(DrawRectCommand, texColourBounds))); + glVertexAttribIPointer( + vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, texMaskAtlas))); glVertexAttribPointer( - vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskBounds)); - glVertexAttribIPointer(vPalettes, 3, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, palettes)); - glVertexAttribIPointer(vFlags, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, flags)); - glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, colour)); - glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, bounds)); - glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, depth)); + vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), + reinterpret_cast(offsetof(DrawRectCommand, texMaskBounds))); + glVertexAttribIPointer( + vPalettes, 3, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, palettes))); + glVertexAttribIPointer( + vFlags, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, flags))); + glVertexAttribIPointer( + vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, colour))); + glVertexAttribIPointer( + vBounds, 4, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, bounds))); + glVertexAttribIPointer( + vDepth, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, depth))); glEnableVertexAttribArray(vVertMat + 0); glEnableVertexAttribArray(vVertMat + 1); @@ -152,7 +165,7 @@ void DrawRectShader::SetInstances(const RectCommandBatch& instances) glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); glBufferData(GL_ARRAY_BUFFER, sizeof(DrawRectCommand) * instances.size(), instances.data(), GL_STREAM_DRAW); - _instanceCount = (GLsizei)instances.size(); + _instanceCount = static_cast(instances.size()); } void DrawRectShader::DrawInstances() diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index 8c0f86b620..e434555d71 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -153,7 +153,7 @@ public: uint32_t finalPixelOffset = width + pixelOffset; uint32_t xPixelOffset = pixelOffset; - xPixelOffset += ((uint8_t)(patternX - patternStartXOffset)) % patternXSpace; + xPixelOffset += (static_cast(patternX - patternStartXOffset)) % patternXSpace; uint8_t patternPixel = pattern[patternYPos * 2 + 1]; for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace) @@ -204,7 +204,7 @@ public: , _drawingContext(new OpenGLDrawingContext(this)) , _rainDrawer(_drawingContext) { - _window = (SDL_Window*)_uiContext->GetWindow(); + _window = static_cast(_uiContext->GetWindow()); _bitsDPI.DrawingEngine = this; # ifdef __ENABLE_LIGHTFX__ lightfx_set_available(false); @@ -839,8 +839,8 @@ void OpenGLDrawingContext::DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, int32_t drawOffsetX = g1Element->x_offset; int32_t drawOffsetY = g1Element->y_offset; - int32_t drawWidth = (uint16_t)g1Element->width; - int32_t drawHeight = (uint16_t)g1Element->height; + int32_t drawWidth = static_cast(g1Element->width); + int32_t drawHeight = static_cast(g1Element->height); int32_t left = x + drawOffsetX; int32_t top = y + drawOffsetY; @@ -887,8 +887,8 @@ void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8 int32_t drawOffsetX = g1Element->x_offset; int32_t drawOffsetY = g1Element->y_offset; - int32_t drawWidth = (uint16_t)g1Element->width; - int32_t drawHeight = (uint16_t)g1Element->height; + int32_t drawWidth = static_cast(g1Element->width); + int32_t drawHeight = static_cast(g1Element->height); int32_t left = x + drawOffsetX; int32_t top = y + drawOffsetY; @@ -1003,14 +1003,14 @@ void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo* dpi) { rct_drawpixelinfo* screenDPI = _engine->GetDPI(); # ifndef NDEBUG - size_t bitsSize = (size_t)screenDPI->height * (size_t)(screenDPI->width + screenDPI->pitch); + size_t bitsSize = static_cast(screenDPI->height) * static_cast(screenDPI->width + screenDPI->pitch); # endif - size_t bitsOffset = (size_t)(dpi->bits - screenDPI->bits); + size_t bitsOffset = static_cast(dpi->bits - screenDPI->bits); assert(bitsOffset < bitsSize); - _clipLeft = (int32_t)(bitsOffset % (screenDPI->width + screenDPI->pitch)); - _clipTop = (int32_t)(bitsOffset / (screenDPI->width + screenDPI->pitch)); + _clipLeft = static_cast(bitsOffset % (screenDPI->width + screenDPI->pitch)); + _clipTop = static_cast(bitsOffset / (screenDPI->width + screenDPI->pitch)); _clipRight = _clipLeft + (dpi->width / dpi->zoom_level); _clipBottom = _clipTop + (dpi->height / dpi->zoom_level); _offsetX = _clipLeft - dpi->x; diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp index e8951c9404..cf19540416 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp @@ -72,7 +72,7 @@ OpenGLFramebuffer::~OpenGLFramebuffer() void OpenGLFramebuffer::Bind() const { glBindFramebuffer(GL_FRAMEBUFFER, _id); - glViewport(0, 0, (GLsizei)_width, (GLsizei)_height); + glViewport(0, 0, static_cast(_width), static_cast(_height)); } void OpenGLFramebuffer::BindDraw() const diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp index 44f4e92f18..67e8689391 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp @@ -29,7 +29,7 @@ OpenGLShader::OpenGLShader(const char* name, GLenum type) auto sourceCodeStr = sourceCode.c_str(); _id = glCreateShader(type); - glShaderSource(_id, 1, (const GLchar**)&sourceCodeStr, nullptr); + glShaderSource(_id, 1, static_cast(&sourceCodeStr), nullptr); glCompileShader(_id); GLint status; @@ -84,7 +84,7 @@ std::string OpenGLShader::ReadSourceCode(const std::string& path) } auto fileData = std::string((size_t)fileLength + 1, '\0'); - fs.Read((void*)fileData.data(), fileLength); + fs.Read(static_cast(fileData.data()), fileLength); return fileData; } diff --git a/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp b/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp index c353b6f0a3..88ca07becb 100644 --- a/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp @@ -86,7 +86,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image) // Load new texture. unique_lock lock(_mutex); - index = (uint32_t)_textureCache.size(); + index = static_cast(_textureCache.size()); AtlasTextureInfo info = LoadImageTexture(image); @@ -105,7 +105,7 @@ BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* pa { shared_lock lock(_mutex); - std::copy_n(palette, sizeof(glyphId.Palette), (uint8_t*)&glyphId.Palette); + std::copy_n(palette, sizeof(glyphId.Palette), reinterpret_cast(&glyphId.Palette)); auto kvp = _glyphTextureMap.find(glyphId); if (kvp != _glyphTextureMap.end()) @@ -271,7 +271,7 @@ AtlasTextureInfo TextureCache::AllocateImage(int32_t imageWidth, int32_t imageHe } // If there is no such atlas, then create a new one - if ((int32_t)_atlases.size() >= _atlasesTextureIndicesLimit) + if (static_cast(_atlases.size()) >= _atlasesTextureIndicesLimit) { throw std::runtime_error("more texture atlases required, but device limit reached!"); } diff --git a/src/openrct2-ui/drawing/engines/opengl/TextureCache.h b/src/openrct2-ui/drawing/engines/opengl/TextureCache.h index 5ee5a7417c..a7065ee75e 100644 --- a/src/openrct2-ui/drawing/engines/opengl/TextureCache.h +++ b/src/openrct2-ui/drawing/engines/opengl/TextureCache.h @@ -105,7 +105,7 @@ public: _freeSlots.resize(_cols * _rows); for (size_t i = 0; i < _freeSlots.size(); i++) { - _freeSlots[i] = (GLuint)i; + _freeSlots[i] = static_cast(i); } } @@ -146,7 +146,7 @@ public: [[nodiscard]] int32_t GetFreeSlots() const { - return (int32_t)_freeSlots.size(); + return static_cast(_freeSlots.size()); } static int32_t CalculateImageSizeOrder(int32_t actualWidth, int32_t actualHeight) @@ -158,7 +158,7 @@ public: actualSize = TEXTURE_CACHE_SMALLEST_SLOT; } - return (int32_t)ceil(log2f((float)actualSize)); + return static_cast(ceil(log2f(static_cast(actualSize)))); } private: @@ -178,10 +178,10 @@ private: [[nodiscard]] vec4 NormalizeCoordinates(const ivec4& coords) const { return vec4{ - coords.x / (float)_atlasWidth, - coords.y / (float)_atlasHeight, - coords.z / (float)_atlasWidth, - coords.w / (float)_atlasHeight, + coords.x / static_cast(_atlasWidth), + coords.y / static_cast(_atlasHeight), + coords.z / static_cast(_atlasWidth), + coords.w / static_cast(_atlasHeight), }; } };