mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-13 13:21:31 +00:00
Revamp flat alignment to be consistent across all renderer functions except for the software slope renderer, which me and fickle tried our best at but couldn't get to work. (This is a backport of 2.2 code that slightly postdates the improved flat alignment Kart's had for a while.)
This fixes #11.
This commit is contained in:
parent
8aff76b8c3
commit
e4f6015b50
4 changed files with 94 additions and 67 deletions
|
@ -643,13 +643,13 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
|
|||
{
|
||||
scrollx = FIXED_TO_FLOAT(FOFsector->floor_xoffs)/fflatsize;
|
||||
scrolly = FIXED_TO_FLOAT(FOFsector->floor_yoffs)/fflatsize;
|
||||
angle = FOFsector->floorpic_angle>>ANGLETOFINESHIFT;
|
||||
angle = FOFsector->floorpic_angle;
|
||||
}
|
||||
else // it's a ceiling
|
||||
{
|
||||
scrollx = FIXED_TO_FLOAT(FOFsector->ceiling_xoffs)/fflatsize;
|
||||
scrolly = FIXED_TO_FLOAT(FOFsector->ceiling_yoffs)/fflatsize;
|
||||
angle = FOFsector->ceilingpic_angle>>ANGLETOFINESHIFT;
|
||||
angle = FOFsector->ceilingpic_angle;
|
||||
}
|
||||
}
|
||||
else if (gr_frontsector)
|
||||
|
@ -658,24 +658,26 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
|
|||
{
|
||||
scrollx = FIXED_TO_FLOAT(gr_frontsector->floor_xoffs)/fflatsize;
|
||||
scrolly = FIXED_TO_FLOAT(gr_frontsector->floor_yoffs)/fflatsize;
|
||||
angle = gr_frontsector->floorpic_angle>>ANGLETOFINESHIFT;
|
||||
angle = gr_frontsector->floorpic_angle;
|
||||
}
|
||||
else // it's a ceiling
|
||||
{
|
||||
scrollx = FIXED_TO_FLOAT(gr_frontsector->ceiling_xoffs)/fflatsize;
|
||||
scrolly = FIXED_TO_FLOAT(gr_frontsector->ceiling_yoffs)/fflatsize;
|
||||
angle = gr_frontsector->ceilingpic_angle>>ANGLETOFINESHIFT;
|
||||
angle = gr_frontsector->ceilingpic_angle;
|
||||
}
|
||||
}
|
||||
|
||||
if (angle) // Only needs to be done if there's an altered angle
|
||||
{
|
||||
|
||||
angle = InvAngle(angle)>>ANGLETOFINESHIFT;
|
||||
|
||||
// This needs to be done so that it scrolls in a different direction after rotation like software
|
||||
tempxsow = FLOAT_TO_FIXED(scrollx);
|
||||
/*tempxsow = FLOAT_TO_FIXED(scrollx);
|
||||
tempytow = FLOAT_TO_FIXED(scrolly);
|
||||
scrollx = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle))));
|
||||
scrolly = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));
|
||||
scrolly = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));*/
|
||||
|
||||
// This needs to be done so everything aligns after rotation
|
||||
// It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does
|
||||
|
@ -689,7 +691,7 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
|
|||
{
|
||||
// Hurdler: add scrolling texture on floor/ceiling
|
||||
v3d->sow = (float)((pv->x / fflatsize) - flatxref + scrollx);
|
||||
v3d->tow = (float)(flatyref - (pv->y / fflatsize) + scrolly);
|
||||
v3d->tow = (float)(-(pv->y / fflatsize) + flatyref + scrolly);
|
||||
|
||||
//v3d->sow = (float)(pv->x / fflatsize);
|
||||
//v3d->tow = (float)(pv->y / fflatsize);
|
||||
|
@ -700,7 +702,7 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is
|
|||
tempxsow = FLOAT_TO_FIXED(v3d->sow);
|
||||
tempytow = FLOAT_TO_FIXED(v3d->tow);
|
||||
v3d->sow = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle))));
|
||||
v3d->tow = (FIXED_TO_FLOAT(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle))));
|
||||
v3d->tow = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));
|
||||
}
|
||||
|
||||
//v3d->sow = (float)(v3d->sow - flatxref + scrollx);
|
||||
|
|
|
@ -5821,10 +5821,8 @@ void P_SpawnSpecials(INT32 fromnetsave)
|
|||
}
|
||||
else // Otherwise, set calculated offsets such that line's v1 is the apparent origin
|
||||
{
|
||||
fixed_t cosinecomponent = FINECOSINE(flatangle>>ANGLETOFINESHIFT);
|
||||
fixed_t sinecomponent = FINESINE(flatangle>>ANGLETOFINESHIFT);
|
||||
xoffs = (-FixedMul(lines[i].v1->x, cosinecomponent) % MAXFLATSIZE) + (FixedMul(lines[i].v1->y, sinecomponent) % MAXFLATSIZE); // No danger of overflow thanks to the strategically placed modulo operations.
|
||||
yoffs = (FixedMul(lines[i].v1->x, sinecomponent) % MAXFLATSIZE) + (FixedMul(lines[i].v1->y, cosinecomponent) % MAXFLATSIZE); // Ditto.
|
||||
xoffs = -lines[i].v1->x;
|
||||
yoffs = lines[i].v1->y;
|
||||
}
|
||||
|
||||
for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;)
|
||||
|
|
44
src/r_bsp.c
44
src/r_bsp.c
|
@ -1126,30 +1126,12 @@ static void R_Subsector(size_t num, UINT8 viewnumber)
|
|||
&& polysec->floorheight >= floorcenterz
|
||||
&& (viewz < polysec->floorheight))
|
||||
{
|
||||
fixed_t xoff, yoff;
|
||||
xoff = polysec->floor_xoffs;
|
||||
yoff = polysec->floor_yoffs;
|
||||
|
||||
if (po->angle != 0) {
|
||||
angle_t fineshift = po->angle >> ANGLETOFINESHIFT;
|
||||
|
||||
xoff -= FixedMul(FINECOSINE(fineshift), po->centerPt.x)+FixedMul(FINESINE(fineshift), po->centerPt.y);
|
||||
yoff -= FixedMul(FINESINE(fineshift), po->centerPt.x)-FixedMul(FINECOSINE(fineshift), po->centerPt.y);
|
||||
} else {
|
||||
xoff -= po->centerPt.x;
|
||||
yoff += po->centerPt.y;
|
||||
}
|
||||
|
||||
light = R_GetPlaneLight(frontsector, polysec->floorheight, viewz < polysec->floorheight);
|
||||
light = 0;
|
||||
ffloor[numffloors].plane = R_FindPlane(polysec->floorheight, polysec->floorpic,
|
||||
polysec->lightlevel, xoff, yoff,
|
||||
polysec->lightlevel, polysec->floor_xoffs, polysec->floor_yoffs,
|
||||
polysec->floorpic_angle-po->angle,
|
||||
NULL,
|
||||
NULL
|
||||
#ifdef POLYOBJECTS_PLANES
|
||||
, po
|
||||
#endif
|
||||
NULL, NULL, po
|
||||
#ifdef ESLOPE
|
||||
, NULL // will ffloors be slopable eventually?
|
||||
#endif
|
||||
|
@ -1174,28 +1156,12 @@ static void R_Subsector(size_t num, UINT8 viewnumber)
|
|||
&& polysec->ceilingheight <= ceilingcenterz
|
||||
&& (viewz > polysec->ceilingheight))
|
||||
{
|
||||
fixed_t xoff, yoff;
|
||||
xoff = polysec->ceiling_xoffs;
|
||||
yoff = polysec->ceiling_yoffs;
|
||||
|
||||
if (po->angle != 0) {
|
||||
angle_t fineshift = po->angle >> ANGLETOFINESHIFT;
|
||||
|
||||
xoff -= FixedMul(FINECOSINE(fineshift), po->centerPt.x)+FixedMul(FINESINE(fineshift), po->centerPt.y);
|
||||
yoff -= FixedMul(FINESINE(fineshift), po->centerPt.x)-FixedMul(FINECOSINE(fineshift), po->centerPt.y);
|
||||
} else {
|
||||
xoff -= po->centerPt.x;
|
||||
yoff += po->centerPt.y;
|
||||
}
|
||||
|
||||
light = R_GetPlaneLight(frontsector, polysec->ceilingheight, viewz < polysec->ceilingheight);
|
||||
light = 0;
|
||||
ffloor[numffloors].plane = R_FindPlane(polysec->ceilingheight, polysec->ceilingpic,
|
||||
polysec->lightlevel, xoff, yoff, polysec->ceilingpic_angle-po->angle,
|
||||
NULL, NULL
|
||||
#ifdef POLYOBJECTS_PLANES
|
||||
, po
|
||||
#endif
|
||||
polysec->lightlevel, polysec->ceiling_xoffs, polysec->ceiling_yoffs,
|
||||
polysec->ceilingpic_angle-po->angle,
|
||||
NULL, NULL, po
|
||||
#ifdef ESLOPE
|
||||
, NULL // will ffloors be slopable eventually?
|
||||
#endif
|
||||
|
|
|
@ -450,19 +450,37 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
|
|||
#ifdef ESLOPE
|
||||
if (slope); else // Don't mess with this right now if a slope is involved
|
||||
#endif
|
||||
if (plangle != 0)
|
||||
{
|
||||
// Add the view offset, rotated by the plane angle.
|
||||
angle_t angle = plangle>>ANGLETOFINESHIFT;
|
||||
xoff += FixedMul(viewx,FINECOSINE(angle))-FixedMul(viewy,FINESINE(angle));
|
||||
yoff += -FixedMul(viewx,FINESINE(angle))-FixedMul(viewy,FINECOSINE(angle));
|
||||
}
|
||||
else
|
||||
{
|
||||
xoff += viewx;
|
||||
yoff -= viewy;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef POLYOBJECTS_PLANES
|
||||
if (polyobj)
|
||||
{
|
||||
if (polyobj->angle != 0)
|
||||
{
|
||||
angle_t fineshift = polyobj->angle >> ANGLETOFINESHIFT;
|
||||
xoff -= FixedMul(FINECOSINE(fineshift), polyobj->centerPt.x)+FixedMul(FINESINE(fineshift), polyobj->centerPt.y);
|
||||
yoff -= FixedMul(FINESINE(fineshift), polyobj->centerPt.x)-FixedMul(FINECOSINE(fineshift), polyobj->centerPt.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
xoff -= polyobj->centerPt.x;
|
||||
yoff += polyobj->centerPt.y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// This appears to fix the Nimbus Ruins sky bug.
|
||||
if (picnum == skyflatnum && pfloor)
|
||||
{
|
||||
|
@ -488,6 +506,7 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel,
|
|||
&& !pfloor && !check->ffloor
|
||||
&& check->viewx == viewx && check->viewy == viewy && check->viewz == viewz
|
||||
&& check->viewangle == viewangle
|
||||
&& check->plangle == plangle
|
||||
#ifdef ESLOPE
|
||||
&& check->slope == slope
|
||||
#endif
|
||||
|
@ -974,23 +993,65 @@ void R_DrawSinglePlane(visplane_t *pl)
|
|||
#ifdef ESLOPE
|
||||
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... -Red
|
||||
// I copied ZDoom's code and adapted it to SRB2... -fickle
|
||||
floatv3_t p, m, n;
|
||||
float ang;
|
||||
float vx, vy, vz;
|
||||
float fudge;
|
||||
// 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);
|
||||
|
||||
xoffs &= ((1 << (32-nflatshiftup))-1);
|
||||
yoffs &= ((1 << (32-nflatshiftup))-1);
|
||||
angle_t hack = (pl->plangle & (ANGLE_90-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);
|
||||
if (hack)
|
||||
{
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
// Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red
|
||||
fudge = ((1<<nflatshiftup)+1.0f)/(1<<nflatshiftup);
|
||||
const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT);
|
||||
const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT);
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
xoffs = (fixed_t)(xoffs*fudge);
|
||||
yoffs = (fixed_t)(yoffs/fudge);
|
||||
|
|
Loading…
Reference in a new issue