From 398d902e7e527f78d109ff70eed53676ce63e9aa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 Aug 2014 10:22:12 +0200 Subject: [PATCH] - split off sprite clipping adjustment code into its own function. --- src/gl/scene/gl_sprite.cpp | 187 ++++++++++++++++++++----------------- src/gl/scene/gl_wall.h | 1 + src/p_setup.cpp | 1 + 3 files changed, 101 insertions(+), 88 deletions(-) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 0ba386b1a..f420256f3 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -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((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((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) { sector_t rs; @@ -610,95 +707,9 @@ void GLSprite::Process(AActor* thing,sector_t * sector) float spriteheight = FIXED2FLOAT(spritescaleY) * gltexture->GetScaledHeightFloat(GLUSE_SPRITE); // 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 - 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;itop.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((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((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; - } + PerformSpriteClipAdjustment(thing, thingx, thingy, spriteheight); } float viewvecX = GLRenderer->mViewVector.X; float viewvecY = GLRenderer->mViewVector.Y; diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index e53513167..2fecf1d60 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -324,6 +324,7 @@ public: void SplitSprite(sector_t * frontsector, bool translucent); void SetLowerParam(); + void PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_t thingy, float spriteheight); public: diff --git a/src/p_setup.cpp b/src/p_setup.cpp index a6dbca868..0312feba5 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1858,6 +1858,7 @@ void P_SpawnThings (int position) { SetMapThingUserData(actor, *udi); } + if (actor != NULL) actor->renderflags |= RF_WALLSPRITE; } for(int i=0; i