optimize software hud drawing
from srb2classic adjusted to our drawers
This commit is contained in:
1 parent
c719637937
commit
39c7fc8c0d
1 file changed
+170
-67
+170
-67
@@ -636,29 +636,17 @@ UINT8 hudtrans = 0;
|
||||
static const UINT8 *v_colormap = NULL;
|
||||
static const UINT8 *v_translevel = NULL;
|
||||
|
||||
FUNCINLINE static ATTRINLINE UINT8 standardpdraw(const UINT8 *dest, const UINT8 *source, fixed_t ofs)
|
||||
{
|
||||
(void)dest; return source[ofs>>FRACBITS];
|
||||
}
|
||||
FUNCINLINE static ATTRINLINE UINT8 mappedpdraw(const UINT8 *dest, const UINT8 *source, fixed_t ofs)
|
||||
{
|
||||
(void)dest; return *(v_colormap + source[ofs>>FRACBITS]);
|
||||
}
|
||||
FUNCINLINE static ATTRINLINE UINT8 translucentpdraw(const UINT8 *dest, const UINT8 *source, fixed_t ofs)
|
||||
{
|
||||
return *(v_translevel + ((source[ofs>>FRACBITS]<<8)&0xff00) + (*dest&0xff));
|
||||
}
|
||||
FUNCINLINE static ATTRINLINE UINT8 transmappedpdraw(const UINT8 *dest, const UINT8 *source, fixed_t ofs)
|
||||
{
|
||||
return *(v_translevel + (((*(v_colormap + source[ofs>>FRACBITS]))<<8)&0xff00) + (*dest&0xff));
|
||||
}
|
||||
#define STANDARDDRAW 1
|
||||
#define MAPPEDDRAW 2
|
||||
#define TRANSLUCENTDRAW 3
|
||||
#define TRANSMAPPEDDRAW 4
|
||||
|
||||
// Draws a patch scaled to arbitrary size.
|
||||
void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 scrn, patch_t *patch, const UINT8 *colormap, INT32 bflags)
|
||||
{
|
||||
UINT8 (*patchdrawfunc)(const UINT8*, const UINT8*, fixed_t);
|
||||
UINT32 alphalevel = ((scrn & V_ALPHAMASK) >> V_ALPHASHIFT);
|
||||
UINT32 blendmode = ((bflags & V_BLENDMASK) >> V_BLENDSHIFT);
|
||||
UINT8 patchdrawtype;
|
||||
UINT32 alphalevel;
|
||||
UINT32 blendmode;
|
||||
|
||||
fixed_t col, ofs, colfrac, rowfrac, fdup, vdup;
|
||||
INT32 dupx, dupy;
|
||||
@@ -683,7 +671,10 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
}
|
||||
#endif
|
||||
|
||||
patchdrawfunc = standardpdraw;
|
||||
alphalevel = ((scrn & V_ALPHAMASK) >> V_ALPHASHIFT);
|
||||
blendmode = ((bflags & V_BLENDMASK) >> V_BLENDSHIFT);
|
||||
|
||||
patchdrawtype = STANDARDDRAW;
|
||||
|
||||
v_translevel = NULL;
|
||||
if (alphalevel || blendmode)
|
||||
@@ -701,7 +692,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
if (alphalevel || blendmode)
|
||||
{
|
||||
v_translevel = R_GetBlendTable(blendmode+1, alphalevel);
|
||||
patchdrawfunc = translucentpdraw;
|
||||
patchdrawtype = TRANSLUCENTDRAW;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,7 +701,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
if (colormap)
|
||||
{
|
||||
v_colormap = colormap;
|
||||
patchdrawfunc = (v_translevel) ? transmappedpdraw : mappedpdraw;
|
||||
patchdrawtype = (v_translevel) ? TRANSMAPPEDDRAW : MAPPEDDRAW;
|
||||
}
|
||||
|
||||
dupx = vid.dupx;
|
||||
@@ -851,6 +842,8 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
deststart = desttop;
|
||||
destend = desttop + pwidth;
|
||||
|
||||
const INT32 stride = vid.width;
|
||||
|
||||
for (col = 0; (col>>FRACBITS) < patch->width; col += colfrac, ++offx, desttop++)
|
||||
{
|
||||
INT32 topdelta, prevdelta = -1;
|
||||
@@ -858,37 +851,111 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
{
|
||||
if (x+pwidth-offx < 0) // don't draw off the left of the screen (WRAP PREVENTION)
|
||||
break;
|
||||
if (x+pwidth-offx >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
if (x+pwidth-offx >= stride) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x+offx < 0) // don't draw off the left of the screen (WRAP PREVENTION)
|
||||
continue;
|
||||
if (x+offx >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
if (x+offx >= stride) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
break;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[col>>FRACBITS]));
|
||||
|
||||
while (column->topdelta != 0xff)
|
||||
switch (patchdrawtype)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (scrn & V_FLIP)
|
||||
dest = deststart + (destend - desttop);
|
||||
dest += FixedInt(FixedMul(topdelta<<FRACBITS,vdup))*vid.width;
|
||||
case STANDARDDRAW:
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (scrn & V_FLIP)
|
||||
dest = deststart + (destend - desttop);
|
||||
dest += FixedInt(FixedMul(topdelta<<FRACBITS,vdup))*stride;
|
||||
|
||||
for (ofs = 0; dest < deststop && (ofs>>FRACBITS) < column->length; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = patchdrawfunc(dest, source, ofs);
|
||||
dest += vid.width;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
for (ofs = 0; dest < deststop && (ofs>>FRACBITS) < column->length; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = source[ofs>>FRACBITS];
|
||||
dest += stride;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case MAPPEDDRAW:
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (scrn & V_FLIP)
|
||||
dest = deststart + (destend - desttop);
|
||||
dest += FixedInt(FixedMul(topdelta<<FRACBITS,vdup))*stride;
|
||||
|
||||
for (ofs = 0; dest < deststop && (ofs>>FRACBITS) < column->length; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = *(v_colormap + source[ofs>>FRACBITS]);
|
||||
dest += stride;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case TRANSLUCENTDRAW:
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (scrn & V_FLIP)
|
||||
dest = deststart + (destend - desttop);
|
||||
dest += FixedInt(FixedMul(topdelta<<FRACBITS,vdup))*stride;
|
||||
|
||||
for (ofs = 0; dest < deststop && (ofs>>FRACBITS) < column->length; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = *(v_translevel + ((source[ofs>>FRACBITS]<<8)&0xff00) + (*dest&0xff));
|
||||
dest += stride;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case TRANSMAPPEDDRAW:
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (scrn & V_FLIP)
|
||||
dest = deststart + (destend - desttop);
|
||||
dest += FixedInt(FixedMul(topdelta<<FRACBITS,vdup))*stride;
|
||||
|
||||
for (ofs = 0; dest < deststop && (ofs>>FRACBITS) < column->length; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = *(v_translevel + (((*(v_colormap + source[ofs>>FRACBITS]))<<8)&0xff00) + (*dest&0xff));
|
||||
dest += stride;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -896,9 +963,8 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca
|
||||
// Draws a patch cropped and scaled to arbitrary size.
|
||||
void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t *patch, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h)
|
||||
{
|
||||
UINT8 (*patchdrawfunc)(const UINT8*, const UINT8*, fixed_t);
|
||||
UINT8 patchdrawtype;
|
||||
UINT32 alphalevel = 0;
|
||||
// boolean flip = false;
|
||||
|
||||
fixed_t col, ofs, colfrac, rowfrac, fdup;
|
||||
INT32 dupx, dupy;
|
||||
@@ -920,7 +986,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_
|
||||
}
|
||||
#endif
|
||||
|
||||
patchdrawfunc = standardpdraw;
|
||||
patchdrawtype = STANDARDDRAW;
|
||||
|
||||
v_translevel = NULL;
|
||||
if ((alphalevel = ((scrn & V_ALPHAMASK) >> V_ALPHASHIFT)))
|
||||
@@ -938,7 +1004,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_
|
||||
if (alphalevel)
|
||||
{
|
||||
v_translevel = transtables + ((alphalevel-1)<<FF_TRANSSHIFT);
|
||||
patchdrawfunc = translucentpdraw;
|
||||
patchdrawtype = TRANSLUCENTDRAW;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,38 +1065,75 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_
|
||||
desttop += (y*vid.width) + x;
|
||||
}
|
||||
|
||||
const INT32 stride = vid.width;
|
||||
|
||||
for (col = sx<<FRACBITS; (col>>FRACBITS) < patch->width && ((col>>FRACBITS) - sx) < w; col += colfrac, ++x, desttop++)
|
||||
{
|
||||
INT32 topdelta, prevdelta = -1;
|
||||
|
||||
if (x < 0) // don't draw off the left of the screen (WRAP PREVENTION)
|
||||
continue;
|
||||
if (x >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
|
||||
if (x >= stride) // don't draw off the right of the screen (WRAP PREVENTION)
|
||||
break;
|
||||
|
||||
column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[col>>FRACBITS]));
|
||||
|
||||
while (column->topdelta != 0xff)
|
||||
switch (patchdrawtype)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (topdelta-sy > 0)
|
||||
{
|
||||
dest += FixedInt(FixedMul((topdelta-sy)<<FRACBITS,fdup))*vid.width;
|
||||
ofs = 0;
|
||||
}
|
||||
else
|
||||
ofs = (sy-topdelta)<<FRACBITS;
|
||||
case STANDARDDRAW:
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (topdelta-sy > 0)
|
||||
{
|
||||
dest += FixedInt(FixedMul((topdelta-sy)<<FRACBITS,fdup))*stride;
|
||||
ofs = 0;
|
||||
}
|
||||
else
|
||||
ofs = (sy-topdelta)<<FRACBITS;
|
||||
|
||||
for (; dest < deststop && (ofs>>FRACBITS) < column->length && (((ofs>>FRACBITS) - sy) + topdelta) < h; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = patchdrawfunc(dest, source, ofs);
|
||||
dest += vid.width;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
for (; dest < deststop && (ofs>>FRACBITS) < column->length && (((ofs>>FRACBITS) - sy) + topdelta) < h; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = source[ofs>>FRACBITS];
|
||||
dest += stride;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case TRANSLUCENTDRAW:
|
||||
while (column->topdelta != 0xff)
|
||||
{
|
||||
topdelta = column->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)(column) + 3;
|
||||
dest = desttop;
|
||||
if (topdelta-sy > 0)
|
||||
{
|
||||
dest += FixedInt(FixedMul((topdelta-sy)<<FRACBITS,fdup))*stride;
|
||||
ofs = 0;
|
||||
}
|
||||
else
|
||||
ofs = (sy-topdelta)<<FRACBITS;
|
||||
|
||||
for (; dest < deststop && (ofs>>FRACBITS) < column->length && (((ofs>>FRACBITS) - sy) + topdelta) < h; ofs += rowfrac)
|
||||
{
|
||||
if (dest >= vid.screens[scrn&V_PARAMMASK]) // don't draw off the top of the screen (CRASH PREVENTION)
|
||||
*dest = *(v_translevel + ((source[ofs>>FRACBITS]<<8)&0xff00) + (*dest&0xff));
|
||||
dest += stride;
|
||||
}
|
||||
column = (const column_t *)((const UINT8 *)column + column->length + 4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user