Bring back shadows on polyobjects

Also optimizes the method used so rings can show their shadows too. Using just the subsector is a tad bit imprecise admittedly but any more precise methods get really laggy.
This commit is contained in:
Sally Coolatta 2022-04-25 20:14:53 -04:00 committed by Eidolon
parent 8597f3876c
commit 48b3ea31c4
3 changed files with 34 additions and 61 deletions

View file

@ -256,6 +256,8 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out)
out->y = R_LerpFixed(mobj->old_y, mobj->y, frac);
out->z = R_LerpFixed(mobj->old_z, mobj->z, frac);
out->subsector = R_PointInSubsector(out->x, out->y);
if (mobj->player)
{
out->angle = R_LerpAngle(mobj->player->old_drawangle, mobj->player->drawangle, frac);
@ -271,6 +273,9 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst
out->x = R_LerpFixed(mobj->old_x, mobj->x, frac);
out->y = R_LerpFixed(mobj->old_y, mobj->y, frac);
out->z = R_LerpFixed(mobj->old_z, mobj->z, frac);
out->subsector = R_PointInSubsector(out->x, out->y);
out->angle = R_LerpAngle(mobj->old_angle, mobj->angle, frac);
}

View file

@ -53,6 +53,7 @@ typedef struct {
fixed_t x;
fixed_t y;
fixed_t z;
subsector_t *subsector;
angle_t angle;
} interpmobjstate_t;

View file

@ -1158,8 +1158,8 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope)
}
halfHeight = interp.z + (thing->height >> 1);
floorz = P_GetFloorZ(thing, thing->subsector->sector, interp.x, interp.y, NULL);
ceilingz = P_GetCeilingZ(thing, thing->subsector->sector, interp.x, interp.y, NULL);
floorz = P_GetFloorZ(thing, interp.subsector->sector, interp.x, interp.y, NULL);
ceilingz = P_GetCeilingZ(thing, interp.subsector->sector, interp.x, interp.y, NULL);
#define CHECKZ (isflipped ? z > halfHeight && z < groundz : z < halfHeight && z > groundz)
@ -1195,6 +1195,32 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope)
}
}
// Check polyobjects and see if groundz needs to be altered
{
// This isn't very precise, but the precise method was far too slow.
// (Polies are just naturally pretty flickery anyway :P)
polyobj_t *po = interp.subsector->polyList;
while (po)
{
if (!(po->flags & POF_RENDERPLANES) || !P_MobjInsidePolyobj(po, thing))
{
po = (polyobj_t *)(po->link.next);
continue;
}
// We're inside it! Yess...
z = isflipped ? po->lines[0]->backsector->floorheight : po->lines[0]->backsector->ceilingheight;
if CHECKZ
{
groundz = z;
groundslope = NULL;
}
po = (polyobj_t *)(po->link.next);
}
}
if (isflipped ? (ceilingz < groundz - (!groundslope ? 0 : FixedMul(abs(groundslope->zdelta), thing->radius*3/2)))
: (floorz > groundz + (!groundslope ? 0 : FixedMul(abs(groundslope->zdelta), thing->radius*3/2))))
{
@ -1202,65 +1228,6 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope)
groundslope = NULL;
}
#if 0 // Unfortunately, this drops CEZ2 down to sub-17 FPS on my i7.
// NOTE: this section was not updated to reflect reverse gravity support
// Check polyobjects and see if groundz needs to be altered, for rings only because they don't update floorz
if (thing->type == MT_RING)
{
INT32 xl, xh, yl, yh, bx, by;
xl = (unsigned)(interp.x - thing->radius - bmaporgx)>>MAPBLOCKSHIFT;
xh = (unsigned)(interp.x + thing->radius - bmaporgx)>>MAPBLOCKSHIFT;
yl = (unsigned)(interp.y - thing->radius - bmaporgy)>>MAPBLOCKSHIFT;
yh = (unsigned)(interp.y + thing->radius - bmaporgy)>>MAPBLOCKSHIFT;
BMBOUNDFIX(xl, xh, yl, yh);
validcount++;
for (by = yl; by <= yh; by++)
for (bx = xl; bx <= xh; bx++)
{
INT32 offset;
polymaplink_t *plink; // haleyjd 02/22/06
if (bx < 0 || by < 0 || bx >= bmapwidth || by >= bmapheight)
continue;
offset = by*bmapwidth + bx;
// haleyjd 02/22/06: consider polyobject lines
plink = polyblocklinks[offset];
while (plink)
{
polyobj_t *po = plink->po;
if (po->validcount != validcount) // if polyobj hasn't been checked
{
po->validcount = validcount;
if (!P_MobjInsidePolyobj(po, thing) || !(po->flags & POF_RENDERPLANES))
{
plink = (polymaplink_t *)(plink->link.next);
continue;
}
// We're inside it! Yess...
z = po->lines[0]->backsector->ceilingheight;
if (z < halfHeight && z > groundz)
{
groundz = z;
groundslope = NULL;
}
}
plink = (polymaplink_t *)(plink->link.next);
}
}
}
#endif
if (shadowslope != NULL)
*shadowslope = groundslope;