Refactor: separate parts of V_DrawCustomFadeScreen into reusable functions

This commit is contained in:
James R 2024-03-18 02:21:16 -07:00
parent 244d5e1063
commit 6efa35549b
2 changed files with 38 additions and 23 deletions

View file

@ -1566,6 +1566,31 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength)
.done();
}
lighttable_t *V_LoadCustomFadeMap(const char *lump)
{
lumpnum_t lumpnum = LUMPERROR;
lighttable_t *clm = NULL;
if (lump != NULL)
lumpnum = W_GetNumForName(lump);
else
return NULL;
if (lumpnum != LUMPERROR)
{
clm = static_cast<lighttable_t*>(Z_MallocAlign(COLORMAP_SIZE, PU_STATIC, NULL, 8));
W_ReadLump(lumpnum, clm);
return clm;
}
return NULL;
}
const UINT8 *V_OffsetIntoFadeMap(const lighttable_t *clm, UINT8 strength)
{
return ((const UINT8 *)clm + strength*256);
}
//
// Fade the screen buffer, using a custom COLORMAP lump.
// Split from V_DrawFadeScreen, because that function has
@ -1583,22 +1608,11 @@ void V_DrawCustomFadeScreen(const char *lump, UINT8 strength)
// TODO: fix this for Twodee
{
lumpnum_t lumpnum = LUMPERROR;
lighttable_t *clm = NULL;
if (lump != NULL)
lumpnum = W_GetNumForName(lump);
else
return;
if (lumpnum != LUMPERROR)
{
clm = static_cast<lighttable_t*>(Z_MallocAlign(COLORMAP_SIZE, PU_STATIC, NULL, 8));
W_ReadLump(lumpnum, clm);
lighttable_t *clm = V_LoadCustomFadeMap(lump);
if (clm != NULL)
{
const UINT8 *fadetable = ((UINT8 *)clm + strength*256);
const UINT8 *fadetable = V_OffsetIntoFadeMap(clm, strength);
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
UINT8 *buf = screens[0];
@ -1612,7 +1626,6 @@ void V_DrawCustomFadeScreen(const char *lump, UINT8 strength)
}
}
}
}
// Simple translucency with one color, over a set number of lines starting from the top.
void V_DrawFadeConsBack(INT32 plines)

View file

@ -236,6 +236,8 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength);
// available to lua over my dead body, which will probably happen in this heat
void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, UINT8 strength);
lighttable_t *V_LoadCustomFadeMap(const char *lump);
const UINT8 *V_OffsetIntoFadeMap(const lighttable_t *clm, UINT8 strength);
void V_DrawCustomFadeScreen(const char *lump, UINT8 strength);
void V_DrawFadeConsBack(INT32 plines);