From b6cb0ce1a13354eaf9a7d179e1d83bc06365f523 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 31 Jul 2020 20:58:55 +0200 Subject: [PATCH] - consolidated shade to light conversion --- source/blood/src/qav.cpp | 4 +--- source/build/include/build.h | 7 +++++++ source/games/duke/src/2d_d.cpp | 8 ++------ source/games/duke/src/2d_r.cpp | 8 ++------ source/games/duke/src/game_misc.cpp | 4 +--- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/source/blood/src/qav.cpp b/source/blood/src/qav.cpp index 429aadaa1..d671e409c 100644 --- a/source/blood/src/qav.cpp +++ b/source/blood/src/qav.cpp @@ -62,9 +62,7 @@ void DrawFrame(F2DDrawer *twod, int x, int y, TILE_FRAME *pTile, int stat, int s bool xflip = !!(stat & 0x100); // repurposed flag bool yflip = !!(stat & RS_YFLIP); - shade = clamp(pTile->shade + shade, 0, numshades-1); - int light = ::scale(numshades-1-shade, 255, numshades-1); - PalEntry color(255,light,light,light); + auto color = shadeToLight(pTile->shade + shade); if (!to3dview) { diff --git a/source/build/include/build.h b/source/build/include/build.h index 6845964e8..241edac6e 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -374,6 +374,13 @@ EXTERN int16_t sintable[2048]; EXTERN int16_t numshades; EXTERN uint8_t paletteloaded; +// Return type is int because this gets passed to variadic functions where structs may produce undefined behavior. +inline int shadeToLight(int shade) +{ + shade = clamp(shade, 0, numshades-1); + int light = scale(numshades-1-shade, 255, numshades-1); + return PalEntry(255,light,light,light); +} EXTERN int32_t maxspritesonscreen; diff --git a/source/games/duke/src/2d_d.cpp b/source/games/duke/src/2d_d.cpp index aa2385358..f67e5e286 100644 --- a/source/games/duke/src/2d_d.cpp +++ b/source/games/duke/src/2d_d.cpp @@ -144,18 +144,14 @@ static void GameText(double x, double y, const char* t, int shade, int align = - { if (align != -1) x -= SmallFont->StringWidth(t) * (align == 0 ? 0.5 : 1); - int light = Scale(numshades - shade, 255, numshades); - PalEntry pe(255, light, light, light); - DrawText(twod, SmallFont, CR_UNDEFINED, x, y + 2, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, pe, TAG_DONE); + DrawText(twod, SmallFont, CR_UNDEFINED, x, y + 2, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, shadeToLight(shade), TAG_DONE); } static void MiniText(double x, double y, const char* t, int shade, int align = -1, int trans = 0) { if (align != -1) x -= SmallFont2->StringWidth(t) * (align == 0 ? 0.5 : 1); - int light = Scale(numshades - shade, 255, numshades); - PalEntry pe(255, light, light, light); - DrawText(twod, SmallFont2, CR_UNDEFINED, x, y, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, pe, TAG_DONE); + DrawText(twod, SmallFont2, CR_UNDEFINED, x, y, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, shadeToLight(shade), TAG_DONE); } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/2d_r.cpp b/source/games/duke/src/2d_r.cpp index 132a743de..5e5415e3a 100644 --- a/source/games/duke/src/2d_r.cpp +++ b/source/games/duke/src/2d_r.cpp @@ -144,9 +144,7 @@ static void GameText(double x, double y, const char* t, int shade, int align = - x *= 2; y *= 2; if (align != -1) x -= SmallFont->StringWidth(t) * (align == 0 ? 0.5 : 1); - int light = Scale(numshades - shade, 255, numshades); - PalEntry pe(255, light, light, light); - DrawText(twod, SmallFont, CR_UNDEFINED, x, y + 2, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 640, DTA_VirtualHeight, 400, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, pe, TAG_DONE); + DrawText(twod, SmallFont, CR_UNDEFINED, x, y + 2, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 640, DTA_VirtualHeight, 400, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, shadeToLight(shade), TAG_DONE); } static void MiniText(double x, double y, const char* t, int shade, int align = -1, int trans = 0) @@ -154,9 +152,7 @@ static void MiniText(double x, double y, const char* t, int shade, int align = - x *= 2; y *= 2; if (align != -1) x -= SmallFont2->StringWidth(t) * (align == 0 ? 0.5 : 1); - int light = Scale(numshades - shade, 255, numshades); - PalEntry pe(255, light, light, light); - DrawText(twod, SmallFont2, CR_UNDEFINED, x, y, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 640, DTA_VirtualHeight, 400, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, pe, TAG_DONE); + DrawText(twod, SmallFont2, CR_UNDEFINED, x, y, t, DTA_FullscreenScale, 3, DTA_VirtualWidth, 640, DTA_VirtualHeight, 400, DTA_TranslationIndex, TRANSLATION(Translation_Remap, trans), DTA_Color, shadeToLight(shade), TAG_DONE); } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 0b72832a5..a8d54b0be 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -649,10 +649,8 @@ void drawoverheadmap(int cposx, int cposy, int czoom, int cang) if (j < 22000) j = 22000; else if (j > (65536 << 1)) j = (65536 << 1); - int light = Scale(numshades - sprite[pp.i].shade, 255, numshades); - PalEntry pe(255, light, light, light); DrawTexture(twod, tileGetTexture(i), xdim / 2. + x1 / 4096., ydim / 2. + y1 / 4096., DTA_TranslationIndex, TRANSLATION(Translation_Remap + pp.palette, sprite[pp.i].pal), - DTA_Color, pe, DTA_ScaleX, j / 65536., DTA_ScaleY, j/65536., TAG_DONE); + DTA_Color, shadeToLight(sprite[pp.i].shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j/65536., TAG_DONE); } }