- split off sprite clipping adjustment code into its own function.

This commit is contained in:
Christoph Oelckers 2014-08-03 10:22:12 +02:00
parent 1b55c17379
commit 398d902e7e
3 changed files with 101 additions and 88 deletions

View file

@ -489,6 +489,103 @@ void GLSprite::SetSpriteColor(sector_t *sector, fixed_t center_y)
// //
//========================================================================== //==========================================================================
void GLSprite::PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_t thingy, float spriteheight)
{
bool smarterclip = false; // Set to true if one condition triggers the test below
if (((thing->player || thing->flags3&MF3_ISMONSTER ||
thing->IsKindOf(RUNTIME_CLASS(AInventory))) && (thing->flags&MF_ICECORPSE ||
!(thing->flags&MF_CORPSE))) || (gl_spriteclip == 3 && (smarterclip = true)) || gl_spriteclip > 1)
{
float btm = 1000000.0f;
float top = -1000000.0f;
extsector_t::xfloor &x = thing->Sector->e->XFloor;
if (x.ffloors.Size())
{
for (unsigned int i = 0; i < x.ffloors.Size(); i++)
{
F3DFloor * ff = x.ffloors[i];
fixed_t floorh = ff->top.plane->ZatPoint(thingx, thingy);
fixed_t ceilingh = ff->bottom.plane->ZatPoint(thingx, thingy);
if (floorh == thing->floorz)
{
btm = FIXED2FLOAT(floorh);
}
if (ceilingh == thing->ceilingz)
{
top = FIXED2FLOAT(ceilingh);
}
if (btm != 1000000.0f && top != -1000000.0f)
{
break;
}
}
}
else if (thing->Sector->heightsec && !(thing->Sector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC))
{
if (thing->flags2&MF2_ONMOBJ && thing->floorz ==
thing->Sector->heightsec->floorplane.ZatPoint(thingx, thingy))
{
btm = FIXED2FLOAT(thing->floorz);
top = FIXED2FLOAT(thing->ceilingz);
}
}
if (btm == 1000000.0f)
btm = FIXED2FLOAT(thing->Sector->floorplane.ZatPoint(thingx, thingy) - thing->floorclip);
if (top == -1000000.0f)
top = FIXED2FLOAT(thing->Sector->ceilingplane.ZatPoint(thingx, thingy));
float diffb = z2 - btm;
float difft = z1 - top;
if (diffb >= 0 /*|| !gl_sprite_clip_to_floor*/) diffb = 0;
// Adjust sprites clipping into ceiling and adjust clipping adjustment for tall graphics
if (smarterclip)
{
// Reduce slightly clipping adjustment of corpses
if (thing->flags & MF_CORPSE || spriteheight > fabs(diffb))
{
float ratio = clamp<float>((fabs(diffb) * (float)gl_sclipfactor / (spriteheight + 1)), 0.5, 1.0);
diffb *= ratio;
}
if (!diffb)
{
if (difft <= 0) difft = 0;
if (difft >= (float)gl_sclipthreshold)
{
// dumb copy of the above.
if (!(thing->flags3&MF3_ISMONSTER) || (thing->flags&MF_NOGRAVITY) || (thing->flags&MF_CORPSE) || difft > (float)gl_sclipthreshold)
{
difft = 0;
}
}
if (spriteheight > fabs(difft))
{
float ratio = clamp<float>((fabs(difft) * (float)gl_sclipfactor / (spriteheight + 1)), 0.5, 1.0);
difft *= ratio;
}
z2 -= difft;
z1 -= difft;
}
}
if (diffb <= (0 - (float)gl_sclipthreshold)) // such a large displacement can't be correct!
{
// for living monsters standing on the floor allow a little more.
if (!(thing->flags3&MF3_ISMONSTER) || (thing->flags&MF_NOGRAVITY) || (thing->flags&MF_CORPSE) || diffb < (-1.8*(float)gl_sclipthreshold))
{
diffb = 0;
}
}
z2 -= diffb;
z1 -= diffb;
}
}
//==========================================================================
//
//
//
//==========================================================================
void GLSprite::Process(AActor* thing,sector_t * sector) void GLSprite::Process(AActor* thing,sector_t * sector)
{ {
sector_t rs; sector_t rs;
@ -610,95 +707,9 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
float spriteheight = FIXED2FLOAT(spritescaleY) * gltexture->GetScaledHeightFloat(GLUSE_SPRITE); float spriteheight = FIXED2FLOAT(spritescaleY) * gltexture->GetScaledHeightFloat(GLUSE_SPRITE);
// Tests show that this doesn't look good for many decorations and corpses // Tests show that this doesn't look good for many decorations and corpses
if (spriteheight>0 && gl_spriteclip>0) if (spriteheight > 0 && gl_spriteclip > 0 && (thing->renderflags & RF_SPRITETYPEMASK) == RF_FACESPRITE)
{ {
bool smarterclip = false; // Set to true if one condition triggers the test below PerformSpriteClipAdjustment(thing, thingx, thingy, spriteheight);
if (((thing->player || thing->flags3&MF3_ISMONSTER ||
thing->IsKindOf(RUNTIME_CLASS(AInventory))) && (thing->flags&MF_ICECORPSE ||
!(thing->flags&MF_CORPSE))) || (gl_spriteclip==3 && (smarterclip = true)) || gl_spriteclip > 1)
{
float btm= 1000000.0f;
float top=-1000000.0f;
extsector_t::xfloor &x = thing->Sector->e->XFloor;
if (x.ffloors.Size())
{
for(unsigned int i=0;i<x.ffloors.Size();i++)
{
F3DFloor * ff=x.ffloors[i];
fixed_t floorh=ff->top.plane->ZatPoint(thingx, thingy);
fixed_t ceilingh=ff->bottom.plane->ZatPoint(thingx, thingy);
if (floorh==thing->floorz)
{
btm=FIXED2FLOAT(floorh);
}
if (ceilingh==thing->ceilingz)
{
top=FIXED2FLOAT(ceilingh);
}
if (btm != 1000000.0f && top != -1000000.0f)
{
break;
}
}
}
else if (thing->Sector->heightsec && !(thing->Sector->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC))
{
if (thing->flags2&MF2_ONMOBJ && thing->floorz==
thing->Sector->heightsec->floorplane.ZatPoint(thingx, thingy))
{
btm=FIXED2FLOAT(thing->floorz);
top=FIXED2FLOAT(thing->ceilingz);
}
}
if (btm==1000000.0f)
btm= FIXED2FLOAT(thing->Sector->floorplane.ZatPoint(thingx, thingy)-thing->floorclip);
if (top==-1000000.0f)
top= FIXED2FLOAT(thing->Sector->ceilingplane.ZatPoint(thingx, thingy));
float diffb = z2 - btm;
float difft = z1 - top;
if (diffb >= 0 /*|| !gl_sprite_clip_to_floor*/) diffb = 0;
// Adjust sprites clipping into ceiling and adjust clipping adjustment for tall graphics
if (smarterclip)
{
// Reduce slightly clipping adjustment of corpses
if (thing->flags & MF_CORPSE || spriteheight > fabs(diffb))
{
float ratio = clamp<float>((fabs(diffb) * (float)gl_sclipfactor/(spriteheight+1)), 0.5, 1.0);
diffb*=ratio;
}
if (!diffb)
{
if (difft <= 0) difft = 0;
if (difft >= (float)gl_sclipthreshold)
{
// dumb copy of the above.
if (!(thing->flags3&MF3_ISMONSTER) || (thing->flags&MF_NOGRAVITY) || (thing->flags&MF_CORPSE) || difft > (float)gl_sclipthreshold)
{
difft=0;
}
}
if (spriteheight > fabs(difft))
{
float ratio = clamp<float>((fabs(difft) * (float)gl_sclipfactor/(spriteheight+1)), 0.5, 1.0);
difft*=ratio;
}
z2-=difft;
z1-=difft;
}
}
if (diffb <= (0 - (float)gl_sclipthreshold)) // such a large displacement can't be correct!
{
// for living monsters standing on the floor allow a little more.
if (!(thing->flags3&MF3_ISMONSTER) || (thing->flags&MF_NOGRAVITY) || (thing->flags&MF_CORPSE) || diffb<(-1.8*(float)gl_sclipthreshold))
{
diffb=0;
}
}
z2-=diffb;
z1-=diffb;
}
} }
float viewvecX = GLRenderer->mViewVector.X; float viewvecX = GLRenderer->mViewVector.X;
float viewvecY = GLRenderer->mViewVector.Y; float viewvecY = GLRenderer->mViewVector.Y;

View file

@ -324,6 +324,7 @@ public:
void SplitSprite(sector_t * frontsector, bool translucent); void SplitSprite(sector_t * frontsector, bool translucent);
void SetLowerParam(); void SetLowerParam();
void PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_t thingy, float spriteheight);
public: public:

View file

@ -1858,6 +1858,7 @@ void P_SpawnThings (int position)
{ {
SetMapThingUserData(actor, *udi); SetMapThingUserData(actor, *udi);
} }
if (actor != NULL) actor->renderflags |= RF_WALLSPRITE;
} }
for(int i=0; i<MAXPLAYERS; i++) for(int i=0; i<MAXPLAYERS; i++)
{ {