- consolidated shade to light conversion

This commit is contained in:
Christoph Oelckers 2020-07-31 20:58:55 +02:00
parent b308e730ea
commit b6cb0ce1a1
5 changed files with 13 additions and 18 deletions

View file

@ -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)
{

View file

@ -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;

View file

@ -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);
}
//---------------------------------------------------------------------------

View file

@ -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);
}
//---------------------------------------------------------------------------

View file

@ -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);
}
}