port the span and column drawer templates + tilted translucent splat drawer

took the liberty to also carry over our optimizations, this is actually slightly faster than what we had before
This commit is contained in:
Alug committed 2025-06-13 03:23:25 +02:00
1 parent 68c7620349
commit 2eae9b197c
9 files changed
+814 -2036

No files matched your search

+8
View File
@@ -6,6 +6,10 @@
#ifndef __K_KART__
#define __K_KART__
#ifdef __cplusplus
extern "C" {
#endif
#include "doomdef.h"
#include "d_player.h" // Need for player_t
@@ -132,5 +136,9 @@ INT32 K_getMinimapTrans(void);
void K_getLapsDrawinfo(drawinfo_t *out);
void K_getMinimapDrawinfo(drawinfo_t *out);
#ifdef __cplusplus
} // extern "C"
#endif
// =========================================================================
#endif // __K_KART__
+21 -22
View File
@@ -15,6 +15,8 @@
/// not the architecture of the frame buffer.
/// The frame buffer is a linear one, and we need only the base address.
#include <algorithm>
#include "doomdef.h"
#include "doomstat.h"
#include "r_local.h"
@@ -115,8 +117,7 @@ void R_InitTranslucencyTables(void)
// Load here the transparency lookup tables 'TRANSx0'
// NOTE: the TRANSx0 resources MUST BE aligned on 64k for the asm
// optimised code (in other words, transtables pointer low word is 0)
transtables = Z_MallocAlign(NUMTRANSTABLES*0x10000, PU_STATIC,
NULL, 16);
transtables = static_cast<UINT8*>(Z_MallocAlign(NUMTRANSTABLES*0x10000, PU_STATIC, NULL, 16));
W_ReadLump(W_GetNumForName("TRANS10"), transtables);
W_ReadLump(W_GetNumForName("TRANS20"), transtables+0x10000);
@@ -177,10 +178,10 @@ static void BlendTab_Subtractive(UINT8 *table, int style, UINT8 blendamt)
RGBA_t frontrgba = V_GetColor(fg);
RGBA_t result;
result.rgba = ASTBlendPixel(backrgba, frontrgba, style, 0xFF);
result.s.red = max(0, result.s.red - blendamt);
result.s.green = max(0, result.s.green - blendamt);
result.s.blue = max(0, result.s.blue - blendamt);
result.rgba = ASTBlendPixel(backrgba, frontrgba, style, 0xFF);
result.s.red = std::max(0, result.s.red - blendamt);
result.s.green = std::max(0, result.s.green - blendamt);
result.s.blue = std::max(0, result.s.blue - blendamt);
table[((bg * 0x100) + fg)] = GetColorLUT(&transtab_lut, result.s.red, result.s.green, result.s.blue);
}
@@ -233,7 +234,7 @@ static void BlendTab_GenerateMaps(INT32 tab, INT32 style, void (*genfunc)(UINT8
for (; i < num; i++)
{
const size_t offs = (0x10000 * i);
const UINT16 alpha = min(amtmul * i, 0xFF);
const UINT16 alpha = std::fmin(amtmul * i, 0xFF);
genfunc(blendtables[tab] + offs, style, alpha);
}
}
@@ -243,7 +244,7 @@ void R_GenerateBlendTables(void)
INT32 i;
for (i = 0; i < NUMBLENDMAPS; i++)
blendtables[i] = Z_MallocAlign(BlendTab_Count[i] * 0x10000, PU_STATIC, NULL, 16);
blendtables[i] = static_cast<UINT8*>(Z_MallocAlign(BlendTab_Count[i] * 0x10000, PU_STATIC, NULL, 16));
InitColorLUT(&transtab_lut, pLocalPalette, false);
@@ -264,8 +265,8 @@ void R_GenerateBlendTables(void)
BlendTab_Modulative(blendtables[blendtab_modulate]);
}
#define ClipBlendLevel(style, trans) max(min((trans), BlendTab_Count[BlendTab_FromStyle[style]]-1), 0)
#define ClipTransLevel(trans) max(min((trans), NUMTRANSMAPS-2), 0)
#define ClipBlendLevel(style, trans) std::max(std::min((trans), BlendTab_Count[BlendTab_FromStyle[style]]-1), 0)
#define ClipTransLevel(trans) std::max(std::min((trans), NUMTRANSMAPS-2), 0)
UINT8 *R_GetTranslucencyTable(INT32 alphalevel)
{
@@ -352,7 +353,7 @@ static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 f
{
// Allocate table for skin if necessary
if (!tt[skintableindex])
tt[skintableindex] = Z_Calloc(MAXTRANSLATIONS * sizeof(UINT8**), PU_STATIC, NULL);
tt[skintableindex] = static_cast<UINT8**>(Z_Calloc(MAXTRANSLATIONS * sizeof(UINT8**), PU_STATIC, NULL));
// Get colormap
ret = tt[skintableindex][color];
@@ -362,7 +363,7 @@ static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 f
// Generate the colormap if necessary
if (!ret)
{
ret = Z_MallocAlign(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL, 8);
ret = static_cast<UINT8*>(Z_MallocAlign(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL, 8));
K_GenerateKartColormap(ret, skinnum, color, local); //R_GenerateTranslationColormap(ret, skinnum, color); // SRB2kart
// Cache the colormap if desired
@@ -457,17 +458,15 @@ void R_FlushTranslationColormapCache(void)
static void R_AllocViewMemory(void)
{
negonearray = Z_Realloc(negonearray, sizeof(*negonearray) * viewwidth, PU_STATIC, NULL);
screenheightarray = Z_Realloc(screenheightarray, sizeof(*screenheightarray) * viewwidth, PU_STATIC, NULL);
negonearray = static_cast<INT16*>(Z_Realloc(negonearray, sizeof(*negonearray) * viewwidth, PU_STATIC, NULL));
screenheightarray = static_cast<INT16*>(Z_Realloc(screenheightarray, sizeof(*screenheightarray) * viewwidth, PU_STATIC, NULL));
floorclip = Z_Realloc(floorclip, sizeof(*floorclip) * viewwidth, PU_STATIC, NULL);
ceilingclip = Z_Realloc(ceilingclip, sizeof(*ceilingclip) * viewwidth, PU_STATIC, NULL);
floorclip = static_cast<INT16*>(Z_Realloc(floorclip, sizeof(*floorclip) * viewwidth, PU_STATIC, NULL));
ceilingclip = static_cast<INT16*>(Z_Realloc(ceilingclip, sizeof(*ceilingclip) * viewwidth, PU_STATIC, NULL));
frontscale = Z_Realloc(frontscale, sizeof(*frontscale) * viewwidth, PU_STATIC, NULL);
frontscale = static_cast<fixed_t*>(Z_Realloc(frontscale, sizeof(*frontscale) * viewwidth, PU_STATIC, NULL));
xtoviewangle = Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL);
//tiltlighting = Z_Realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth, PU_STATIC, NULL);
xtoviewangle = static_cast<angle_t*>(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL));
R_AllocSegMemory();
R_AllocClipSegMemory();
@@ -662,5 +661,5 @@ void R_DrawViewBorder(void)
// INCLUDE DRAWING CODE HERE
// ==========================================================================
#include "r_draw_column.c"
#include "r_draw_span.c"
#include "r_draw_column.cpp"
#include "r_draw_span.cpp"
+2
View File
@@ -136,6 +136,7 @@ enum
SPANDRAWFUNC_SPLAT,
SPANDRAWFUNC_TRANSSPLAT,
SPANDRAWFUNC_TILTEDSPLAT,
SPANDRAWFUNC_TILTEDTRANSSPLAT,
SPANDRAWFUNC_WATER,
SPANDRAWFUNC_TILTEDWATER,
@@ -264,6 +265,7 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds);
void R_DrawSplat_Tilted(drawspandata_t* ds);
void R_DrawSplat(drawspandata_t* ds);
void R_DrawTranslucentSplat(drawspandata_t* ds);
void R_DrawTranslucentSplat_Tilted(drawspandata_t* ds);
#ifdef __cplusplus
} // extern "C"
-780
View File
@@ -1,780 +0,0 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2018 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file r_draw_column.c
/// \brief column drawer functions
/// \note no includes because this is included as part of r_draw.c
// ==========================================================================
// COLUMNS
// ==========================================================================
// A column is a vertical slice/span of a wall texture that uses
// a has a constant z depth from top to bottom.
//
/** \brief The R_DrawColumn function
Experiment to make software go faster. Taken from the Boom source
*/
void R_DrawColumn(drawcolumndata_t* dc)
{
INT32 count;
register UINT8 *restrict dest;
intptr_t frac;
count = dc->yh - dc->yl;
if (count < 0) // Zero length, column does not exceed a pixel.
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
count++;
// Determine scaling, which is the only mapping to be done.
const intptr_t fracstep = dc->iscale;
frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets.
const UINT8 *restrict source = dc->source;
const lighttable_t *restrict colormap = dc->colormap;
intptr_t heightmask = dc->sourcelength-1;
static const INT32 npow2min = -1;
const INT32 npow2max = dc->sourcelength;
register const INT32 stride = vid.width;
if (heightmask == -1)
{
// texture has no height, so just go
while (--count > 0)
{
*dest = colormap[source[frac>>FRACBITS]];
dest += stride;
frac += fracstep;
}
}
else if (dc->sourcelength & heightmask) // not a power of 2 -- killough
{
heightmask = dc->texheight << FRACBITS;
if (frac < 0)
{
while ((frac += heightmask) < 0)
{
;
}
}
else
{
while (frac >= heightmask)
{
frac -= heightmask;
}
}
do
{
// Re-map color indices from wall texture column
// using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
*dest = colormap[source[CLAMP(frac >> FRACBITS, npow2min, npow2max)]];
dest += stride;
#if __SIZEOF_POINTER__ < 8 // 64-bit systems have large enough numbers for this to be a non-issue
// Avoid overflow.
if (fracstep > 0x7FFFFFFF - frac)
{
frac += fracstep - heightmask;
}
else
#endif
{
frac += fracstep;
}
while (frac >= heightmask)
{
frac -= heightmask;
}
} while (--count);
}
else
{
while ((count -= 2) >= 0) // texture height is a power of 2
{
*dest = colormap[source[(frac>>FRACBITS) & heightmask]];
dest += stride;
frac += fracstep;
*dest = colormap[source[(frac>>FRACBITS) & heightmask]];
dest += stride;
frac += fracstep;
}
if (count & 1)
{
*dest = colormap[source[(frac>>FRACBITS) & heightmask]];
}
}
}
void R_Draw2sMultiPatchColumn(drawcolumndata_t* dc)
{
INT32 count;
register UINT8 *restrict dest;
intptr_t frac;
count = dc->yh - dc->yl;
if (count < 0) // Zero length, column does not exceed a pixel.
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
count++;
// Determine scaling, which is the only mapping to be done.
const intptr_t fracstep = dc->iscale;
frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets.
const UINT8 *restrict source = dc->source;
const lighttable_t *restrict colormap = dc->colormap;
intptr_t heightmask = dc->sourcelength-1;
UINT8 val;
static const INT32 npow2min = -1;
const INT32 npow2max = dc->sourcelength;
register const INT32 stride = vid.width;
if (heightmask == -1)
{
// texture has no height, so just go
while (--count > 0)
{
*dest = colormap[source[frac>>FRACBITS]];
dest += stride;
frac += fracstep;
}
}
else if (dc->sourcelength & heightmask) // not a power of 2 -- killough
{
heightmask = dc->texheight << FRACBITS;
if (frac < 0)
{
while ((frac += heightmask) < 0)
{
;
}
}
else
{
while (frac >= heightmask)
{
frac -= heightmask;
}
}
do
{
// Re-map color indices from wall texture column
// using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
val = source[CLAMP(frac >> FRACBITS, npow2min, npow2max)];
if (val != TRANSPARENTPIXEL)
{
*dest = colormap[val];
}
dest += stride;
// Avoid overflow.
#if __SIZEOF_POINTER__ < 8
if (fracstep > 0x7FFFFFFF - frac)
{
frac += fracstep - heightmask;
}
else
#endif
{
frac += fracstep;
}
while (frac >= heightmask)
{
frac -= heightmask;
}
} while (--count);
}
else
{
while ((count -= 2) >= 0) // texture height is a power of 2
{
val = source[(frac>>FRACBITS) & heightmask];
if (val != TRANSPARENTPIXEL)
{
*dest = colormap[val];
}
dest += stride;
frac += fracstep;
val = source[(frac>>FRACBITS) & heightmask];
if (val != TRANSPARENTPIXEL)
{
*dest = colormap[val];
}
dest += stride;
frac += fracstep;
}
if (count & 1)
{
val = source[CLAMP(frac >> FRACBITS, -1, dc->sourcelength)];
if (val != TRANSPARENTPIXEL)
{
*dest = colormap[val];
}
}
}
}
void R_Draw2sMultiPatchTranslucentColumn(drawcolumndata_t* dc)
{
INT32 count;
register UINT8 *restrict dest;
intptr_t frac;
count = dc->yh - dc->yl;
if (count < 0) // Zero length, column does not exceed a pixel.
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
count++;
// Determine scaling, which is the only mapping to be done.
const intptr_t fracstep = dc->iscale;
frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets.
const UINT8 *restrict source = dc->source;
const UINT8 *transmap = dc->transmap;
const lighttable_t *restrict colormap = dc->colormap;
intptr_t heightmask = dc->sourcelength-1;
register UINT8 val;
static const INT32 npow2min = -1;
const INT32 npow2max = dc->sourcelength;
register const INT32 stride = vid.width;
if (heightmask == -1)
{
// texture has no height, so just go
while (--count > 0)
{
*dest = colormap[source[frac>>FRACBITS]];
dest += stride;
frac += fracstep;
}
}
else if (dc->sourcelength & heightmask) // not a power of 2 -- killough
{
heightmask = dc->texheight << FRACBITS;
if (frac < 0)
{
while ((frac += heightmask) < 0)
{
;
}
}
else
{
while (frac >= heightmask)
{
frac -= heightmask;
}
}
do
{
// Re-map color indices from wall texture column
// using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
val = source[CLAMP(frac >> FRACBITS, npow2min, npow2max)];
if (val != TRANSPARENTPIXEL)
{
*dest = *(transmap + (colormap[val]<<8) + (*dest));
}
dest += stride;
// Avoid overflow.
#if __SIZEOF_POINTER__ < 8
if (fracstep > 0x7FFFFFFF - frac)
{
frac += fracstep - heightmask;
}
else
#endif
{
frac += fracstep;
}
while (frac >= heightmask)
{
frac -= heightmask;
}
} while (--count);
}
else
{
while ((count -= 2) >= 0) // texture height is a power of 2
{
val = source[(frac>>FRACBITS) & heightmask];
if (val != TRANSPARENTPIXEL)
{
*dest = *(transmap + (colormap[val]<<8) + (*dest));
}
dest += stride;
frac += fracstep;
val = source[(frac>>FRACBITS) & heightmask];
if (val != TRANSPARENTPIXEL)
{
*dest = *(transmap + (colormap[val]<<8) + (*dest));
}
dest += stride;
frac += fracstep;
}
if (count & 1)
{
val = source[(frac>>FRACBITS) & heightmask];
if (val != TRANSPARENTPIXEL)
{
*dest = *(transmap + (colormap[val]<<8) + (*dest));
}
}
}
}
/** \brief The R_DrawTranslucentColumn function
I've made an asm routine for the transparency, because it slows down
a lot in 640x480 with big sprites (bfg on all screen, or transparent
walls on fullscreen)
*/
void R_DrawTranslucentColumn(drawcolumndata_t* dc)
{
register INT32 count;
register UINT8 *restrict dest;
intptr_t frac;
count = dc->yh - dc->yl + 1;
if (count <= 0) // Zero length, column does not exceed a pixel.
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
// Looks familiar.
const intptr_t fracstep = dc->iscale;
frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets.
const UINT8 *restrict source = dc->source;
const UINT8 *transmap = dc->transmap;
const lighttable_t *restrict colormap = dc->colormap;
intptr_t heightmask = dc->sourcelength-1;
static const INT32 npow2min = -1;
const INT32 npow2max = dc->sourcelength;
register const INT32 stride = vid.width;
if (dc->sourcelength & heightmask)
{
heightmask = dc->texheight << FRACBITS;
if (frac < 0)
{
while ((frac += heightmask) < 0)
{
;
}
}
else
{
while (frac >= heightmask)
{
frac -= heightmask;
}
}
do
{
// Re-map color indices from wall texture column
// using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
*dest = *(transmap + (colormap[source[CLAMP(frac >> FRACBITS, npow2min, npow2max)]]<<8) + (*dest));
dest += stride;
if ((frac += fracstep) >= heightmask)
{
frac -= heightmask;
}
}
while (--count);
}
else
{
while ((count -= 2) >= 0) // texture height is a power of 2
{
*dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest));
dest += stride;
frac += fracstep;
*dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest));
dest += stride;
frac += fracstep;
}
if (count & 1)
{
*dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest));
}
}
}
/** \brief The R_DrawTranslatedTranslucentColumn function
Spiffy function. Not only does it colormap a sprite, but does translucency as well.
Uber-kudos to Cyan Helkaraxe
*/
void R_DrawTranslatedTranslucentColumn(drawcolumndata_t* dc)
{
register INT32 count;
register UINT8 *restrict dest;
intptr_t frac;
count = dc->yh - dc->yl + 1;
if (count <= 0) // Zero length, column does not exceed a pixel.
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
// Looks familiar.
const intptr_t fracstep = dc->iscale;
frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets.
intptr_t heightmask = dc->sourcelength-1;
static const INT32 npow2min = -1;
const INT32 npow2max = dc->sourcelength;
register const INT32 stride = vid.width;
if (dc->sourcelength & heightmask)
{
heightmask = dc->texheight << FRACBITS;
if (frac < 0)
{
while ((frac += heightmask) < 0)
{
;
}
}
else
{
while (frac >= heightmask)
{
frac -= heightmask;
}
}
do
{
// Re-map color indices from wall texture column
// using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
*dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[CLAMP(frac >> FRACBITS, npow2min, npow2max)]]]<<8) + (*dest));
dest += stride;
if ((frac += fracstep) >= heightmask)
{
frac -= heightmask;
}
}
while (--count);
}
else
{
while ((count -= 2) >= 0) // texture height is a power of 2
{
*dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest));
dest += stride;
frac += fracstep;
*dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest));
dest += stride;
frac += fracstep;
}
if (count & 1)
{
*dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest));
}
}
}
/** \brief The R_DrawTranslatedColumn function
Draw columns up to 128 high but remap the green ramp to other colors
\warning STILL NOT IN ASM, TO DO..
*/
void R_DrawTranslatedColumn(drawcolumndata_t* dc)
{
register INT32 count;
register UINT8 *dest;
register fixed_t frac;
count = dc->yh - dc->yl;
if (count < 0)
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
// Looks familiar.
const fixed_t fracstep = dc->iscale;
frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
register const INT32 stride = vid.width;
// Here we do an additional index re-mapping.
do
{
// Translation tables are used
// to map certain colorramps to other ones,
// used with PLAY sprites.
// Thus the "green" ramp of the player 0 sprite
// is mapped to gray, red, black/indigo.
*dest = dc->colormap[dc->translation[dc->source[frac>>FRACBITS]]];
dest += stride;
frac += fracstep;
} while (count--);
}
/** \brief The R_DrawFogColumn function
Fog wall.
*/
void R_DrawFogColumn(drawcolumndata_t* dc)
{
register INT32 count;
register UINT8 *dest;
count = dc->yh - dc->yl;
// Zero length, column does not exceed a pixel.
if (count < 0)
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
register const INT32 stride = vid.width;
// Determine scaling, which is the only mapping to be done.
do
{
// Simple. Apply the colormap to what's already on the screen.
*dest = dc->colormap[*dest];
dest += stride;
} while (count--);
}
/** \brief The R_DrawShadeColumn function
This is for 3D floors that cast shadows on walls.
This function just cuts the column up into sections and calls R_DrawColumn
*/
void R_DrawColumnShadowed(drawcolumndata_t* dc)
{
register INT32 count;
INT32 realyh, i, height, bheight = 0, solid = 0;
count = dc->yh - dc->yl;
// Zero length, column does not exceed a pixel.
if (count < 0)
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
realyh = dc->yh;
// This runs through the lightlist from top to bottom and cuts up the column accordingly.
for (i = 0; i < dc->numlights; i++)
{
// If the height of the light is above the column, get the colormap
// anyway because the lighting of the top should be affected.
solid = dc->lightlist[i].flags & FF_CUTSOLIDS;
height = dc->lightlist[i].height >> LIGHTSCALESHIFT;
if (solid)
{
bheight = dc->lightlist[i].botheight >> LIGHTSCALESHIFT;
if (bheight < height)
{
// confounded slopes sometimes allow partial invertedness,
// even including cases where the top and bottom heights
// should actually be the same!
// swap the height values as a workaround for this quirk
INT32 temp = height;
height = bheight;
bheight = temp;
}
}
if (height <= dc->yl)
{
dc->colormap = dc->lightlist[i].rcolormap;
if (encoremap)
dc->colormap += COLORMAP_REMAPOFFSET;
if (solid && dc->yl < bheight)
dc->yl = bheight;
continue;
}
// Found a break in the column!
dc->yh = height;
if (dc->yh > realyh)
dc->yh = realyh;
(colfuncs[BASEDRAWFUNC])(dc); // R_DrawColumn_8 for the appropriate architecture
if (solid)
dc->yl = bheight;
else
dc->yl = dc->yh + 1;
dc->colormap = dc->lightlist[i].rcolormap;
if (encoremap)
dc->colormap += COLORMAP_REMAPOFFSET;
}
dc->yh = realyh;
if (dc->yl <= realyh)
(colfuncs[BASEDRAWFUNC])(dc); // R_DrawWallColumn_8 for the appropriate architecture
}
+333
View File
@@ -0,0 +1,333 @@
// SONIC ROBO BLAST 2 KART
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by Kart Krew.
// Copyright (C) 2020 by Sonic Team Junior.
// Copyright (C) 2000 by DooM Legacy Team.
// Copyright (C) 1996 by id Software, Inc.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file r_draw_column.cpp
/// \brief column drawer functions
/// \note no includes because this is included as part of r_draw.cpp
// ==========================================================================
// COLUMNS
// ==========================================================================
// A column is a vertical slice/span of a wall texture that uses
// a has a constant z depth from top to bottom.
//
enum DrawColumnType
{
DC_BASIC = 0x0000,
DC_COLORMAP = 0x0001,
DC_TRANSMAP = 0x0002,
DC_HOLES = 0x0004,
DC_LIGHTLIST = 0x0008,
};
template<DrawColumnType Type>
static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 *colormap)
{
if constexpr (Type & DrawColumnType::DC_COLORMAP)
{
col = dc->translation[col];
}
return colormap[col];
}
template<DrawColumnType Type>
static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 *dest, UINT8 col, const UINT8 *colormap)
{
col = R_GetColumnTranslated<Type>(dc, col, colormap);
if constexpr (Type & DrawColumnType::DC_TRANSMAP)
{
return *(dc->transmap + (col << 8) + (*dest));
}
else
{
return col;
}
}
template<DrawColumnType Type>
static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 *dest, UINT32 bit, const UINT8 *source, const UINT8 *colormap)
{
UINT8 col = source[bit];
if constexpr (Type & DrawColumnType::DC_HOLES)
{
if (col == TRANSPARENTPIXEL)
{
return *dest;
}
}
return R_GetColumnTranslucent<Type>(dc, dest, col, colormap);
}
/** \brief The R_DrawColumn function
Experiment to make software go faster. Taken from the Boom source
*/
template<DrawColumnType Type>
static void R_DrawColumnTemplate(drawcolumndata_t *dc)
{
INT32 count;
count = dc->yh - dc->yl;
if (count < 0) // Zero length, column does not exceed a pixel.
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
if constexpr (Type & DrawColumnType::DC_LIGHTLIST)
{
constexpr DrawColumnType NewType = static_cast<DrawColumnType>(Type & ~DC_LIGHTLIST);
INT32 i, height, bheight = 0, solid = 0;
drawcolumndata_t dc_copy = *dc;
const INT32 realyh = dc_copy.yh;
// This runs through the lightlist from top to bottom and cuts up the column accordingly.
for (i = 0; i < dc_copy.numlights; i++)
{
// If the height of the light is above the column, get the colormap
// anyway because the lighting of the top should be affected.
solid = dc_copy.lightlist[i].flags & FF_CUTSOLIDS;
height = dc_copy.lightlist[i].height >> LIGHTSCALESHIFT;
if (solid)
{
bheight = dc_copy.lightlist[i].botheight >> LIGHTSCALESHIFT;
if (bheight < height)
{
// confounded slopes sometimes allow partial invertedness,
// even including cases where the top and bottom heights
// should actually be the same!
// swap the height values as a workaround for this quirk
INT32 temp = height;
height = bheight;
bheight = temp;
}
}
if (height <= dc_copy.yl)
{
dc_copy.colormap = dc_copy.lightlist[i].rcolormap;
if (encoremap)
{
dc_copy.colormap += COLORMAP_REMAPOFFSET;
}
if (solid && dc_copy.yl < bheight)
{
dc_copy.yl = bheight;
}
continue;
}
// Found a break in the column!
dc_copy.yh = height;
if (dc_copy.yh > realyh)
{
dc_copy.yh = realyh;
}
R_DrawColumnTemplate<NewType>(&dc_copy);
if (solid)
{
dc_copy.yl = bheight;
}
else
{
dc_copy.yl = dc_copy.yh + 1;
}
dc_copy.colormap = dc_copy.lightlist[i].rcolormap;
if (encoremap)
{
dc_copy.colormap += COLORMAP_REMAPOFFSET;
}
}
dc_copy.yh = realyh;
if (dc_copy.yl <= realyh)
{
R_DrawColumnTemplate<NewType>(&dc_copy);
}
}
else
{
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets.
fixed_t frac;
const intptr_t fracstep = dc->iscale;
intptr_t heightmask = dc->sourcelength-1;
static const INT32 npow2min = -1;
const INT32 npow2max = dc->sourcelength;
const INT32 stride = vid.width;
const UINT8 *source = dc->source;
const lighttable_t *colormap = dc->colormap;
// Framebuffer destination address.
UINT8 *dest = R_Address(dc->x, dc->yl);
count++;
// Determine scaling, which is the only mapping to be done.
frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
if (heightmask == -1)
{
if (frac < 0)
// adjust in case we underread
frac += FRACUNIT;
// texture has no height, so just go
while (--count > 0)
{
*dest = R_DrawColumnPixel<Type>(dc, dest, frac>>FRACBITS, source, colormap);
dest += stride;
frac += fracstep;
}
}
else if (dc->sourcelength & heightmask) // not a power of 2 -- killough
{
heightmask = dc->texheight << FRACBITS;
if (frac < 0)
{
while ((frac += heightmask) < 0)
{
;
}
}
else
{
while (frac >= heightmask)
{
frac -= heightmask;
}
}
do
{
// Re-map color indices from wall texture column
// using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
*dest = R_DrawColumnPixel<Type>(dc, dest, std::clamp((frac >> FRACBITS), npow2min, npow2max), source, colormap);
dest += stride;
#if __SIZEOF_POINTER__ < 8 // 64-bit systems have large enough numbers for this to be a non-issue
// Avoid overflow.
if (fracstep > 0x7FFFFFFF - frac)
{
frac += fracstep - heightmask;
}
else
#endif
{
frac += fracstep;
}
while (frac >= heightmask)
{
frac -= heightmask;
}
}
while (--count);
}
else
{
while ((count -= 2) >= 0) // texture height is a power of 2
{
*dest = R_DrawColumnPixel<Type>(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap);
dest += stride;
frac += fracstep;
*dest = R_DrawColumnPixel<Type>(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap);
dest += stride;
frac += fracstep;
}
if (count & 1)
{
*dest = R_DrawColumnPixel<Type>(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap);
}
}
}
}
#define DEFINE_COLUMN_FUNC(name, flags) \
void name(drawcolumndata_t *dc) \
{ \
constexpr DrawColumnType opt = static_cast<DrawColumnType>(flags); \
R_DrawColumnTemplate<opt>(dc); \
}
DEFINE_COLUMN_FUNC(R_DrawColumn, DC_BASIC)
DEFINE_COLUMN_FUNC(R_DrawTranslucentColumn, DC_TRANSMAP)
DEFINE_COLUMN_FUNC(R_DrawTranslatedColumn, DC_COLORMAP)
DEFINE_COLUMN_FUNC(R_DrawColumnShadowed, DC_LIGHTLIST)
DEFINE_COLUMN_FUNC(R_DrawTranslatedTranslucentColumn, DC_COLORMAP|DC_TRANSMAP)
DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchColumn, DC_HOLES)
DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_HOLES|DC_TRANSMAP)
/** \brief The R_DrawFogColumn function
Fog wall.
*/
void R_DrawFogColumn(drawcolumndata_t* dc)
{
INT32 count;
UINT8 *dest;
count = dc->yh - dc->yl;
// Zero length, column does not exceed a pixel.
if (count < 0)
{
return;
}
if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
{
return;
}
// Framebuffer destination address.
dest = R_Address(dc->x, dc->yl);
const INT32 stride = vid.width;
const lighttable_t *colormap = dc->colormap;
// Determine scaling, which is the only mapping to be done.
do
{
// Simple. Apply the colormap to what's already on the screen.
*dest = colormap[*dest];
dest += stride;
} while (count--);
}
-1234
View File
File diff suppressed because it is too large. Load diff
+446
View File
@@ -0,0 +1,446 @@
// SONIC ROBO BLAST 2 KART
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by Kart Krew.
// Copyright (C) 2020 by Sonic Team Junior.
// Copyright (C) 2000 by DooM Legacy Team.
// Copyright (C) 1996 by id Software, Inc.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file r_draw_span.cpp
/// \brief span drawer functions
/// \note no includes because this is included as part of r_draw.cpp
#ifdef HAVE_THREADS
#ifdef _WIN32
#include <windows.h>
#define local_for_thread static __thread
#else
#include <threads.h>
#define local_for_thread thread_local static
#endif
#else
#define local_for_thread static
#endif
// ==========================================================================
// SPANS
// ==========================================================================
#define SPANSIZE 16
#define INVSPAN 0.0625f
// <Callum> 4194303 = (2048x2048)-1 (2048x2048 is maximum flat size)
#define MAXFLATBYTES 4194303
#define PLANELIGHTFLOAT ((float)BASEVIDWIDTH * BASEVIDWIDTH / stride / ds->zeroheight / 21.0f * FIXED_TO_FLOAT(fovtan))
enum DrawSpanType
{
DS_BASIC = 0x0000,
DS_COLORMAP = 0x0001,
DS_TRANSMAP = 0x0002,
DS_HOLES = 0x0004,
DS_RIPPLE = 0x0008,
};
template<DrawSpanType Type>
static constexpr UINT8 R_GetSpanTranslucent(drawspandata_t* ds, UINT8 *dsrc, const UINT8 *colormap, UINT8 col)
{
col = colormap[col];
if constexpr (Type & DrawSpanType::DS_TRANSMAP)
{
return *(ds->transmap + (col << 8) + (*dsrc));
}
else
{
return col;
}
}
template<DrawSpanType Type>
static constexpr UINT8 R_DrawSpanPixel(drawspandata_t* ds, UINT8 *dsrc, const UINT8 *colormap, UINT32 bit, const UINT8 *source)
{
UINT8 col = source[bit];
if constexpr (Type & DrawSpanType::DS_HOLES)
{
if (col == TRANSPARENTPIXEL)
{
return *dsrc;
}
}
return R_GetSpanTranslucent<Type>(ds, dsrc, colormap, col);
}
/** \brief The R_DrawSpan_8 function
Draws the actual span.
*/
template<DrawSpanType Type>
static void R_DrawSpanTemplate(drawspandata_t* ds)
{
UINT32 xposition;
UINT32 yposition;
UINT32 xstep, ystep;
UINT32 bit;
UINT8 *dest = R_Address(ds->x1, ds->y);
UINT8 *dsrc;
const UINT8 *deststop = vid.screens[0] + vid.rowbytes * vid.height;
if (dest+8 > deststop)
{
return;
}
intptr_t count = (ds->x2 - ds->x1 + 1);
size_t i;
xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds->xstep; ystep = ds->ystep;
const UINT8 *source = ds->source;
const UINT8 *colormap = ds->colormap;
if constexpr (Type & DS_RIPPLE)
{
yposition += ds->waterofs;
}
// SoM: we only need 6 bits for the integer part (0 thru 63) so the rest
// can be used for the fraction part. This allows calculation of the memory address in the
// texture with two shifts, an OR and one AND. (see below)
// for texture sizes > 64 the amount of precision we can allow will decrease, but only by one
// bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit?
xposition <<= ds->nflatshiftup; yposition <<= ds->nflatshiftup;
xstep <<= ds->nflatshiftup; ystep <<= ds->nflatshiftup;
if constexpr (Type & DS_RIPPLE)
{
dsrc = vid.screens[1] + (ds->y + ds->bgofs) * vid.width + ds->x1;
}
else
{
dsrc = dest;
}
while (count >= 8)
{
// SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't
// have the uber complicated math to calculate it now, so that was a memory write we didn't
// need!
for (i = 0; i < 8; i++)
{
bit = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
dest[i] = R_DrawSpanPixel<Type>(ds, &dsrc[i], colormap, bit, source);
xposition += xstep;
yposition += ystep;
}
dest += 8;
dsrc += 8;
count -= 8;
}
while (count-- && dest <= deststop)
{
bit = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
*dest = R_DrawSpanPixel<Type>(ds, dsrc, colormap, bit, source);
dest++;
dsrc++;
xposition += xstep;
yposition += ystep;
}
}
// R_CalcTiltedLighting
// Exactly what it says on the tin. I wish I wasn't too lazy to explain things properly.
static void R_CalcTiltedLighting(INT32 *lightbuffer, INT32 x1, INT32 x2, fixed_t start, fixed_t end)
{
// ZDoom uses a different lighting setup to us, and I couldn't figure out how to adapt their version
// of this function. Here's my own.
INT32 i, left = x1, right = x2;
const fixed_t step = (end-start)/(x2 - x1 + 1);
// I wanna do some optimizing by checking for out-of-range segments on either side to fill in all at once,
// but I'm too bad at coding to not crash the game trying to do that. I guess this is fast enough for now...
for (i = left; i <= right; i++)
{
lightbuffer[i] = (start += step) >> FRACBITS;
if (lightbuffer[i] < 0)
{
lightbuffer[i] = 0;
}
else if (lightbuffer[i] >= MAXLIGHTSCALE)
{
lightbuffer[i] = MAXLIGHTSCALE-1;
}
}
}
template<DrawSpanType Type>
static void R_DrawTiltedSpanTemplate(drawspandata_t* ds)
{
int width = ds->x2 - ds->x1;
float iz, uz, vz;
UINT32 u, v;
int i;
UINT8 *dest = R_Address(ds->x1, ds->y);
UINT8 *dsrc;
float startz, startu, startv;
float izstep, uzstep, vzstep;
float endz, endu, endv;
UINT32 stepu, stepv;
UINT32 bit;
local_for_thread INT32 *tiltlighting = NULL;
local_for_thread INT32 oldviewwidth = 0;
// dont realloc every frame pls thx
if (tiltlighting == NULL || oldviewwidth != viewwidth)
{
tiltlighting = static_cast<INT32*>(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth));
oldviewwidth = viewwidth;
}
INT32 x1 = ds->x1;
const INT32 nflatxshift = ds->nflatxshift;
const INT32 nflatyshift = ds->nflatyshift;
const INT32 nflatmask = ds->nflatmask;
const INT32 stride = vid.width;
iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds->szp.x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(tiltlighting, ds->x1, ds->x2, FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds->sup.z + ds->sup.y*(centery-ds->y) + ds->sup.x*(ds->x1-centerx);
vz = ds->svp.z + ds->svp.y*(centery-ds->y) + ds->svp.x*(ds->x1-centerx);
const UINT8 *source = ds->source;
const UINT8 *colormap = ds->colormap;
if constexpr (Type & DS_RIPPLE)
{
dsrc = vid.screens[1] + (ds->y + ds->bgofs) * stride + ds->x1;
}
else
{
dsrc = dest;
}
#if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look.
i = 0;
do
{
double z = 1.f/iz;
u = (INT64)(uz*z);
v = (INT64)(vz*z);
bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift);
colormap = planezlight[tiltlighting[ds->x1]] + (ds->colormap - colormaps);
*dest = R_DrawSpanPixel<Type>(ds, dsrc, colormap, bit);
dest++;
ds->x1++;
dsrc++;
iz += ds_szp->x;
uz += ds_sup->x;
vz += ds_svp->x;
} while (--width >= 0);
#else
startz = 1.f/iz;
startu = uz*startz;
startv = vz*startz;
izstep = ds->szp.x * SPANSIZE;
uzstep = ds->sup.x * SPANSIZE;
vzstep = ds->svp.x * SPANSIZE;
//x1 = 0;
width++;
while (width >= SPANSIZE)
{
iz += izstep;
uz += uzstep;
vz += vzstep;
endz = 1.f/iz;
endu = uz*endz;
endv = vz*endz;
stepu = (INT64)((endu - startu) * INVSPAN);
stepv = (INT64)((endv - startv) * INVSPAN);
u = (INT64)(startu);
v = (INT64)(startv);
x1 = ds->x1;
for (i = 0; i < SPANSIZE; i++)
{
bit = (((v + stepv * i) >> nflatyshift) & nflatmask) | ((u + stepu * i) >> nflatxshift);
colormap = ds->planezlight[tiltlighting[x1 + i]] + (ds->colormap - colormaps);
dest[i] = R_DrawSpanPixel<Type>(ds, &dsrc[i], colormap, bit, source);
}
ds->x1 += SPANSIZE;
dest += SPANSIZE;
dsrc += SPANSIZE;
startu = endu;
startv = endv;
width -= SPANSIZE;
}
if (width > 0)
{
if (width == 1)
{
u = (INT64)(startu);
v = (INT64)(startv);
bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift);
colormap = ds->planezlight[tiltlighting[ds->x1]] + (ds->colormap - colormaps);
*dest = R_DrawSpanPixel<Type>(ds, dsrc, colormap, bit, source);
ds->x1++;
}
else
{
double left = width;
iz += ds->szp.x * left;
uz += ds->sup.x * left;
vz += ds->svp.x * left;
endz = 1.f/iz;
endu = uz*endz;
endv = vz*endz;
left = 1.f/left;
stepu = (INT64)((endu - startu) * left);
stepv = (INT64)((endv - startv) * left);
u = (INT64)(startu);
v = (INT64)(startv);
for (; width != 0; width--)
{
bit = ((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift);
colormap = ds->planezlight[tiltlighting[ds->x1]] + (ds->colormap - colormaps);
*dest = R_DrawSpanPixel<Type>(ds, dsrc, colormap, bit, source);
dest++;
ds->x1++;
dsrc++;
u += stepu;
v += stepv;
}
}
}
#endif
}
#define DEFINE_SPAN_FUNC(name, flags, template) \
void name(drawspandata_t* ds) \
{ \
constexpr DrawSpanType opt = static_cast<DrawSpanType>(flags); \
template<opt>(ds); \
}
#define DEFINE_SPAN_COMBO(name, flags) \
DEFINE_SPAN_FUNC(name, flags, R_DrawSpanTemplate) \
DEFINE_SPAN_FUNC(name ## _Tilted, flags, R_DrawTiltedSpanTemplate) \
DEFINE_SPAN_COMBO(R_DrawSpan, DS_BASIC)
DEFINE_SPAN_COMBO(R_DrawTranslucentSpan, DS_TRANSMAP)
DEFINE_SPAN_COMBO(R_DrawSplat, DS_HOLES)
DEFINE_SPAN_COMBO(R_DrawTranslucentSplat, DS_TRANSMAP|DS_HOLES)
DEFINE_SPAN_COMBO(R_DrawTranslucentWaterSpan, DS_TRANSMAP|DS_RIPPLE)
/** \brief The R_DrawFogSpan function
Draws the actual span with fogging.
*/
void R_DrawFogSpan(drawspandata_t* ds)
{
const UINT8 *colormap = ds->colormap;
UINT8 *dest = R_Address(ds->x1, ds->y);
intptr_t count = ds->x2 - ds->x1 + 1;
while (count >= 4)
{
dest[0] = colormap[dest[0]];
dest[1] = colormap[dest[1]];
dest[2] = colormap[dest[2]];
dest[3] = colormap[dest[3]];
dest += 4;
count -= 4;
}
while (count--)
{
*dest = colormap[*dest];
dest++;
}
}
void R_DrawFogSpan_Tilted(drawspandata_t* ds)
{
int width = ds->x2 - ds->x1;
float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx);
UINT8 *dest;
local_for_thread INT32 *tiltlighting = NULL;
local_for_thread INT32 oldviewwidth = 0;
// dont realloc every frame pls thx
if (tiltlighting == NULL || oldviewwidth != viewwidth)
{
tiltlighting = static_cast<INT32*>(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth));
oldviewwidth = viewwidth;
}
dest = R_Address(ds->x1, ds->y);
const INT32 stride = vid.width;
// Lighting is simple. It's just linear interpolation from start to end
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds->szp.x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(tiltlighting, ds->x1, ds->x2, FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
do
{
UINT8 *colormap = ds->planezlight[tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = colormap[*dest];
dest++;
}
while (--width >= 0);
}
+3
View File
@@ -1272,6 +1272,9 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle
case SPANDRAWFUNC_SPLAT:
spanfunctype = SPANDRAWFUNC_TILTEDSPLAT;
break;
case SPANDRAWFUNC_TRANSSPLAT:
spanfunctype = SPANDRAWFUNC_TILTEDTRANSSPLAT;
break;
case SPANDRAWFUNC_FOG:
spanfunctype = SPANDRAWFUNC_TILTEDFOG;
break;
+1
View File
@@ -91,6 +91,7 @@ static void SCR_SetDrawFuncs(void)
spanfuncs[SPANDRAWFUNC_SPLAT] = R_DrawSplat;
spanfuncs[SPANDRAWFUNC_TRANSSPLAT] = R_DrawTranslucentSplat;
spanfuncs[SPANDRAWFUNC_TILTEDSPLAT] = R_DrawSplat_Tilted;
spanfuncs[SPANDRAWFUNC_TILTEDTRANSSPLAT] = R_DrawTranslucentSpan_Tilted;
spanfuncs[SPANDRAWFUNC_WATER] = R_DrawTranslucentWaterSpan;
spanfuncs[SPANDRAWFUNC_TILTEDWATER] = R_DrawTranslucentWaterSpan_Tilted;
spanfuncs[SPANDRAWFUNC_FOG] = R_DrawFogSpan;