Merge branch 'plane-sorting-fix' into 'master'

Fix sprite against FOF plane sorting

See merge request KartKrew/Kart!328
This commit is contained in:
Sal 2020-11-03 13:06:49 -05:00
commit d79c719ad9
2 changed files with 41 additions and 31 deletions

View file

@ -1074,14 +1074,6 @@ static void R_SplitSprite(vissprite_t *sprite)
sprite->sz = cutfrac; sprite->sz = cutfrac;
newsprite->szt = (INT16)(sprite->sz - 1); newsprite->szt = (INT16)(sprite->sz - 1);
if (testheight < sprite->pzt && testheight > sprite->pz)
sprite->pz = newsprite->pzt = testheight;
else
{
newsprite->pz = newsprite->gz;
newsprite->pzt = newsprite->gzt;
}
newsprite->szt -= 8; newsprite->szt -= 8;
newsprite->cut |= SC_TOP; newsprite->cut |= SC_TOP;
@ -1238,6 +1230,32 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope)
return groundz; return groundz;
} }
static void R_SetSpritePlaneHeights(vissprite_t *vis)
{
ffloor_t *rover;
fixed_t top;
fixed_t bot;
vis->pt = vis->sector->floorheight;
vis->pb = vis->sector->ceilingheight;
for (rover = vis->sector->ffloors; rover; rover = rover->next)
{
if (rover->flags & FF_EXISTS)
{
top = P_GetFFloorTopZAt (rover, vis->gx, vis->gy);
bot = P_GetFFloorBottomZAt (rover, vis->gx, vis->gy);
if (top <= vis->gzt && top > vis->pt)
vis->pt = top;
if (bot >= vis->gz && bot < vis->pb)
vis->pb = bot;
}
}
}
static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, fixed_t tx, fixed_t tz) static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, fixed_t tx, fixed_t tz)
{ {
vissprite_t *shadow; vissprite_t *shadow;
@ -1305,16 +1323,12 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale,
shadow->patch = patch; shadow->patch = patch;
shadow->heightsec = vis->heightsec; shadow->heightsec = vis->heightsec;
shadow->thingheight = FRACUNIT;
shadow->pz = groundz + (isflipped ? -shadow->thingheight : 0);
shadow->pzt = shadow->pz + shadow->thingheight;
shadow->mobjflags = 0; shadow->mobjflags = 0;
shadow->sortscale = vis->sortscale; shadow->sortscale = vis->sortscale;
shadow->dispoffset = vis->dispoffset - 5; shadow->dispoffset = vis->dispoffset - 5;
shadow->gx = thing->x; shadow->gx = thing->x;
shadow->gy = thing->y; shadow->gy = thing->y;
shadow->gzt = (isflipped ? shadow->pzt : shadow->pz) + SHORT(patch->height) * shadowyscale / 2; shadow->gzt = groundz + SHORT(patch->height) * shadowyscale / 2;
shadow->gz = shadow->gzt - SHORT(patch->height) * shadowyscale; shadow->gz = shadow->gzt - SHORT(patch->height) * shadowyscale;
shadow->texturemid = FixedMul(thing->scale, FixedDiv(shadow->gzt - viewz, shadowyscale)); shadow->texturemid = FixedMul(thing->scale, FixedDiv(shadow->gzt - viewz, shadowyscale));
if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES) if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES)
@ -1330,6 +1344,8 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale,
shadow->xscale = FixedMul(xscale, shadowxscale); //SoM: 4/17/2000 shadow->xscale = FixedMul(xscale, shadowxscale); //SoM: 4/17/2000
shadow->scale = FixedMul(yscale, shadowyscale); shadow->scale = FixedMul(yscale, shadowyscale);
shadow->sector = vis->sector; shadow->sector = vis->sector;
shadow->pt = vis->pt;
shadow->pb = vis->pb;
shadow->szt = (INT16)((centeryfrac - FixedMul(shadow->gzt - viewz, yscale))>>FRACBITS); shadow->szt = (INT16)((centeryfrac - FixedMul(shadow->gzt - viewz, yscale))>>FRACBITS);
shadow->sz = (INT16)((centeryfrac - FixedMul(shadow->gz - viewz, yscale))>>FRACBITS); shadow->sz = (INT16)((centeryfrac - FixedMul(shadow->gz - viewz, yscale))>>FRACBITS);
shadow->cut = SC_ISSCALED|SC_SHADOW; //check this shadow->cut = SC_ISSCALED|SC_SHADOW; //check this
@ -1812,9 +1828,6 @@ static void R_ProjectSprite(mobj_t *thing)
vis->gy = thingypos; vis->gy = thingypos;
vis->gz = gz; vis->gz = gz;
vis->gzt = gzt; vis->gzt = gzt;
vis->thingheight = thing->height;
vis->pz = thingzpos;
vis->pzt = vis->pz + vis->thingheight;
vis->texturemid = vis->gzt - viewz; vis->texturemid = vis->gzt - viewz;
vis->scalestep = scalestep; vis->scalestep = scalestep;
vis->paperoffset = paperoffset; vis->paperoffset = paperoffset;
@ -1832,6 +1845,9 @@ static void R_ProjectSprite(mobj_t *thing)
vis->sector = thing->subsector->sector; vis->sector = thing->subsector->sector;
vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, sortscale))>>FRACBITS); vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, sortscale))>>FRACBITS);
vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, sortscale))>>FRACBITS); vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, sortscale))>>FRACBITS);
R_SetSpritePlaneHeights(vis);
vis->cut = cut; vis->cut = cut;
if (thing->subsector->sector->numlights) if (thing->subsector->sector->numlights)
vis->extra_colormap = *thing->subsector->sector->lightlist[light].extra_colormap; vis->extra_colormap = *thing->subsector->sector->lightlist[light].extra_colormap;
@ -2032,9 +2048,6 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
vis->gy = thing->y; vis->gy = thing->y;
vis->gz = gz; vis->gz = gz;
vis->gzt = gzt; vis->gzt = gzt;
vis->thingheight = 4*FRACUNIT;
vis->pz = thing->z;
vis->pzt = vis->pz + vis->thingheight;
vis->texturemid = vis->gzt - viewz; vis->texturemid = vis->gzt - viewz;
vis->scalestep = 0; vis->scalestep = 0;
vis->paperdistance = 0; vis->paperdistance = 0;
@ -2049,6 +2062,8 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, yscale))>>FRACBITS); vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, yscale))>>FRACBITS);
vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, yscale))>>FRACBITS); vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, yscale))>>FRACBITS);
R_SetSpritePlaneHeights(vis);
iscale = FixedDiv(FRACUNIT, xscale); iscale = FixedDiv(FRACUNIT, xscale);
vis->startfrac = 0; vis->startfrac = 0;
@ -2425,19 +2440,15 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps
planeobjectz = P_GetZAt(r2->plane->slope, rover->gx, rover->gy, r2->plane->height); planeobjectz = P_GetZAt(r2->plane->slope, rover->gx, rover->gy, r2->plane->height);
planecameraz = P_GetZAt(r2->plane->slope, viewx, viewy, r2->plane->height); planecameraz = P_GetZAt(r2->plane->slope, viewx, viewy, r2->plane->height);
if (rover->mobjflags & MF_NOCLIPHEIGHT) // bird: if any part of the sprite peeks in front the plane
if (planecameraz < viewz)
{ {
//Objects with NOCLIPHEIGHT can appear halfway in. if (rover->pt >= planeobjectz && rover->gzt >= planeobjectz)
if (planecameraz < viewz && rover->pz+(rover->thingheight/2) >= planeobjectz)
continue;
if (planecameraz > viewz && rover->pzt-(rover->thingheight/2) <= planeobjectz)
continue; continue;
} }
else else if (planecameraz > viewz)
{ {
if (planecameraz < viewz && rover->pz >= planeobjectz) if (rover->pb <= planeobjectz && rover->gz <= planeobjectz)
continue;
if (planecameraz > viewz && rover->pzt <= planeobjectz)
continue; continue;
} }

View file

@ -138,8 +138,7 @@ typedef struct vissprite_s
INT32 x1, x2; INT32 x1, x2;
fixed_t gx, gy; // for line side calculation fixed_t gx, gy; // for line side calculation
fixed_t gz, gzt; // global bottom/top for silhouette clipping fixed_t gz, gzt; // global bottom/top for silhouette clipping and sorting with 3D floors
fixed_t pz, pzt; // physical bottom/top for sorting with 3D floors
fixed_t startfrac; // horizontal position of x1 fixed_t startfrac; // horizontal position of x1
fixed_t scale, sortscale; // sortscale only differs from scale for paper sprites and MF2_LINKDRAW fixed_t scale, sortscale; // sortscale only differs from scale for paper sprites and MF2_LINKDRAW
@ -171,8 +170,8 @@ typedef struct vissprite_s
fixed_t xscale; fixed_t xscale;
// Precalculated top and bottom screen coords for the sprite. // Precalculated top and bottom screen coords for the sprite.
fixed_t thingheight; // The actual height of the thing (for 3D floors)
sector_t *sector; // The sector containing the thing. sector_t *sector; // The sector containing the thing.
fixed_t pt, pb; // plane heights, also for sorting against 3D floors
INT16 sz, szt; INT16 sz, szt;
spritecut_e cut; spritecut_e cut;