From 36a4bc22c19bf50348ace534da1852137f132d65 Mon Sep 17 00:00:00 2001 From: lag <115616336+lag@users.noreply.github.com> Date: Fri, 6 Mar 2026 07:58:40 -0600 Subject: [PATCH] static_cast refactor --- Minecraft.Client/ChatScreen.cpp | 18 +++++----- Minecraft.Client/Font.cpp | 32 ++++++++--------- Minecraft.Client/Gui.cpp | 6 ++-- Minecraft.Client/GuiComponent.cpp | 34 +++++++++---------- Minecraft.Client/Screen.cpp | 16 ++++----- .../Windows64/KeyboardMouseInput.cpp | 8 ++--- .../Windows64/Windows64_Minecraft.cpp | 6 ++-- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/Minecraft.Client/ChatScreen.cpp b/Minecraft.Client/ChatScreen.cpp index 4c405e3c7..543cab76c 100644 --- a/Minecraft.Client/ChatScreen.cpp +++ b/Minecraft.Client/ChatScreen.cpp @@ -37,14 +37,14 @@ void ChatScreen::removed() void ChatScreen::tick() { frame++; - if (cursorIndex > (int)message.length()) - cursorIndex = (int)message.length(); + if (cursorIndex > static_cast(message.length())) + cursorIndex = static_cast(message.length()); } void ChatScreen::handlePasteRequest() { wstring pasted = Screen::getClipboard(); - for (size_t i = 0; i < pasted.length() && (int)message.length() < SharedConstants::maxChatLength; i++) + for (size_t i = 0; i < pasted.length() && static_cast(message.length()) < SharedConstants::maxChatLength; i++) { if (isAllowedChatChar(pasted[i])) { @@ -57,7 +57,7 @@ void ChatScreen::handlePasteRequest() void ChatScreen::applyHistoryMessage() { message = s_historyIndex >= 0 ? s_chatHistory[s_historyIndex] : s_historyDraft; - cursorIndex = (int)message.length(); + cursorIndex = static_cast(message.length()); } void ChatScreen::handleHistoryUp() @@ -66,7 +66,7 @@ void ChatScreen::handleHistoryUp() if (s_historyIndex == -1) { s_historyDraft = message; - s_historyIndex = (int)s_chatHistory.size() - 1; + s_historyIndex = static_cast(s_chatHistory.size()) - 1; } else if (s_historyIndex > 0) s_historyIndex--; @@ -76,7 +76,7 @@ void ChatScreen::handleHistoryUp() void ChatScreen::handleHistoryDown() { if (s_chatHistory.empty()) return; - if (s_historyIndex < (int)s_chatHistory.size() - 1) + if (s_historyIndex < static_cast(s_chatHistory.size()) - 1) s_historyIndex++; else s_historyIndex = -1; @@ -121,7 +121,7 @@ void ChatScreen::keyPressed(wchar_t ch, int eventKey) } if (eventKey == Keyboard::KEY_RIGHT) { - if (cursorIndex < (int)message.length()) + if (cursorIndex < static_cast(message.length())) cursorIndex++; return; } @@ -131,7 +131,7 @@ void ChatScreen::keyPressed(wchar_t ch, int eventKey) cursorIndex--; return; } - if (isAllowedChatChar(ch) && (int)message.length() < SharedConstants::maxChatLength) + if (isAllowedChatChar(ch) && static_cast(message.length()) < SharedConstants::maxChatLength) { message.insert(cursorIndex, 1, ch); cursorIndex++; @@ -172,7 +172,7 @@ void ChatScreen::mouseClicked(int x, int y, int buttonNum) if (insertLen > 0) { message = message.substr(0, cursorIndex) + minecraft->gui->selectedName.substr(0, insertLen) + message.substr(cursorIndex); - cursorIndex += (int)insertLen; + cursorIndex += static_cast(insertLen); } } else diff --git a/Minecraft.Client/Font.cpp b/Minecraft.Client/Font.cpp index 0f321f9fd..51b50ca19 100644 --- a/Minecraft.Client/Font.cpp +++ b/Minecraft.Client/Font.cpp @@ -189,15 +189,15 @@ void Font::renderCharacter(wchar_t c) } if (m_underline) - renderStyleLine(x0, y1 - 1.0f, xPos + (float)charWidths[c], y1); + renderStyleLine(x0, y1 - 1.0f, xPos + static_cast(charWidths[c]), y1); if (m_strikethrough) { float mid = y0 + height * 0.5f; - renderStyleLine(x0, mid - 0.5f, xPos + (float)charWidths[c], mid + 0.5f); + renderStyleLine(x0, mid - 0.5f, xPos + static_cast(charWidths[c]), mid + 0.5f); } - xPos += (float) charWidths[c]; + xPos += static_cast(charWidths[c]); } void Font::drawShadow(const wstring& str, int x, int y, int color) @@ -219,8 +219,8 @@ void Font::drawLiteral(const wstring& str, int x, int y, int color) if ((color & 0xFC000000) == 0) color |= 0xFF000000; textures->bindTexture(m_textureLocation); glColor4f((color >> 16 & 255) / 255.0F, (color >> 8 & 255) / 255.0F, (color & 255) / 255.0F, (color >> 24 & 255) / 255.0F); - xPos = (float)x; - yPos = (float)y; + xPos = static_cast(x); + yPos = static_cast(y); wstring cleanStr = sanitize(str); for (size_t i = 0; i < cleanStr.length(); ++i) renderCharacter(cleanStr.at(i)); @@ -247,7 +247,7 @@ static bool isSectionFormatCode(wchar_t ca) { if ((ca >= L'0' && ca <= L'9') || (ca >= L'a' && ca <= L'f') || (ca >= L'A' && ca <= L'F')) return true; - wchar_t l = (wchar_t)(ca | 32); + wchar_t l = static_cast(ca | 32); return l == L'l' || l == L'o' || l == L'n' || l == L'm' || l == L'r' || l == L'k'; } @@ -260,7 +260,7 @@ void Font::draw(const wstring &str, bool dropShadow) m_bold = m_italic = m_underline = m_strikethrough = false; wstring cleanStr = sanitize(str); - for (int i = 0; i < (int)cleanStr.length(); ++i) + for (int i = 0; i < static_cast(cleanStr.length()); ++i) { // Map character wchar_t c = cleanStr.at(i); @@ -282,7 +282,7 @@ void Font::draw(const wstring &str, bool dropShadow) if (colorN == 16) { - wchar_t l = (wchar_t)(ca | 32); + wchar_t l = static_cast(ca | 32); if (l == L'l') m_bold = true; else if (l == L'o') m_italic = true; else if (l == L'n') m_underline = true; @@ -358,7 +358,7 @@ int Font::width(const wstring& str) { len += charWidths[167]; if (i + 1 < cleanStr.length()) - len += charWidths[(unsigned)cleanStr[++i]]; + len += charWidths[static_cast(cleanStr[++i])]; } } else @@ -374,7 +374,7 @@ int Font::widthLiteral(const wstring& str) if (cleanStr == L"") return 0; int len = 0; for (size_t i = 0; i < cleanStr.length(); ++i) - len += charWidths[(unsigned)cleanStr.at(i)]; + len += charWidths[static_cast(cleanStr.at(i))]; return len; } @@ -551,7 +551,7 @@ void Font::setBidirectional(bool bidirectional) bool Font::AllCharactersValid(const wstring &str) { - for (int i = 0; i < (int)str.length(); ++i) + for (int i = 0; i < static_cast(str.length()); ++i) { wchar_t c = str.at(i); @@ -596,15 +596,15 @@ void Font::renderFakeCB(IntBuffer *ib) float uo = (0.0f) / 128.0f; float vo = (0.0f) / 128.0f; - t->vertexUV((float)(0), (float)( 0 + s), (float)( 0), (float)( ix / 128.0f + uo), (float)( (iy + s) / 128.0f + vo)); - t->vertexUV((float)(0 + s), (float)( 0 + s), (float)( 0), (float)( (ix + s) / 128.0f + uo), (float)( (iy + s) / 128.0f + vo)); - t->vertexUV((float)(0 + s), (float)( 0), (float)( 0), (float)( (ix + s) / 128.0f + uo), (float)( iy / 128.0f + vo)); - t->vertexUV((float)(0), (float)( 0), (float)( 0), (float)( ix / 128.0f + uo), (float)( iy / 128.0f + vo)); + t->vertexUV(static_cast(0), static_cast(0 + s), static_cast(0), static_cast(ix / 128.0f + uo), static_cast((iy + s) / 128.0f + vo)); + t->vertexUV(static_cast(0 + s), static_cast(0 + s), static_cast(0), static_cast((ix + s) / 128.0f + uo), static_cast((iy + s) / 128.0f + vo)); + t->vertexUV(static_cast(0 + s), static_cast(0), static_cast(0), static_cast((ix + s) / 128.0f + uo), static_cast(iy / 128.0f + vo)); + t->vertexUV(static_cast(0), static_cast(0), static_cast(0), static_cast(ix / 128.0f + uo), static_cast(iy / 128.0f + vo)); // target.colorBlit(texture, x + xo, y, color, ix, iy, // charWidths[chars[i]], 8); t->end(); - glTranslatef((float)charWidths[i], 0, 0); + glTranslatef(static_cast(charWidths[i]), 0, 0); } else { diff --git a/Minecraft.Client/Gui.cpp b/Minecraft.Client/Gui.cpp index 1ea8d433b..365ddeac7 100644 --- a/Minecraft.Client/Gui.cpp +++ b/Minecraft.Client/Gui.cpp @@ -973,7 +973,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) #if defined(_WINDOWS64) glPushMatrix(); - glTranslatef(0.0f, (float)(screenHeight - iSafezoneYHalf - iTooltipsYOffset - 16 - 3 + 22) - 24.0f, 0.0f); + glTranslatef(0.0f, static_cast(screenHeight - iSafezoneYHalf - iTooltipsYOffset - 16 - 3 + 22) - 24.0f, 0.0f); if(bDisplayGui) { @@ -988,13 +988,13 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) if (t < 0) t = 0; if (t > 1) t = 1; t = t * t; - int alpha = (int) (255 * t); + int alpha = static_cast(255 * t); if (isChatting) alpha = 255; if (alpha > 0) { int x = iSafezoneXHalf+2; - int y = -((int)i) * 9; + int y = -(static_cast(i)) * 9; if(bTwoPlayerSplitscreen) { y+= iHeightOffset; diff --git a/Minecraft.Client/GuiComponent.cpp b/Minecraft.Client/GuiComponent.cpp index 470928900..c6b5f518b 100644 --- a/Minecraft.Client/GuiComponent.cpp +++ b/Minecraft.Client/GuiComponent.cpp @@ -48,10 +48,10 @@ void GuiComponent::fill(int x0, int y0, int x1, int y1, int col) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(r, g, b, a); t->begin(); - t->vertex((float)(x0), (float)( y1), (float)( 0)); - t->vertex((float)(x1), (float)( y1), (float)( 0)); - t->vertex((float)(x1), (float)( y0), (float)( 0)); - t->vertex((float)(x0), (float)( y0), (float)( 0)); + t->vertex(static_cast(x0), static_cast(y1), static_cast(0)); + t->vertex(static_cast(x1), static_cast(y1), static_cast(0)); + t->vertex(static_cast(x1), static_cast(y0), static_cast(0)); + t->vertex(static_cast(x0), static_cast(y0), static_cast(0)); t->end(); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); @@ -77,11 +77,11 @@ void GuiComponent::fillGradient(int x0, int y0, int x1, int y1, int col1, int co Tesselator *t = Tesselator::getInstance(); t->begin(); t->color(r1, g1, b1, a1); - t->vertex((float)(x1), (float)( y0), blitOffset); - t->vertex((float)(x0), (float)( y0), blitOffset); + t->vertex(static_cast(x1), static_cast(y0), blitOffset); + t->vertex(static_cast(x0), static_cast(y0), blitOffset); t->color(r2, g2, b2, a2); - t->vertex((float)(x0), (float)( y1), blitOffset); - t->vertex((float)(x1), (float)( y1), blitOffset); + t->vertex(static_cast(x0), static_cast(y1), blitOffset); + t->vertex(static_cast(x1), static_cast(y1), blitOffset); t->end(); glShadeModel(GL_FLAT); @@ -122,20 +122,20 @@ void GuiComponent::blit(int x, int y, int sx, int sy, int w, int h) const float extraShift = 0.75f; // 4J - subtracting extraShift (actual screen pixels, so need to compensate for physical & game width) from each x & y coordinate to compensate for centre of pixels in directx vs openGL - float dx = ( extraShift * (float)Minecraft::GetInstance()->width ) / (float)Minecraft::GetInstance()->width_phys; + float dx = ( extraShift * static_cast(Minecraft::GetInstance()->width) ) / static_cast(Minecraft::GetInstance()->width_phys); // 4J - Also factor in the scaling from gui coordinate space to the screen. This varies based on user-selected gui scale, and whether we are in a viewport mode or not dx /= Gui::currentGuiScaleFactor; float dy = extraShift / Gui::currentGuiScaleFactor; // Ensure that the x/y, width and height are actually pixel aligned at our current scale factor - in particular, for split screen mode with the default (3X) // scale, we have an overall scale factor of 3 * 0.5 = 1.5, and so any odd pixels won't align - float fx = (floorf((float)x * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; - float fy = (floorf((float)y * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; - float fw = (floorf((float)w * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; - float fh = (floorf((float)h * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; + float fx = (floorf(static_cast(x) * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; + float fy = (floorf(static_cast(y) * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; + float fw = (floorf(static_cast(w) * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; + float fh = (floorf(static_cast(h) * Gui::currentGuiScaleFactor)) / Gui::currentGuiScaleFactor; - t->vertexUV(fx + 0 - dx, fy + fh - dy, (float)( blitOffset), (float)( (sx + 0) * us), (float)( (sy + h) * vs)); - t->vertexUV(fx + fw - dx, fy + fh - dy, (float)( blitOffset), (float)( (sx + w) * us), (float)( (sy + h) * vs)); - t->vertexUV(fx + fw - dx, fy + 0 - dy, (float)( blitOffset), (float)( (sx + w) * us), (float)( (sy + 0) * vs)); - t->vertexUV(fx + 0 - dx, fy + 0 - dy, (float)( blitOffset), (float)( (sx + 0) * us), (float)( (sy + 0) * vs)); + t->vertexUV(fx + 0 - dx, fy + fh - dy, static_cast(blitOffset), static_cast((sx + 0) * us), static_cast((sy + h) * vs)); + t->vertexUV(fx + fw - dx, fy + fh - dy, static_cast(blitOffset), static_cast((sx + w) * us), static_cast((sy + h) * vs)); + t->vertexUV(fx + fw - dx, fy + 0 - dy, static_cast(blitOffset), static_cast((sx + w) * us), static_cast((sy + 0) * vs)); + t->vertexUV(fx + 0 - dx, fy + 0 - dy, static_cast(blitOffset), static_cast((sx + 0) * us), static_cast((sy + 0) * vs)); t->end(); } \ No newline at end of file diff --git a/Minecraft.Client/Screen.cpp b/Minecraft.Client/Screen.cpp index 6f7ef2773..9b7531460 100644 --- a/Minecraft.Client/Screen.cpp +++ b/Minecraft.Client/Screen.cpp @@ -49,7 +49,7 @@ wstring Screen::getClipboard() wstring out; if (h) { - const wchar_t *p = (const wchar_t *)GlobalLock(h); + const wchar_t *p = reinterpret_cast(GlobalLock(h)); if (p) { out = p; GlobalUnlock(h); } } CloseClipboard(); @@ -215,10 +215,10 @@ void Screen::updateEvents() else if (vk == VK_TAB) mappedKey = Keyboard::KEY_TAB; else if (vk >= 'A' && vk <= 'Z') { - ch = (wchar_t)(vk - 'A' + L'a'); - if (g_KBMInput.IsKeyDown(VK_LSHIFT) || g_KBMInput.IsKeyDown(VK_RSHIFT)) ch = (wchar_t)vk; + ch = static_cast(vk - 'A' + L'a'); + if (g_KBMInput.IsKeyDown(VK_LSHIFT) || g_KBMInput.IsKeyDown(VK_RSHIFT)) ch = static_cast(vk); } - else if (vk >= '0' && vk <= '9') ch = (wchar_t)vk; + else if (vk >= '0' && vk <= '9') ch = static_cast(vk); else if (vk == VK_SPACE) ch = L' '; if (mappedKey != -1) keyPressed(ch, mappedKey); @@ -306,10 +306,10 @@ void Screen::renderDirtBackground(int vo) float s = 32; t->begin(); t->color(0x404040); - t->vertexUV((float)(0), (float)( height), (float)( 0), (float)( 0), (float)( height / s + vo)); - t->vertexUV((float)(width), (float)( height), (float)( 0), (float)( width / s), (float)( height / s + vo)); - t->vertexUV((float)(width), (float)( 0), (float)( 0), (float)( width / s), (float)( 0 + vo)); - t->vertexUV((float)(0), (float)( 0), (float)( 0), (float)( 0), (float)( 0 + vo)); + t->vertexUV(static_cast(0), static_cast(height), static_cast(0), static_cast(0), static_cast(height / s + vo)); + t->vertexUV(static_cast(width), static_cast(height), static_cast(0), static_cast(width / s), static_cast(height / s + vo)); + t->vertexUV(static_cast(width), static_cast(0), static_cast(0), static_cast(width / s), static_cast(0 + vo)); + t->vertexUV(static_cast(0), static_cast(0), static_cast(0), static_cast(0), static_cast(0 + vo)); t->end(); #endif } diff --git a/Minecraft.Client/Windows64/KeyboardMouseInput.cpp b/Minecraft.Client/Windows64/KeyboardMouseInput.cpp index fe3c39194..d3e408065 100644 --- a/Minecraft.Client/Windows64/KeyboardMouseInput.cpp +++ b/Minecraft.Client/Windows64/KeyboardMouseInput.cpp @@ -257,8 +257,8 @@ bool KeyboardMouseInput::IsMouseButtonReleased(int button) const void KeyboardMouseInput::ConsumeMouseDelta(float &dx, float &dy) { - dx = (float)m_mouseDeltaAccumX; - dy = (float)m_mouseDeltaAccumY; + dx = static_cast(m_mouseDeltaAccumX); + dy = static_cast(m_mouseDeltaAccumY); m_mouseDeltaAccumX = 0; m_mouseDeltaAccumY = 0; } @@ -375,12 +375,12 @@ float KeyboardMouseInput::GetMoveY() const float KeyboardMouseInput::GetLookX(float sensitivity) const { - return (float)m_mouseDeltaX * sensitivity; + return static_cast(m_mouseDeltaX) * sensitivity; } float KeyboardMouseInput::GetLookY(float sensitivity) const { - return (float)(-m_mouseDeltaY) * sensitivity; + return static_cast(-m_mouseDeltaY) * sensitivity; } void KeyboardMouseInput::OnChar(wchar_t c) diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 4160b7576..208fd3f7d 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -575,13 +575,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_CHAR: // Buffer typed characters so UIScene_Keyboard can dispatch them to the Iggy Flash player if (wParam >= 0x20 || wParam == 0x08 || wParam == 0x0D) // printable chars + backspace + enter - g_KBMInput.OnChar((wchar_t)wParam); + g_KBMInput.OnChar(static_cast(wParam)); break; case WM_KEYDOWN: case WM_SYSKEYDOWN: { - int vk = (int)wParam; + int vk = static_cast(wParam); if ((lParam & 0x40000000) && vk != VK_LEFT && vk != VK_RIGHT && vk != VK_BACK) break; #ifdef _WINDOWS64 @@ -609,7 +609,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_KEYUP: case WM_SYSKEYUP: { - int vk = (int)wParam; + int vk = static_cast(wParam); if (vk == VK_SHIFT) vk = (MapVirtualKey((lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK_EX) == VK_RSHIFT) ? VK_RSHIFT : VK_LSHIFT; else if (vk == VK_CONTROL)