Clean up + optimize Software Plane Drawers, move Water drawers where they belong + Add support for tilted water #89
No files matched your search
@@ -5945,8 +5945,8 @@ static void HWR_PortalClipping(gl_portal_t *portal)
|
||||
|
||||
line_t *line = &lines[portal->clipline];
|
||||
|
||||
angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y);
|
||||
angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y);
|
||||
angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y);
|
||||
angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y);
|
||||
|
||||
// clip things that are not inside the portal window from our viewpoint
|
||||
gld_clipper_SafeAddClipRange(angle2, angle1);
|
||||
|
||||
+4
-3
@@ -110,11 +110,12 @@ INT32 ds_y, ds_x1, ds_x2;
|
||||
lighttable_t *ds_colormap;
|
||||
fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep;
|
||||
|
||||
UINT8 *ds_source; // start of a 64*64 tile image
|
||||
UINT8 *ds_source; // points to the start of a flat
|
||||
UINT8 *ds_transmap; // one of the translucency tables
|
||||
|
||||
pslope_t *ds_slope; // Current slope being used
|
||||
floatv3_t ds_su, ds_sv, ds_sz; // Vectors for... stuff?
|
||||
// Vectors for Software's tilted slope drawers
|
||||
floatv3_t *ds_su, *ds_sv, *ds_sz;
|
||||
floatv3_t *ds_sup, *ds_svp, *ds_szp;
|
||||
float focallengthf, zeroheight;
|
||||
|
||||
/** \brief Variable flat sizes
|
||||
|
||||
+6
-2
@@ -60,6 +60,7 @@ extern INT32 dc_texheight;
|
||||
extern INT32 ds_y, ds_x1, ds_x2;
|
||||
extern lighttable_t *ds_colormap;
|
||||
extern fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep;
|
||||
extern INT32 ds_waterofs, ds_bgofs;
|
||||
extern UINT8 *ds_source; // start of a 64*64 tile image
|
||||
extern UINT8 *ds_transmap;
|
||||
|
||||
@@ -69,8 +70,9 @@ typedef struct {
|
||||
float x, y, z;
|
||||
} floatv3_t;
|
||||
|
||||
extern pslope_t *ds_slope; // Current slope being used
|
||||
extern floatv3_t ds_su, ds_sv, ds_sz; // Vectors for... stuff?
|
||||
// Vectors for Software's tilted slope drawers
|
||||
extern floatv3_t *ds_su, *ds_sv, *ds_sz;
|
||||
extern floatv3_t *ds_sup, *ds_svp, *ds_szp;
|
||||
extern float focallengthf, zeroheight;
|
||||
|
||||
// Variable flat sizes
|
||||
@@ -153,10 +155,12 @@ void R_DrawSpan_8(void);
|
||||
void R_CalcTiltedLighting(fixed_t start, fixed_t end);
|
||||
void R_DrawTiltedSpan_8(void);
|
||||
void R_DrawTiltedTranslucentSpan_8(void);
|
||||
void R_DrawTiltedTranslucentWaterSpan_8(void);
|
||||
void R_DrawTiltedSplat_8(void);
|
||||
void R_DrawSplat_8(void);
|
||||
void R_DrawTranslucentSplat_8(void);
|
||||
void R_DrawTranslucentSpan_8(void);
|
||||
void R_DrawTranslucentWaterSpan_8(void);
|
||||
void R_Draw2sMultiPatchColumn_8(void);
|
||||
void R_Draw2sMultiPatchTranslucentColumn_8(void);
|
||||
void R_DrawFogSpan_8(void);
|
||||
|
||||
+254
-40
@@ -644,7 +644,7 @@ void R_CalcTiltedLighting(fixed_t start, fixed_t end)
|
||||
}
|
||||
}
|
||||
|
||||
#define PLANELIGHTFLOAT (BASEVIDWIDTH * BASEVIDWIDTH / vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f * FIXED_TO_FLOAT(fovtan))
|
||||
#define PLANELIGHTFLOAT (BASEVIDWIDTH * BASEVIDWIDTH / vid.width / zeroheight / 21.0f * FIXED_TO_FLOAT(fovtan))
|
||||
|
||||
/** \brief The R_DrawTiltedSpan_8 function
|
||||
Draw slopes! Holy sheit!
|
||||
@@ -666,22 +666,22 @@ void R_DrawTiltedSpan_8(void)
|
||||
double endz, endu, endv;
|
||||
UINT32 stepu, stepv;
|
||||
|
||||
iz = ds_sz.z + ds_sz.y*(centery-ds_y) + ds_sz.x*(ds_x1-centerx);
|
||||
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_sz.x*width) * planelightfloat;
|
||||
lightend = (iz + ds_szp->x*width) * planelightfloat;
|
||||
lightstart = iz * planelightfloat;
|
||||
|
||||
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
|
||||
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
|
||||
}
|
||||
|
||||
uz = ds_su.z + ds_su.y*(centery-ds_y) + ds_su.x*(ds_x1-centerx);
|
||||
vz = ds_sv.z + ds_sv.y*(centery-ds_y) + ds_sv.x*(ds_x1-centerx);
|
||||
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);
|
||||
|
||||
dest = ylookup[ds_y] + columnofs[ds_x1];
|
||||
source = ds_source;
|
||||
@@ -700,9 +700,9 @@ void R_DrawTiltedSpan_8(void)
|
||||
|
||||
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]];
|
||||
dest++;
|
||||
iz += ds_sz.x;
|
||||
uz += ds_su.x;
|
||||
vz += ds_sv.x;
|
||||
iz += ds_szp->x;
|
||||
uz += ds_sup->x;
|
||||
vz += ds_svp->x;
|
||||
} while (--width >= 0);
|
||||
#else
|
||||
#define SPANSIZE 16
|
||||
@@ -712,9 +712,9 @@ void R_DrawTiltedSpan_8(void)
|
||||
startu = uz*startz;
|
||||
startv = vz*startz;
|
||||
|
||||
izstep = ds_sz.x * SPANSIZE;
|
||||
uzstep = ds_su.x * SPANSIZE;
|
||||
vzstep = ds_sv.x * SPANSIZE;
|
||||
izstep = ds_szp->x * SPANSIZE;
|
||||
uzstep = ds_sup->x * SPANSIZE;
|
||||
vzstep = ds_svp->x * SPANSIZE;
|
||||
//x1 = 0;
|
||||
width++;
|
||||
|
||||
@@ -756,9 +756,9 @@ void R_DrawTiltedSpan_8(void)
|
||||
else
|
||||
{
|
||||
double left = width;
|
||||
iz += ds_sz.x * left;
|
||||
uz += ds_su.x * left;
|
||||
vz += ds_sv.x * left;
|
||||
iz += ds_szp->x * left;
|
||||
uz += ds_sup->x * left;
|
||||
vz += ds_svp->x * left;
|
||||
|
||||
endz = 1.f/iz;
|
||||
endu = uz*endz;
|
||||
@@ -802,22 +802,22 @@ void R_DrawTiltedTranslucentSpan_8(void)
|
||||
double endz, endu, endv;
|
||||
UINT32 stepu, stepv;
|
||||
|
||||
iz = ds_sz.z + ds_sz.y*(centery-ds_y) + ds_sz.x*(ds_x1-centerx);
|
||||
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_sz.x*width) * planelightfloat;
|
||||
lightend = (iz + ds_szp->x*width) * planelightfloat;
|
||||
lightstart = iz * planelightfloat;
|
||||
|
||||
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
|
||||
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
|
||||
}
|
||||
|
||||
uz = ds_su.z + ds_su.y*(centery-ds_y) + ds_su.x*(ds_x1-centerx);
|
||||
vz = ds_sv.z + ds_sv.y*(centery-ds_y) + ds_sv.x*(ds_x1-centerx);
|
||||
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);
|
||||
|
||||
dest = ylookup[ds_y] + columnofs[ds_x1];
|
||||
source = ds_source;
|
||||
@@ -835,9 +835,9 @@ void R_DrawTiltedTranslucentSpan_8(void)
|
||||
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
|
||||
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest);
|
||||
dest++;
|
||||
iz += ds_sz.x;
|
||||
uz += ds_su.x;
|
||||
vz += ds_sv.x;
|
||||
iz += ds_szp->x;
|
||||
uz += ds_sup->x;
|
||||
vz += ds_svp->x;
|
||||
} while (--width >= 0);
|
||||
#else
|
||||
#define SPANSIZE 16
|
||||
@@ -847,9 +847,9 @@ void R_DrawTiltedTranslucentSpan_8(void)
|
||||
startu = uz*startz;
|
||||
startv = vz*startz;
|
||||
|
||||
izstep = ds_sz.x * SPANSIZE;
|
||||
uzstep = ds_su.x * SPANSIZE;
|
||||
vzstep = ds_sv.x * SPANSIZE;
|
||||
izstep = ds_szp->x * SPANSIZE;
|
||||
uzstep = ds_sup->x * SPANSIZE;
|
||||
vzstep = ds_svp->x * SPANSIZE;
|
||||
//x1 = 0;
|
||||
width++;
|
||||
|
||||
@@ -891,9 +891,9 @@ void R_DrawTiltedTranslucentSpan_8(void)
|
||||
else
|
||||
{
|
||||
double left = width;
|
||||
iz += ds_sz.x * left;
|
||||
uz += ds_su.x * left;
|
||||
vz += ds_sv.x * left;
|
||||
iz += ds_szp->x * left;
|
||||
uz += ds_sup->x * left;
|
||||
vz += ds_svp->x * left;
|
||||
|
||||
endz = 1.f/iz;
|
||||
endu = uz*endz;
|
||||
@@ -917,6 +917,143 @@ void R_DrawTiltedTranslucentSpan_8(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \brief The R_DrawTiltedTranslucentWaterSpan_8 function
|
||||
Like DrawTiltedTranslucentSpan, but for water
|
||||
*/
|
||||
void R_DrawTiltedTranslucentWaterSpan_8(void)
|
||||
{
|
||||
// x1, x2 = ds_x1, ds_x2
|
||||
int width = ds_x2 - ds_x1;
|
||||
double iz, uz, vz;
|
||||
UINT32 u, v;
|
||||
int i;
|
||||
|
||||
UINT8 *source;
|
||||
UINT8 *colormap;
|
||||
UINT8 *dest;
|
||||
UINT8 *dsrc;
|
||||
|
||||
double startz, startu, startv;
|
||||
double izstep, uzstep, vzstep;
|
||||
double endz, endu, endv;
|
||||
UINT32 stepu, stepv;
|
||||
|
||||
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 = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f;
|
||||
float lightstart, lightend;
|
||||
|
||||
lightend = (iz + ds_szp->x*width) * planelightfloat;
|
||||
lightstart = iz * planelightfloat;
|
||||
|
||||
R_CalcTiltedLighting(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);
|
||||
|
||||
dest = ylookup[ds_y] + columnofs[ds_x1];
|
||||
dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1;
|
||||
source = ds_source;
|
||||
//colormap = ds_colormap;
|
||||
|
||||
#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) + viewx;
|
||||
v = (INT64)(vz*z) + viewy;
|
||||
|
||||
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
|
||||
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++);
|
||||
dest++;
|
||||
iz += ds_szp->x;
|
||||
uz += ds_sup->x;
|
||||
vz += ds_svp->x;
|
||||
} while (--width >= 0);
|
||||
#else
|
||||
#define SPANSIZE 16
|
||||
#define INVSPAN 0.0625f
|
||||
|
||||
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) + viewx;
|
||||
v = (INT64)(startv) + viewy;
|
||||
|
||||
for (i = SPANSIZE-1; i >= 0; i--)
|
||||
{
|
||||
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
|
||||
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++);
|
||||
dest++;
|
||||
u += stepu;
|
||||
v += stepv;
|
||||
}
|
||||
startu = endu;
|
||||
startv = endv;
|
||||
width -= SPANSIZE;
|
||||
}
|
||||
if (width > 0)
|
||||
{
|
||||
if (width == 1)
|
||||
{
|
||||
u = (INT64)(startu);
|
||||
v = (INT64)(startv);
|
||||
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
|
||||
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++);
|
||||
}
|
||||
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) + viewx;
|
||||
v = (INT64)(startv) + viewy;
|
||||
|
||||
for (; width != 0; width--)
|
||||
{
|
||||
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps);
|
||||
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++);
|
||||
dest++;
|
||||
u += stepu;
|
||||
v += stepv;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void R_DrawTiltedSplat_8(void)
|
||||
{
|
||||
// x1, x2 = ds_x1, ds_x2
|
||||
@@ -936,22 +1073,22 @@ void R_DrawTiltedSplat_8(void)
|
||||
double endz, endu, endv;
|
||||
UINT32 stepu, stepv;
|
||||
|
||||
iz = ds_sz.z + ds_sz.y*(centery-ds_y) + ds_sz.x*(ds_x1-centerx);
|
||||
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_sz.x*width) * planelightfloat;
|
||||
lightend = (iz + ds_szp->x*width) * planelightfloat;
|
||||
lightstart = iz * planelightfloat;
|
||||
|
||||
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
|
||||
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
|
||||
}
|
||||
|
||||
uz = ds_su.z + ds_su.y*(centery-ds_y) + ds_su.x*(ds_x1-centerx);
|
||||
vz = ds_sv.z + ds_sv.y*(centery-ds_y) + ds_sv.x*(ds_x1-centerx);
|
||||
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);
|
||||
|
||||
dest = ylookup[ds_y] + columnofs[ds_x1];
|
||||
source = ds_source;
|
||||
@@ -972,9 +1109,9 @@ void R_DrawTiltedSplat_8(void)
|
||||
if (val != TRANSPARENTPIXEL)
|
||||
*dest = colormap[val];
|
||||
dest++;
|
||||
iz += ds_sz.x;
|
||||
uz += ds_su.x;
|
||||
vz += ds_sv.x;
|
||||
iz += ds_szp->x;
|
||||
uz += ds_sup->x;
|
||||
vz += ds_svp->x;
|
||||
} while (--width >= 0);
|
||||
#else
|
||||
#define SPANSIZE 16
|
||||
@@ -984,9 +1121,9 @@ void R_DrawTiltedSplat_8(void)
|
||||
startu = uz*startz;
|
||||
startv = vz*startz;
|
||||
|
||||
izstep = ds_sz.x * SPANSIZE;
|
||||
uzstep = ds_su.x * SPANSIZE;
|
||||
vzstep = ds_sv.x * SPANSIZE;
|
||||
izstep = ds_szp->x * SPANSIZE;
|
||||
uzstep = ds_sup->x * SPANSIZE;
|
||||
vzstep = ds_svp->x * SPANSIZE;
|
||||
//x1 = 0;
|
||||
width++;
|
||||
|
||||
@@ -1032,9 +1169,9 @@ void R_DrawTiltedSplat_8(void)
|
||||
else
|
||||
{
|
||||
double left = width;
|
||||
iz += ds_sz.x * left;
|
||||
uz += ds_su.x * left;
|
||||
vz += ds_sv.x * left;
|
||||
iz += ds_szp->x * left;
|
||||
uz += ds_sup->x * left;
|
||||
vz += ds_svp->x * left;
|
||||
|
||||
endz = 1.f/iz;
|
||||
endu = uz*endz;
|
||||
@@ -1362,6 +1499,83 @@ void R_DrawTranslucentSpan_8 (void)
|
||||
}
|
||||
}
|
||||
|
||||
void R_DrawTranslucentWaterSpan_8(void)
|
||||
{
|
||||
UINT32 xposition;
|
||||
UINT32 yposition;
|
||||
UINT32 xstep, ystep;
|
||||
|
||||
UINT8 *source;
|
||||
UINT8 *colormap;
|
||||
UINT8 *dest;
|
||||
UINT8 *dsrc;
|
||||
|
||||
size_t count;
|
||||
|
||||
// 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_xfrac << nflatshiftup; yposition = (ds_yfrac + ds_waterofs) << nflatshiftup;
|
||||
xstep = ds_xstep << nflatshiftup; ystep = ds_ystep << nflatshiftup;
|
||||
|
||||
source = ds_source;
|
||||
colormap = ds_colormap;
|
||||
dest = ylookup[ds_y] + columnofs[ds_x1];
|
||||
dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1;
|
||||
count = ds_x2 - ds_x1 + 1;
|
||||
|
||||
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!
|
||||
dest[0] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[1] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[2] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[3] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[4] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[5] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[6] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[7] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest += 8;
|
||||
count -= 8;
|
||||
}
|
||||
while (count--)
|
||||
{
|
||||
*dest++ = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief The R_DrawFogSpan_8 function
|
||||
Draws the actual span with fogging.
|
||||
*/
|
||||
|
||||
@@ -1060,6 +1060,16 @@ void R_ExecuteSetViewSize(void)
|
||||
dy = FixedMul(abs(dy), fovtan);
|
||||
yslopetab[i] = FixedDiv(centerx*FRACUNIT, dy);
|
||||
}
|
||||
|
||||
if (ds_su)
|
||||
Z_Free(ds_su);
|
||||
if (ds_sv)
|
||||
Z_Free(ds_sv);
|
||||
if (ds_sz)
|
||||
Z_Free(ds_sz);
|
||||
|
||||
ds_su = ds_sv = ds_sz = NULL;
|
||||
ds_sup = ds_svp = ds_szp = NULL;
|
||||
}
|
||||
|
||||
memset(scalelight, 0xFF, sizeof(scalelight));
|
||||
|
||||
+336
-275
@@ -102,6 +102,7 @@ fixed_t cachedxstep[MAXVIDHEIGHT];
|
||||
fixed_t cachedystep[MAXVIDHEIGHT];
|
||||
|
||||
static fixed_t xoffs, yoffs;
|
||||
static floatv3_t ds_slope_origin, ds_slope_u, ds_slope_v;
|
||||
|
||||
//
|
||||
// R_InitPlanes
|
||||
@@ -156,6 +157,44 @@ void R_PortalRestoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Water ripple effect!!
|
||||
// Needs the height of the plane, and the vertical position of the span.
|
||||
// Sets planeripple.xfrac and planeripple.yfrac, added to ds_xfrac and ds_yfrac, if the span is not tilted.
|
||||
//
|
||||
|
||||
INT32 ds_bgofs;
|
||||
INT32 ds_waterofs;
|
||||
|
||||
struct
|
||||
{
|
||||
INT32 offset;
|
||||
fixed_t xfrac, yfrac;
|
||||
boolean active;
|
||||
} planeripple;
|
||||
|
||||
// ripples da water texture
|
||||
static fixed_t R_CalculateRippleOffset(INT32 y)
|
||||
{
|
||||
fixed_t distance = FixedMul(planeheight, yslope[y]);
|
||||
const INT32 yay = (planeripple.offset + (distance>>9)) & 8191;
|
||||
return FixedDiv(FINESINE(yay), (1<<12) + (distance>>11));
|
||||
}
|
||||
|
||||
static void R_CalculatePlaneRipple(angle_t angle)
|
||||
{
|
||||
angle >>= ANGLETOFINESHIFT;
|
||||
angle = (angle + 2048) & 8191; // 90 degrees
|
||||
planeripple.xfrac = FixedMul(FINECOSINE(angle), ds_bgofs);
|
||||
planeripple.yfrac = FixedMul(FINESINE(angle), ds_bgofs);
|
||||
}
|
||||
|
||||
static void R_UpdatePlaneRipple(void)
|
||||
{
|
||||
ds_waterofs = (leveltime & 1)*16384;
|
||||
planeripple.offset = ((leveltime-1)*140) + ((rendertimefrac*140) / FRACUNIT);
|
||||
}
|
||||
|
||||
//
|
||||
// R_MapPlane
|
||||
//
|
||||
@@ -168,97 +207,10 @@ void R_PortalRestoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor
|
||||
// viewsin
|
||||
// viewcos
|
||||
// viewheight
|
||||
|
||||
#ifndef NOWATER
|
||||
INT32 ds_bgofs;
|
||||
static INT32 wtofs=0;
|
||||
static INT32 waterofs;
|
||||
static boolean itswater;
|
||||
#endif
|
||||
|
||||
#ifndef NOWATER
|
||||
static void R_DrawTranslucentWaterSpan_8(void)
|
||||
{
|
||||
UINT32 xposition;
|
||||
UINT32 yposition;
|
||||
UINT32 xstep, ystep;
|
||||
|
||||
UINT8 *source;
|
||||
UINT8 *colormap;
|
||||
UINT8 *dest;
|
||||
UINT8 *dsrc;
|
||||
|
||||
size_t count;
|
||||
|
||||
// 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_xfrac << nflatshiftup; yposition = (ds_yfrac + waterofs) << nflatshiftup;
|
||||
xstep = ds_xstep << nflatshiftup; ystep = ds_ystep << nflatshiftup;
|
||||
|
||||
source = ds_source;
|
||||
colormap = ds_colormap;
|
||||
dest = ylookup[ds_y] + columnofs[ds_x1];
|
||||
dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1;
|
||||
count = ds_x2 - ds_x1 + 1;
|
||||
|
||||
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!
|
||||
dest[0] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[1] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[2] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[3] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[4] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[5] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[6] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest[7] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
|
||||
dest += 8;
|
||||
count -= 8;
|
||||
}
|
||||
while (count--)
|
||||
{
|
||||
*dest++ = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)];
|
||||
xposition += xstep;
|
||||
yposition += ystep;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
|
||||
static void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
|
||||
{
|
||||
angle_t angle, planecos, planesin;
|
||||
fixed_t distance, span;
|
||||
fixed_t distance = 0, span;
|
||||
size_t pindex;
|
||||
|
||||
#ifdef RANGECHECK
|
||||
@@ -266,8 +218,8 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
|
||||
I_Error("R_MapPlane: %d, %d at %d", x1, x2, y);
|
||||
#endif
|
||||
|
||||
// from r_splats's R_RenderFloorSplat
|
||||
if (x1 >= vid.width) x1 = vid.width - 1;
|
||||
if (x1 >= vid.width)
|
||||
x1 = vid.width - 1;
|
||||
|
||||
angle = (currentplane->viewangle + currentplane->plangle)>>ANGLETOFINESHIFT;
|
||||
planecos = FINECOSINE(angle);
|
||||
@@ -276,15 +228,22 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
|
||||
if (planeheight != cachedheight[y])
|
||||
{
|
||||
cachedheight[y] = planeheight;
|
||||
distance = cacheddistance[y] = FixedMul(planeheight, yslope[y]);
|
||||
ds_xstep = cachedxstep[y] = FixedMul(distance, basexscale);
|
||||
ds_ystep = cachedystep[y] = FixedMul(distance, baseyscale);
|
||||
cacheddistance[y] = distance = FixedMul(planeheight, yslope[y]);
|
||||
span = abs(centery - y);
|
||||
|
||||
if ((span = abs(centery-y)))
|
||||
if (span) // don't divide by zero
|
||||
{
|
||||
ds_xstep = cachedxstep[y] = FixedMul(planesin, planeheight) / span;
|
||||
ds_ystep = cachedystep[y] = FixedMul(planecos, planeheight) / span;
|
||||
ds_xstep = FixedMul(planesin, planeheight) / span;
|
||||
ds_ystep = FixedMul(planecos, planeheight) / span;
|
||||
}
|
||||
else
|
||||
{
|
||||
ds_xstep = FixedMul(distance, basexscale);
|
||||
ds_ystep = FixedMul(distance, baseyscale);
|
||||
}
|
||||
|
||||
cachedxstep[y] = ds_xstep;
|
||||
cachedystep[y] = ds_ystep;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -296,33 +255,29 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
|
||||
ds_xfrac = xoffs + FixedMul(planecos, distance) + (x1 - centerx) * ds_xstep;
|
||||
ds_yfrac = yoffs - FixedMul(planesin, distance) + (x1 - centerx) * ds_ystep;
|
||||
|
||||
#ifndef NOWATER
|
||||
if (itswater)
|
||||
// Water ripple effect
|
||||
if (planeripple.active)
|
||||
{
|
||||
const INT32 yay = (wtofs + (distance>>9) ) & 8191;
|
||||
// ripples da water texture
|
||||
ds_bgofs = FixedDiv(FINESINE(yay), (1<<12) + (distance>>11))>>FRACBITS;
|
||||
angle = (currentplane->viewangle + currentplane->plangle + xtoviewangle[x1])>>ANGLETOFINESHIFT;
|
||||
ds_bgofs = R_CalculateRippleOffset(y);
|
||||
|
||||
angle = (angle + 2048) & 8191; // 90 degrees
|
||||
ds_xfrac += FixedMul(FINECOSINE(angle), (ds_bgofs<<FRACBITS));
|
||||
ds_yfrac += FixedMul(FINESINE(angle), (ds_bgofs<<FRACBITS));
|
||||
R_CalculatePlaneRipple(currentplane->viewangle + currentplane->plangle);
|
||||
|
||||
if (y+ds_bgofs>=viewheight)
|
||||
ds_xfrac += planeripple.xfrac;
|
||||
ds_yfrac += planeripple.yfrac;
|
||||
ds_bgofs >>= FRACBITS;
|
||||
|
||||
if ((y + ds_bgofs) >= viewheight)
|
||||
ds_bgofs = viewheight-y-1;
|
||||
if (y+ds_bgofs<0)
|
||||
if ((y + ds_bgofs) < 0)
|
||||
ds_bgofs = -y;
|
||||
}
|
||||
#endif
|
||||
|
||||
pindex = distance >> LIGHTZSHIFT;
|
||||
if (pindex >= MAXLIGHTZ)
|
||||
pindex = MAXLIGHTZ - 1;
|
||||
|
||||
if (currentplane->slope)
|
||||
ds_colormap = colormaps;
|
||||
else
|
||||
ds_colormap = planezlight[pindex];
|
||||
|
||||
if (encoremap && !currentplane->noencore)
|
||||
ds_colormap += (256*32);
|
||||
|
||||
@@ -336,6 +291,48 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
|
||||
spanfunc();
|
||||
}
|
||||
|
||||
static void R_MapTiltedPlane(INT32 y, INT32 x1, INT32 x2)
|
||||
{
|
||||
#ifdef RANGECHECK
|
||||
if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y > viewheight)
|
||||
I_Error("R_MapTiltedPlane: %d, %d at %d", x1, x2, y);
|
||||
#endif
|
||||
|
||||
if (x1 >= vid.width)
|
||||
x1 = vid.width - 1;
|
||||
|
||||
// Water ripple effect
|
||||
if (planeripple.active)
|
||||
{
|
||||
ds_bgofs = R_CalculateRippleOffset(y);
|
||||
|
||||
ds_sup = &ds_su[y];
|
||||
ds_svp = &ds_sv[y];
|
||||
ds_szp = &ds_sz[y];
|
||||
|
||||
ds_bgofs >>= FRACBITS;
|
||||
|
||||
if ((y + ds_bgofs) >= viewheight)
|
||||
ds_bgofs = viewheight-y-1;
|
||||
if ((y + ds_bgofs) < 0)
|
||||
ds_bgofs = -y;
|
||||
}
|
||||
|
||||
if (encoremap && !currentplane->noencore)
|
||||
ds_colormap += (256*32);
|
||||
|
||||
if (currentplane->extra_colormap)
|
||||
ds_colormap = currentplane->extra_colormap->colormap;
|
||||
else
|
||||
ds_colormap = colormaps;
|
||||
|
||||
ds_y = y;
|
||||
ds_x1 = x1;
|
||||
ds_x2 = x2;
|
||||
|
||||
spanfunc();
|
||||
}
|
||||
|
||||
//
|
||||
// R_ClearPlanes
|
||||
// At begining of frame.
|
||||
@@ -385,7 +382,7 @@ static visplane_t *new_visplane(unsigned hash)
|
||||
visplane_t *check = freetail;
|
||||
if (!check)
|
||||
{
|
||||
check = calloc(1, sizeof (*check));
|
||||
check = malloc(sizeof (*check));
|
||||
if (check == NULL) I_Error("%s: Out of memory", "new_visplane"); // FIXME: ugly
|
||||
}
|
||||
else
|
||||
@@ -421,11 +418,11 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
|
||||
if (plangle != 0)
|
||||
{
|
||||
// Add the view offset, rotated by the plane angle.
|
||||
fixed_t cosinecomponent = FINECOSINE(plangle>>ANGLETOFINESHIFT);
|
||||
fixed_t sinecomponent = FINESINE(plangle>>ANGLETOFINESHIFT);
|
||||
fixed_t oldxoff = xoff;
|
||||
xoff = FixedMul(xoff,cosinecomponent)+FixedMul(yoff,sinecomponent);
|
||||
yoff = -FixedMul(oldxoff,sinecomponent)+FixedMul(yoff,cosinecomponent);
|
||||
float ang = ANG2RAD(plangle);
|
||||
float x = FixedToFloat(xoff);
|
||||
float y = FixedToFloat(yoff);
|
||||
xoff = FloatToFixed(x * cos(ang) + y * sin(ang));
|
||||
yoff = FloatToFixed(-x * sin(ang) + y * cos(ang));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,10 +627,7 @@ void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop)
|
||||
pl->minx = unionl, pl->maxx = unionh;
|
||||
}
|
||||
|
||||
//
|
||||
// R_MakeSpans
|
||||
//
|
||||
void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2)
|
||||
static void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2)
|
||||
{
|
||||
// Alam: from r_splats's R_RenderFloorSplat
|
||||
if (t1 >= vid.height) t1 = vid.height-1;
|
||||
@@ -659,6 +653,32 @@ void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2)
|
||||
spanstart[b2--] = x;
|
||||
}
|
||||
|
||||
static void R_MakeTiltedSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2)
|
||||
{
|
||||
// Alam: from r_splats's R_RasterizeFloorSplat
|
||||
if (t1 >= vid.height) t1 = vid.height-1;
|
||||
if (b1 >= vid.height) b1 = vid.height-1;
|
||||
if (t2 >= vid.height) t2 = vid.height-1;
|
||||
if (b2 >= vid.height) b2 = vid.height-1;
|
||||
if (x-1 >= vid.width) x = vid.width;
|
||||
|
||||
while (t1 < t2 && t1 <= b1)
|
||||
{
|
||||
R_MapTiltedPlane(t1, spanstart[t1], x - 1);
|
||||
t1++;
|
||||
}
|
||||
while (b1 > b2 && b1 >= t1)
|
||||
{
|
||||
R_MapTiltedPlane(b1, spanstart[b1], x - 1);
|
||||
b1--;
|
||||
}
|
||||
|
||||
while (t2 < t1 && t2 <= b2)
|
||||
spanstart[t2++] = x;
|
||||
while (b2 > b1 && b2 >= t2)
|
||||
spanstart[b2--] = x;
|
||||
}
|
||||
|
||||
void R_DrawPlanes(void)
|
||||
{
|
||||
visplane_t *pl;
|
||||
@@ -666,6 +686,7 @@ void R_DrawPlanes(void)
|
||||
|
||||
spanfunc = basespanfunc;
|
||||
wallcolfunc = walldrawerfunc;
|
||||
R_UpdatePlaneRipple();
|
||||
|
||||
for (i = 0; i < MAXVISPLANES; i++, pl++)
|
||||
{
|
||||
@@ -677,10 +698,6 @@ void R_DrawPlanes(void)
|
||||
R_DrawSinglePlane(pl);
|
||||
}
|
||||
}
|
||||
#ifndef NOWATER
|
||||
waterofs = (leveltime & 1)*16384;
|
||||
wtofs = ((leveltime-1)*140) + ((rendertimefrac*140) / FRACUNIT);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void R_DrawSkyPlane(visplane_t *pl)
|
||||
@@ -725,6 +742,161 @@ static void R_DrawSkyPlane(visplane_t *pl)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the height of the sloped plane at (x, y) as a 32.16 fixed_t
|
||||
static INT64 R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y)
|
||||
{
|
||||
INT64 x64 = ((INT64)x - (INT64)slope->o.x);
|
||||
INT64 y64 = ((INT64)y - (INT64)slope->o.y);
|
||||
|
||||
x64 = (x64 * (INT64)slope->d.x) / FRACUNIT;
|
||||
y64 = (y64 * (INT64)slope->d.y) / FRACUNIT;
|
||||
|
||||
return (INT64)slope->o.z + ((x64 + y64) * (INT64)slope->zdelta) / FRACUNIT;
|
||||
}
|
||||
|
||||
// Sets the texture origin vector of the sloped plane.
|
||||
static void R_SetSlopePlaneOrigin(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xoff, fixed_t yoff, fixed_t angle)
|
||||
{
|
||||
floatv3_t *p = &ds_slope_origin;
|
||||
|
||||
INT64 vx = (INT64)xpos + (INT64)xoff;
|
||||
INT64 vy = (INT64)ypos - (INT64)yoff;
|
||||
|
||||
float vxf = vx / (float)FRACUNIT;
|
||||
float vyf = vy / (float)FRACUNIT;
|
||||
float ang = ANG2RAD(ANGLE_270 - angle);
|
||||
|
||||
// p is the texture origin in view space
|
||||
// Don't add in the offsets at this stage, because doing so can result in
|
||||
// errors if the flat is rotated.
|
||||
p->x = vxf * cos(ang) - vyf * sin(ang);
|
||||
p->z = vxf * sin(ang) + vyf * cos(ang);
|
||||
p->y = (R_GetSlopeZAt(slope, -xoff, yoff) - zpos) / (float)FRACUNIT;
|
||||
}
|
||||
|
||||
// This function calculates all of the vectors necessary for drawing a sloped plane.
|
||||
void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle)
|
||||
{
|
||||
// Potentially override other stuff for now cus we're mean. :< But draw a slope plane!
|
||||
// I copied ZDoom's code and adapted it to SRB2... -Red
|
||||
floatv3_t *m = &ds_slope_v, *n = &ds_slope_u;
|
||||
fixed_t height, temp;
|
||||
float ang;
|
||||
|
||||
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
|
||||
height = P_GetZAt(slope, xpos, ypos);
|
||||
zeroheight = FixedToFloat(height - zpos);
|
||||
|
||||
// m is the v direction vector in view space
|
||||
ang = ANG2RAD(ANGLE_180 - (angle + plangle));
|
||||
m->x = cos(ang);
|
||||
m->z = sin(ang);
|
||||
|
||||
// n is the u direction vector in view space
|
||||
n->x = sin(ang);
|
||||
n->z = -cos(ang);
|
||||
|
||||
plangle >>= ANGLETOFINESHIFT;
|
||||
temp = P_GetZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle));
|
||||
m->y = FixedToFloat(temp - height);
|
||||
temp = P_GetZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle));
|
||||
n->y = FixedToFloat(temp - height);
|
||||
}
|
||||
|
||||
// This function calculates all of the vectors necessary for drawing a sloped and scaled plane.
|
||||
void R_SetScaledSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xs, fixed_t ys, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle)
|
||||
{
|
||||
floatv3_t *m = &ds_slope_v, *n = &ds_slope_u;
|
||||
fixed_t height, temp;
|
||||
|
||||
float xscale = FixedToFloat(xs);
|
||||
float yscale = FixedToFloat(ys);
|
||||
float ang;
|
||||
|
||||
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
|
||||
height = P_GetZAt(slope, xpos, ypos);
|
||||
zeroheight = FixedToFloat(height - zpos);
|
||||
|
||||
// m is the v direction vector in view space
|
||||
ang = ANG2RAD(ANGLE_180 - (angle + plangle));
|
||||
m->x = yscale * cos(ang);
|
||||
m->z = yscale * sin(ang);
|
||||
|
||||
// n is the u direction vector in view space
|
||||
n->x = xscale * sin(ang);
|
||||
n->z = -xscale * cos(ang);
|
||||
|
||||
ang = ANG2RAD(plangle);
|
||||
temp = P_GetZAt(slope, xpos + FloatToFixed(yscale * sin(ang)), ypos + FloatToFixed(yscale * cos(ang)));
|
||||
m->y = FixedToFloat(temp - height);
|
||||
temp = P_GetZAt(slope, xpos + FloatToFixed(xscale * cos(ang)), ypos - FloatToFixed(xscale * sin(ang)));
|
||||
n->y = FixedToFloat(temp - height);
|
||||
}
|
||||
|
||||
void R_CalculateSlopeVectors(void)
|
||||
{
|
||||
float sfmult = 65536.f;
|
||||
|
||||
// Eh. I tried making this stuff fixed-point and it exploded on me. Here's a macro for the only floating-point vector function I recall using.
|
||||
#define CROSS(d, v1, v2) \
|
||||
d->x = (v1.y * v2.z) - (v1.z * v2.y);\
|
||||
d->y = (v1.z * v2.x) - (v1.x * v2.z);\
|
||||
d->z = (v1.x * v2.y) - (v1.y * v2.x)
|
||||
CROSS(ds_sup, ds_slope_origin, ds_slope_v);
|
||||
CROSS(ds_svp, ds_slope_origin, ds_slope_u);
|
||||
CROSS(ds_szp, ds_slope_v, ds_slope_u);
|
||||
#undef CROSS
|
||||
|
||||
ds_sup->z *= focallengthf;
|
||||
ds_svp->z *= focallengthf;
|
||||
ds_szp->z *= focallengthf;
|
||||
|
||||
// Premultiply the texture vectors with the scale factors
|
||||
sfmult *= (1 << nflatshiftup);
|
||||
|
||||
ds_sup->x *= sfmult;
|
||||
ds_sup->y *= sfmult;
|
||||
ds_sup->z *= sfmult;
|
||||
ds_svp->x *= sfmult;
|
||||
ds_svp->y *= sfmult;
|
||||
ds_svp->z *= sfmult;
|
||||
}
|
||||
|
||||
void R_SetTiltedSpan(INT32 span)
|
||||
{
|
||||
if (ds_su == NULL)
|
||||
ds_su = Z_Malloc(sizeof(*ds_su) * vid.height, PU_STATIC, NULL);
|
||||
if (ds_sv == NULL)
|
||||
ds_sv = Z_Malloc(sizeof(*ds_sv) * vid.height, PU_STATIC, NULL);
|
||||
if (ds_sz == NULL)
|
||||
ds_sz = Z_Malloc(sizeof(*ds_sz) * vid.height, PU_STATIC, NULL);
|
||||
|
||||
ds_sup = &ds_su[span];
|
||||
ds_svp = &ds_sv[span];
|
||||
ds_szp = &ds_sz[span];
|
||||
}
|
||||
|
||||
static void R_SetSlopePlaneVectors(visplane_t *pl, INT32 y, fixed_t xoff, fixed_t yoff)
|
||||
{
|
||||
R_SetTiltedSpan(y);
|
||||
R_SetSlopePlane(pl->slope, pl->viewx, pl->viewy, pl->viewz, xoff, yoff, pl->viewangle, pl->plangle);
|
||||
R_CalculateSlopeVectors();
|
||||
}
|
||||
|
||||
static inline void R_AdjustSlopeCoordinates(vector3_t *origin)
|
||||
{
|
||||
const fixed_t modmask = ((1 << (32-nflatshiftup)) - 1);
|
||||
|
||||
fixed_t ox = (origin->x & modmask);
|
||||
fixed_t oy = -(origin->y & modmask);
|
||||
|
||||
xoffs &= modmask;
|
||||
yoffs &= modmask;
|
||||
|
||||
xoffs -= (origin->x - ox);
|
||||
yoffs += (origin->y + oy);
|
||||
}
|
||||
|
||||
void R_DrawSinglePlane(visplane_t *pl)
|
||||
{
|
||||
INT32 light = 0;
|
||||
@@ -743,9 +915,7 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NOWATER
|
||||
itswater = false;
|
||||
#endif
|
||||
planeripple.active = false;
|
||||
spanfunc = basespanfunc;
|
||||
|
||||
if (pl->polyobj && pl->polyobj->translucency != 0) {
|
||||
@@ -832,15 +1002,13 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
}
|
||||
else light = (pl->lightlevel >> LIGHTSEGSHIFT);
|
||||
|
||||
#ifndef NOWATER
|
||||
if (pl->ffloor->flags & FF_RIPPLE
|
||||
&& !pl->slope
|
||||
)
|
||||
if (pl->ffloor->flags & FF_RIPPLE)
|
||||
{
|
||||
INT32 top, bottom;
|
||||
UINT8 *scr;
|
||||
|
||||
itswater = true;
|
||||
planeripple.active = true;
|
||||
|
||||
if (spanfunc == R_DrawTranslucentSpan_8)
|
||||
{
|
||||
spanfunc = R_DrawTranslucentWaterSpan_8;
|
||||
@@ -869,12 +1037,11 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
vid.width, vid.width);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else light = (pl->lightlevel >> LIGHTSEGSHIFT);
|
||||
|
||||
if (!pl->slope) // Don't mess with angle on slopes! We'll handle this ourselves later
|
||||
if (viewangle != pl->viewangle+pl->plangle)
|
||||
if (!pl->slope // Don't mess with angle on slopes! We'll handle this ourselves later
|
||||
&& viewangle != pl->viewangle+pl->plangle)
|
||||
{
|
||||
memset(cachedheight, 0, sizeof (cachedheight));
|
||||
angle = (pl->viewangle+pl->plangle-ANGLE_90)>>ANGLETOFINESHIFT;
|
||||
@@ -939,7 +1106,6 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
|
||||
xoffs = pl->xoffs;
|
||||
yoffs = pl->yoffs;
|
||||
planeheight = abs(pl->height - pl->viewz);
|
||||
|
||||
if (light >= LIGHTLEVELS)
|
||||
light = LIGHTLEVELS-1;
|
||||
@@ -947,137 +1113,32 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
if (light < 0)
|
||||
light = 0;
|
||||
|
||||
if (pl->slope) {
|
||||
// Potentially override other stuff for now cus we're mean. :< But draw a slope plane!
|
||||
// I copied ZDoom's code and adapted it to SRB2... -fickle
|
||||
floatv3_t p, m, n;
|
||||
float ang;
|
||||
float vx, vy, vz;
|
||||
// compiler complains when P_GetZAt is used in FLOAT_TO_FIXED directly
|
||||
// use this as a temp var to store P_GetZAt's return value each time
|
||||
fixed_t temp;
|
||||
// Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -fickle
|
||||
const float fudge = ((1<<nflatshiftup)+1.0f)/(1<<nflatshiftup);
|
||||
|
||||
angle_t hack = (pl->plangle & (ANGLE_90-1));
|
||||
|
||||
if (hack)
|
||||
if (pl->slope)
|
||||
{
|
||||
if (!pl->plangle)
|
||||
{
|
||||
/*
|
||||
Essentially: We can't & the components along the regular axes when the plane is rotated.
|
||||
This is because the distance on each regular axis in order to loop is different.
|
||||
We rotate them, & the components, add them together, & them again, and then rotate them back.
|
||||
These three seperate & operations are done per axis in order to prevent overflows.
|
||||
toast 10/04/17
|
||||
---
|
||||
...of coooourse, this still isn't perfect. but it looks... merely kind of grody, rather than
|
||||
completely wrong? idk. i'm just backporting this to kart right now. if anyone else wants to
|
||||
ever try dig around: it's drifting towards 0,0, and no, multiplying by fudge doesn't fix it.
|
||||
toast 27/09/18
|
||||
*/
|
||||
R_AdjustSlopeCoordinates(&pl->slope->o);
|
||||
}
|
||||
|
||||
if (planeripple.active)
|
||||
{
|
||||
planeheight = abs(P_GetZAt(pl->slope, pl->viewx, pl->viewy) - pl->viewz);
|
||||
|
||||
const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT);
|
||||
const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT);
|
||||
R_PlaneBounds(pl);
|
||||
|
||||
const fixed_t modmask = ((1 << (32-nflatshiftup)) - 1);
|
||||
|
||||
fixed_t ox = (FixedMul(pl->slope->o.x,cosinecomponent) & modmask) - (FixedMul(pl->slope->o.y,sinecomponent) & modmask);
|
||||
fixed_t oy = (-FixedMul(pl->slope->o.x,sinecomponent) & modmask) - (FixedMul(pl->slope->o.y,cosinecomponent) & modmask);
|
||||
|
||||
temp = ox & modmask;
|
||||
oy &= modmask;
|
||||
ox = FixedMul(temp,cosinecomponent)+FixedMul(oy,-sinecomponent); // negative sine for opposite direction
|
||||
oy = -FixedMul(temp,-sinecomponent)+FixedMul(oy,cosinecomponent);
|
||||
|
||||
temp = xoffs;
|
||||
xoffs = (FixedMul(temp,cosinecomponent) & modmask) + (FixedMul(yoffs,sinecomponent) & modmask);
|
||||
yoffs = (-FixedMul(temp,sinecomponent) & modmask) + (FixedMul(yoffs,cosinecomponent) & modmask);
|
||||
|
||||
temp = xoffs & modmask;
|
||||
yoffs &= modmask;
|
||||
xoffs = FixedMul(temp,cosinecomponent)+FixedMul(yoffs,-sinecomponent); // ditto
|
||||
yoffs = -FixedMul(temp,-sinecomponent)+FixedMul(yoffs,cosinecomponent);
|
||||
|
||||
xoffs -= (pl->slope->o.x - ox);
|
||||
yoffs += (pl->slope->o.y + oy);
|
||||
for (x = pl->high; x < pl->low; x++)
|
||||
{
|
||||
ds_bgofs = R_CalculateRippleOffset(x);
|
||||
R_CalculatePlaneRipple(pl->viewangle + pl->plangle);
|
||||
R_SetSlopePlaneVectors(pl, x, (xoffs + planeripple.xfrac), (yoffs + planeripple.yfrac));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xoffs &= ((1 << (32-nflatshiftup))-1);
|
||||
yoffs &= ((1 << (32-nflatshiftup))-1);
|
||||
xoffs -= (pl->slope->o.x + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);
|
||||
yoffs += (pl->slope->o.y + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);
|
||||
}
|
||||
R_SetSlopePlaneVectors(pl, 0, xoffs, yoffs);
|
||||
|
||||
xoffs = (fixed_t)(xoffs*fudge);
|
||||
yoffs = (fixed_t)(yoffs/fudge);
|
||||
|
||||
vx = FIXED_TO_FLOAT(pl->viewx+xoffs);
|
||||
vy = FIXED_TO_FLOAT(pl->viewy-yoffs);
|
||||
vz = FIXED_TO_FLOAT(pl->viewz);
|
||||
|
||||
temp = P_GetZAt(pl->slope, pl->viewx, pl->viewy);
|
||||
zeroheight = FIXED_TO_FLOAT(temp);
|
||||
|
||||
#define ANG2RAD(angle) ((float)((angle)*M_PIl)/ANGLE_180)
|
||||
|
||||
// p is the texture origin in view space
|
||||
// Don't add in the offsets at this stage, because doing so can result in
|
||||
// errors if the flat is rotated.
|
||||
ang = ANG2RAD(ANGLE_270 - pl->viewangle);
|
||||
p.x = vx * cos(ang) - vy * sin(ang);
|
||||
p.z = vx * sin(ang) + vy * cos(ang);
|
||||
temp = P_GetZAt(pl->slope, -xoffs, yoffs);
|
||||
p.y = FIXED_TO_FLOAT(temp) - vz;
|
||||
|
||||
// m is the v direction vector in view space
|
||||
ang = ANG2RAD(ANGLE_180 - (pl->viewangle + pl->plangle));
|
||||
m.x = cos(ang);
|
||||
m.z = sin(ang);
|
||||
|
||||
// n is the u direction vector in view space
|
||||
n.x = sin(ang);
|
||||
n.z = -cos(ang);
|
||||
|
||||
ang = ANG2RAD(pl->plangle);
|
||||
temp = P_GetZAt(pl->slope, pl->viewx + FLOAT_TO_FIXED(sin(ang)), pl->viewy + FLOAT_TO_FIXED(cos(ang)));
|
||||
m.y = FIXED_TO_FLOAT(temp) - zeroheight;
|
||||
temp = P_GetZAt(pl->slope, pl->viewx + FLOAT_TO_FIXED(cos(ang)), pl->viewy - FLOAT_TO_FIXED(sin(ang)));
|
||||
n.y = FIXED_TO_FLOAT(temp) - zeroheight;
|
||||
|
||||
m.x /= fudge;
|
||||
m.y /= fudge;
|
||||
m.z /= fudge;
|
||||
|
||||
n.x *= fudge;
|
||||
n.y *= fudge;
|
||||
n.z *= fudge;
|
||||
|
||||
// Eh. I tried making this stuff fixed-point and it exploded on me. Here's a macro for the only floating-point vector function I recall using.
|
||||
#define CROSS(d, v1, v2) \
|
||||
d.x = (v1.y * v2.z) - (v1.z * v2.y);\
|
||||
d.y = (v1.z * v2.x) - (v1.x * v2.z);\
|
||||
d.z = (v1.x * v2.y) - (v1.y * v2.x)
|
||||
CROSS(ds_su, p, m);
|
||||
CROSS(ds_sv, p, n);
|
||||
CROSS(ds_sz, m, n);
|
||||
#undef CROSS
|
||||
|
||||
ds_su.z *= focallengthf;
|
||||
ds_sv.z *= focallengthf;
|
||||
ds_sz.z *= focallengthf;
|
||||
|
||||
// Premultiply the texture vectors with the scale factors
|
||||
#define SFMULT 65536.f*(1<<nflatshiftup)
|
||||
ds_su.x *= SFMULT;
|
||||
ds_su.y *= SFMULT;
|
||||
ds_su.z *= SFMULT;
|
||||
ds_sv.x *= SFMULT;
|
||||
ds_sv.y *= SFMULT;
|
||||
ds_sv.z *= SFMULT;
|
||||
#undef SFMULT
|
||||
|
||||
if (spanfunc == R_DrawTranslucentSpan_8)
|
||||
if (spanfunc == R_DrawTranslucentWaterSpan_8)
|
||||
spanfunc = R_DrawTiltedTranslucentWaterSpan_8;
|
||||
else if (spanfunc == R_DrawTranslucentSpan_8)
|
||||
spanfunc = R_DrawTiltedTranslucentSpan_8;
|
||||
else if (spanfunc == splatfunc)
|
||||
spanfunc = R_DrawTiltedSplat_8;
|
||||
@@ -1085,9 +1146,12 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
spanfunc = R_DrawTiltedSpan_8;
|
||||
|
||||
planezlight = scalelight[light];
|
||||
} else
|
||||
|
||||
planezlight = zlight[light];
|
||||
}
|
||||
else
|
||||
{
|
||||
planeheight = abs(pl->height - pl->viewz);
|
||||
planezlight = zlight[light];
|
||||
}
|
||||
|
||||
// set the maximum value for unsigned
|
||||
pl->top[pl->maxx+1] = 0xffff;
|
||||
@@ -1097,18 +1161,15 @@ void R_DrawSinglePlane(visplane_t *pl)
|
||||
|
||||
stop = pl->maxx + 1;
|
||||
|
||||
if (viewx != pl->viewx || viewy != pl->viewy)
|
||||
if (pl->slope)
|
||||
{
|
||||
viewx = pl->viewx;
|
||||
viewy = pl->viewy;
|
||||
for (x = pl->minx; x <= stop; x++)
|
||||
R_MakeTiltedSpans(x, pl->top[x-1], pl->bottom[x-1], pl->top[x], pl->bottom[x]);
|
||||
}
|
||||
if (viewz != pl->viewz)
|
||||
viewz = pl->viewz;
|
||||
|
||||
for (x = pl->minx; x <= stop; x++)
|
||||
else
|
||||
{
|
||||
R_MakeSpans(x, pl->top[x-1], pl->bottom[x-1],
|
||||
pl->top[x], pl->bottom[x]);
|
||||
for (x = pl->minx; x <= stop; x++)
|
||||
R_MakeSpans(x, pl->top[x-1], pl->bottom[x-1], pl->top[x], pl->bottom[x]);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+8
-2
@@ -79,8 +79,6 @@ void R_PortalStoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor,
|
||||
void R_PortalRestoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor, fixed_t *scale);
|
||||
void R_ClearPlanes(void);
|
||||
|
||||
void R_MapPlane(INT32 y, INT32 x1, INT32 x2);
|
||||
void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2);
|
||||
void R_DrawPlanes(void);
|
||||
visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, fixed_t xoff, fixed_t yoff, angle_t plangle,
|
||||
extracolormap_t *planecolormap, ffloor_t *ffloor
|
||||
@@ -94,6 +92,14 @@ void R_PlaneBounds(visplane_t *plane);
|
||||
// Draws a single visplane.
|
||||
void R_DrawSinglePlane(visplane_t *pl);
|
||||
|
||||
// Calculates the slope vectors needed for tilted span drawing.
|
||||
void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle);
|
||||
void R_SetScaledSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xs, fixed_t ys, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle);
|
||||
void R_CalculateSlopeVectors(void);
|
||||
|
||||
// Sets the slope vector pointers for the current tilted span.
|
||||
void R_SetTiltedSpan(INT32 span);
|
||||
|
||||
typedef struct planemgr_s
|
||||
{
|
||||
visplane_t *plane;
|
||||
|
||||
Reference in new issue
Block a user