From be23f6864b607a26bafd6531adf37976da2f5fcd Mon Sep 17 00:00:00 2001 From: ephphatha Date: Mon, 5 Jul 2021 19:56:38 +1000 Subject: [PATCH] Reorder int *= float operations that could be expressed using int fractions This was triggering narrowing conversion warnings in msvc. I assume the compiler can optimise this into a float multiplication if it does turn out faster. --- Source/DiabloUI/ttf_render_wrapped.cpp | 2 +- Source/items.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/DiabloUI/ttf_render_wrapped.cpp b/Source/DiabloUI/ttf_render_wrapped.cpp index d569ceec4..a88fe741f 100644 --- a/Source/DiabloUI/ttf_render_wrapped.cpp +++ b/Source/DiabloUI/ttf_render_wrapped.cpp @@ -142,7 +142,7 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo SDLC_SetColorKey(textbuf, 0); // Reduced space between lines to roughly match Diablo. - const int lineskip = 0.7 * TTF_FontLineSkip(font); + const int lineskip = TTF_FontLineSkip(font) * 7 / 10; // avoids forced int > float > int conversion SDL_Rect dest = { 0, 0, 0, 0 }; for (std::size_t line = 0; line < numLines; line++) { text = strLines[line]; diff --git a/Source/items.cpp b/Source/items.cpp index 281c47907..929e0bba4 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4257,7 +4257,7 @@ static void SpawnOnePremium(int i, int plvl, int playerId) itemValue = 0; break; } - itemValue *= 0.8; + itemValue = itemValue * 4 / 5; // avoids forced int > float > int conversion count++; } while (keepGoing @@ -4504,7 +4504,7 @@ void SpawnBoy(int lvl) break; } } - ivalue *= 0.8; + ivalue = ivalue * 4 / 5; // avoids forced int > float > int conversion count++;