From f479f995a194170047542c22fc0bfeda92b0407d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 6 Dec 2022 20:49:49 +0100 Subject: [PATCH] - transitioned all tileLeftOffset and tileTopOffset calls to use the texture manager. --- source/build/src/clip.cpp | 7 ++++--- source/core/actorlist.cpp | 6 ++++-- source/core/automap.cpp | 19 +++++++++++------- source/core/defparser.cpp | 7 ++++--- source/core/textures/buildtiles.h | 14 ------------- source/games/blood/src/animatesprite.cpp | 9 ++++++--- source/games/blood/src/db.h | 7 +++++-- source/games/blood/src/hudsprites.cpp | 3 ++- source/games/blood/src/nnexts.cpp | 12 ++++++++++-- source/games/blood/src/seq.cpp | 4 +++- source/games/exhumed/src/2d.cpp | 5 +++-- source/games/sw/src/game.h | 25 +++++++++++++----------- source/games/sw/src/skull.cpp | 6 ++++-- 13 files changed, 71 insertions(+), 53 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index fcba3addb..169480496 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -11,6 +11,7 @@ #include "printf.h" #include "gamefuncs.h" #include "coreactor.h" +#include "texturemanager.h" enum { MAXCLIPDIST = 1024 }; @@ -463,12 +464,12 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, continue; // the rest is for slope sprites only. - const int32_t tilenum = actor->spr.picnum; + auto tex = TexMan.GetGameTexture(actor->spr.spritetexture()); const int32_t cosang = bcos(actor->int_ang()); const int32_t sinang = bsin(actor->int_ang()); - vec2_t const span = { tileWidth(tilenum), tileHeight(tilenum) }; + vec2_t const span = { (int)tex->GetDisplayWidth(), (int)tex->GetDisplayHeight() }; vec2_t const repeat = { int(actor->spr.scale.X * scaletoint), int(actor->spr.scale.Y * scaletoint) }; - vec2_t adjofs = { tileLeftOffset(tilenum), tileTopOffset(tilenum) }; + vec2_t adjofs = { (int)tex->GetDisplayTopOffset(), (int)tex->GetDisplayTopOffset() }; if (actor->spr.cstat & CSTAT_SPRITE_XFLIP) adjofs.X = -adjofs.X; diff --git a/source/core/actorlist.cpp b/source/core/actorlist.cpp index b02cae2a4..08c75fe60 100644 --- a/source/core/actorlist.cpp +++ b/source/core/actorlist.cpp @@ -37,6 +37,7 @@ #include "gamefuncs.h" #include "raze_sound.h" #include "vm.h" +#include "texturemanager.h" // Doubly linked ring list of Actors @@ -528,9 +529,10 @@ size_t DCoreActor::PropagateMark() double DCoreActor::GetOffsetAndHeight(double& height) { + auto tex = TexMan.GetGameTexture(spr.spritetexture()); double yscale = spr.scale.Y; - height = tileHeight(spr.picnum) * yscale; + height = tex->GetDisplayHeight() * yscale; double zofs = (spr.cstat & CSTAT_SPRITE_YCENTER) ? height * 0.5 : 0; - return zofs - tileTopOffset(spr.picnum) * yscale; + return zofs - tex->GetDisplayTopOffset() * yscale; } diff --git a/source/core/automap.cpp b/source/core/automap.cpp index 6b209ba39..48eeb2364 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -47,6 +47,8 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "gamefuncs.h" #include "hw_sections.h" #include "coreactor.h" +#include "texturemanager.h" + CVAR(Bool, am_followplayer, true, CVAR_ARCHIVE) CVAR(Bool, am_rotate, true, CVAR_ARCHIVE) CVAR(Float, am_linealpha, 1.0f, CVAR_ARCHIVE) @@ -637,15 +639,16 @@ void DrawAutomapAlignmentFacing(const spritetype& spr, const DVector2& bpos, con //--------------------------------------------------------------------------- // -// Draws lines for alls in Duke/SW when cstat is CSTAT_SPRITE_ALIGNMENT_WALL. +// Draws lines for sprites in Duke/SW when cstat is CSTAT_SPRITE_ALIGNMENT_WALL. // //--------------------------------------------------------------------------- void DrawAutomapAlignmentWall(const spritetype& spr, const DVector2& bpos, const DVector2& cangvect, const double czoom, const DVector2& xydim, const PalEntry& col) { + auto tex = TexMan.GetGameTexture(spr.spritetexture()); auto xrep = spr.scale.X; - auto xspan = tileWidth(spr.picnum); - auto xoff = tileLeftOffset(spr.picnum) + spr.xoffset; + int xspan = (int)tex->GetDisplayWidth(); + int xoff = (int)tex->GetDisplayLeftOffset() + spr.xoffset; if ((spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff; @@ -669,12 +672,14 @@ void DrawAutomapAlignmentWall(const spritetype& spr, const DVector2& bpos, const void DrawAutomapAlignmentFloor(const spritetype& spr, const DVector2& bpos, const DVector2& cangvect, const double czoom, const DVector2& xydim, const PalEntry& col) { + auto tex = TexMan.GetGameTexture(spr.spritetexture()); + auto xrep = spr.scale.X; auto yrep = spr.scale.Y; - auto xspan = tileWidth(spr.picnum); - auto yspan = tileHeight(spr.picnum); - auto xoff = tileLeftOffset(spr.picnum); - auto yoff = tileTopOffset(spr.picnum); + int xspan = (int)tex->GetDisplayWidth(); + int yspan = (int)tex->GetDisplayHeight(); + int xoff = (int)tex->GetDisplayLeftOffset(); + int yoff = (int)tex->GetDisplayTopOffset(); if (isSWALL() || (spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLOPE) { diff --git a/source/core/defparser.cpp b/source/core/defparser.cpp index e46e4c9f2..9c096885d 100644 --- a/source/core/defparser.cpp +++ b/source/core/defparser.cpp @@ -160,12 +160,13 @@ void processTileImport(const char* cmd, FScriptPosition& pos, TileImport& imp) // This is not quite the same as originally, for two reasons: // 1: Since these are texture properties now, there's no need to clear them. // 2: The original code assumed that an imported texture cannot have an offset. But this can import Doom patches and PNGs with grAb, so the situation is very different. - if (imp.xoffset == INT_MAX) imp.xoffset = tileLeftOffset(imp.tile); + auto tex = tileGetTexture(imp.tile); + + if (imp.xoffset == INT_MAX) imp.xoffset = tex->GetTexelLeftOffset(); else imp.xoffset = clamp(imp.xoffset, -128, 127); - if (imp.yoffset == INT_MAX) imp.yoffset = tileTopOffset(imp.tile); + if (imp.yoffset == INT_MAX) imp.yoffset = tex->GetTexelTopOffset(); else imp.yoffset = clamp(imp.yoffset, -128, 127); - auto tex = tileGetTexture(imp.tile); if (tex) { tex->SetOffsets(imp.xoffset, imp.yoffset); diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index 8daebe67f..befd841a5 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -394,20 +394,6 @@ inline int tileHeight(int num) return (int)TileFiles.tiledata[num].texture->GetDisplayHeight(); } -inline int tileLeftOffset(int num) -{ - assert((unsigned)num < MAXTILES); - if ((unsigned)num >= MAXTILES) return 0; - return (int)TileFiles.tiledata[num].texture->GetDisplayLeftOffset(); -} - -inline int tileTopOffset(int num) -{ - assert((unsigned)num < MAXTILES); - if ((unsigned)num >= MAXTILES) return 0; - return (int)TileFiles.tiledata[num].texture->GetDisplayTopOffset(); -} - int tileAnimateOfs(int tilenum, int randomize = -1); inline void tileUpdatePicnum(int* const tileptr, bool mayrotate = false, int randomize = -1) diff --git a/source/games/blood/src/animatesprite.cpp b/source/games/blood/src/animatesprite.cpp index 81f90b5c0..11c8c45ba 100644 --- a/source/games/blood/src/animatesprite.cpp +++ b/source/games/blood/src/animatesprite.cpp @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "v_font.h" #include "hw_voxels.h" #include "gamefuncs.h" +#include "texturemanager.h" #include "models/modeldata.h" BEGIN_BLD_NS @@ -389,8 +390,9 @@ static tspritetype* viewAddEffect(tspriteArray& tsprites, int nTSprite, VIEW_EFF if (!VanillaMode() && (pTSprite->type == kThingDroppedLifeLeech)) // fix shadow for thrown lifeleech pNSprite->picnum = 800; pNSprite->pal = 5; - int height = tileHeight(pNSprite->picnum); - int center = height / 2 + tileTopOffset(pNSprite->picnum); + auto tex = TexMan.GetGameTexture(pNSprite->spritetexture()); + double height = tex->GetDisplayHeight(); + double center = height / 2 + tex->GetDisplayTopOffset(); pNSprite->pos.Z -= (pNSprite->scale.Y) * (height - center); break; } @@ -636,7 +638,8 @@ void viewProcessSprites(tspriteArray& tsprites, const DVector3& cPos, DAngle cA, { pTSprite->cstat |= CSTAT_SPRITE_ALIGNMENT_SLAB; pTSprite->cstat &= ~(CSTAT_SPRITE_XFLIP | CSTAT_SPRITE_YFLIP); - pTSprite->yoffset += tileTopOffset(pTSprite->picnum); + auto tex = TexMan.GetGameTexture(pTSprite->spritetexture()); + pTSprite->yoffset += (uint8_t)tex->GetDisplayTopOffset(); pTSprite->picnum = tprops[pTSprite->spritetexture()].voxelIndex; if ((picanm[nTile].extra & 7) == 7) { diff --git a/source/games/blood/src/db.h b/source/games/blood/src/db.h index 448ebde1f..da0e3122e 100644 --- a/source/games/blood/src/db.h +++ b/source/games/blood/src/db.h @@ -22,7 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //------------------------------------------------------------------------- #pragma once +#include #include "mapstructs.h" +#include "texturemanager.h" BEGIN_BLD_NS @@ -85,8 +87,9 @@ void GetSpriteExtents(spritetypebase const* const pSprite, double* top, double* *top = *bottom = pSprite->pos.Z; if ((pSprite->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_FLOOR) { - int height = tileHeight(pSprite->picnum); - int center = height / 2 + tileTopOffset(pSprite->picnum); + auto tex = TexMan.GetGameTexture(pSprite->spritetexture()); + double height = tex->GetDisplayHeight(); + double center = height / 2 + tex->GetDisplayTopOffset(); *top -= pSprite->scale.Y * center; *bottom += pSprite->scale.Y * (height - center); } diff --git a/source/games/blood/src/hudsprites.cpp b/source/games/blood/src/hudsprites.cpp index 68e68d97a..eb9686b89 100644 --- a/source/games/blood/src/hudsprites.cpp +++ b/source/games/blood/src/hudsprites.cpp @@ -88,7 +88,8 @@ static void viewBurnTime(int gScale) for (int i = 0; i < 9; i++) { - int nTile = burnTable[i].nTile + tileAnimateOfs(burnTable[i].nTile, i); + int nTile = burnTable[i].nTile; + tileUpdatePicnum(&nTile); int nScale = burnTable[i].nScale; if (gScale < 600) { diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 7d8923b54..c80d17762 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -3311,8 +3311,12 @@ void useEffectGen(DBloodActor* sourceactor, DBloodActor* actor) pos = bottom; break; case 2: // middle - pos = actor->spr.pos.Z + (tileHeight(actor->spr.picnum) / 2 + tileTopOffset(actor->spr.picnum)) * actor->spr.scale.Y; + { + auto tex = TexMan.GetGameTexture(actor->spr.spritetexture()); + double center = tex->GetDisplayHeight() / 2 + tex->GetDisplayTopOffset(); + pos = actor->spr.pos.Z + center * actor->spr.scale.Y; break; + } case 3: case 4: if (actor->insector()) @@ -3752,9 +3756,13 @@ void useSeqSpawnerGen(DBloodActor* sourceactor, int objType, sectortype* pSector pos.Z = top; break; case 4: + { // this had no value shift and no repeat handling, which looks like a bug. - pos.Z += (tileHeight(iactor->spr.picnum) / 2 + tileTopOffset(iactor->spr.picnum)) * iactor->spr.scale.Y; + auto tex = TexMan.GetGameTexture(iactor->spr.spritetexture()); + double center = tex->GetDisplayHeight() / 2 + tex->GetDisplayTopOffset(); + pos.Z += center * iactor->spr.scale.Y; break; + } case 5: case 6: if (!iactor->insector()) pos.Z = top; diff --git a/source/games/blood/src/seq.cpp b/source/games/blood/src/seq.cpp index c98ce9bb6..f19ee25af 100644 --- a/source/games/blood/src/seq.cpp +++ b/source/games/blood/src/seq.cpp @@ -246,7 +246,9 @@ void UpdateSprite(DBloodActor* actor, SEQFRAME* pFrame) assert(actor->hasX()); if (actor->spr.flags & 2) { - if (tileHeight(actor->spr.picnum) != tileHeight(seqGetTile(pFrame)) || tileTopOffset(actor->spr.picnum) != tileTopOffset(seqGetTile(pFrame)) + auto atex = TexMan.GetGameTexture(actor->spr.spritetexture()); + auto stex = TexMan.GetGameTexture(seqGetTexture(pFrame)); + if (atex->GetDisplayHeight() != stex->GetDisplayHeight() || atex->GetDisplayTopOffset() != stex->GetDisplayTopOffset() || (pFrame->scaley && pFrame->scaley != int(actor->spr.scale.Y * INV_REPEAT_SCALE))) actor->spr.flags |= 4; } diff --git a/source/games/exhumed/src/2d.cpp b/source/games/exhumed/src/2d.cpp index 4a0efb73a..6522fff96 100644 --- a/source/games/exhumed/src/2d.cpp +++ b/source/games/exhumed/src/2d.cpp @@ -62,8 +62,9 @@ void DrawAbs(int tile, double x, double y, int shade = 0) void DrawRel(int tile, double x, double y, int shade) { // This is slightly different than what the backend does here, but critical for some graphics. - int offx = (tileWidth(tile) >> 1) + tileLeftOffset(tile); - int offy = (tileHeight(tile) >> 1) + tileTopOffset(tile); + auto tex = tileGetTexture(tile); + int offx = (int(tex->GetDisplayWidth()) >> 1) + int(tex->GetDisplayLeftOffset()); + int offy = (int(tex->GetDisplayHeight()) >> 1) + int(tex->GetDisplayTopOffset()); DrawAbs(tile, x - offx, y - offy, shade); } diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 72e5cd2ed..823deccaf 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -47,6 +47,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "packet.h" #include "gameinput.h" #include "serialize_obj.h" +#include "texturemanager.h" EXTERN_CVAR(Bool, sw_ninjahack) EXTERN_CVAR(Bool, sw_darts) @@ -202,24 +203,23 @@ constexpr int NORM_ANGLE(int ang) { return ((ang) & 2047); } int StdRandomRange(int range); -inline double GetSpriteSizeZ(const spritetypebase* sp) -{ - return (tileHeight(sp->picnum) * sp->scale.Y); -} - // actual Z for TOS and BOS - handles both WYSIWYG and old style inline double GetSpriteZOfTop(const spritetypebase* sp) { + auto tex = TexMan.GetGameTexture(sp->spritetexture()); + auto sizez = tex->GetDisplayHeight() * sp->scale.Y; return (sp->cstat & CSTAT_SPRITE_YCENTER) ? - sp->pos.Z - ((GetSpriteSizeZ(sp) * 0.5) + tileTopOffset(sp->picnum)) : - sp->pos.Z - GetSpriteSizeZ(sp); + sp->pos.Z - ((sizez * 0.5) + tex->GetDisplayTopOffset()) : + sp->pos.Z - sizez; } inline double GetSpriteZOfBottom(const spritetypebase* sp) { + auto tex = TexMan.GetGameTexture(sp->spritetexture()); + auto sizez = tex->GetDisplayHeight() * sp->scale.Y; return (sp->cstat & CSTAT_SPRITE_YCENTER) ? - sp->pos.Z + ((GetSpriteSizeZ(sp) * 0.5) - tileTopOffset(sp->picnum)) : + sp->pos.Z + ((sizez * 0.5) - tex->GetDisplayTopOffset()) : sp->pos.Z; } @@ -2071,12 +2071,14 @@ inline DVector3 ActorLowerVect(DSWActor* actor) // Z size of top (TOS) and bottom (BOS) part of sprite inline double ActorSizeToTop(DSWActor* a) { - return (ActorSizeZ(a) + tileTopOffset(a->spr.picnum)) * 0.5; + auto tex = TexMan.GetGameTexture(a->spr.spritetexture()); + return (ActorSizeZ(a) + tex->GetDisplayTopOffset()) * 0.5; } inline void SetActorSizeX(DSWActor* sp) { - sp->clipdist = tileWidth(sp->spr.picnum) * sp->spr.scale.X * 0.25; + auto tex = TexMan.GetGameTexture(sp->spr.spritetexture()); + sp->clipdist = tex->GetDisplayWidth() * sp->spr.scale.X * 0.25; } inline bool Facing(DSWActor* actor1, DSWActor* actor2) @@ -2087,7 +2089,8 @@ inline bool Facing(DSWActor* actor1, DSWActor* actor2) // Given a z height and sprite return the correct y repeat value inline int GetRepeatFromHeight(DSWActor* sp, double zh) { - return int(zh * 64) / tileHeight(sp->spr.picnum); + auto tex = TexMan.GetGameTexture(sp->spr.spritetexture()); + return int(zh * 64) / int(tex->GetDisplayHeight()); } inline bool SpriteInDiveArea(DSWActor* a) diff --git a/source/games/sw/src/skull.cpp b/source/games/sw/src/skull.cpp index 847910267..d402fde61 100644 --- a/source/games/sw/src/skull.cpp +++ b/source/games/sw/src/skull.cpp @@ -240,7 +240,8 @@ int SetupSkull(DSWActor* actor) if (ActorZOfBottom(actor) > actor->user.loz - 16) { - actor->spr.pos.Z = actor->user.loz + tileTopOffset(actor->spr.picnum); + auto tex = TexMan.GetGameTexture(actor->spr.spritetexture()); + actor->spr.pos.Z = actor->user.loz + tex->GetDisplayTopOffset(); actor->user.loz = actor->spr.pos.Z; // leave 8 pixels above the ground @@ -658,7 +659,8 @@ int SetupBetty(DSWActor* actor) if (ActorZOfBottom(actor) > actor->user.loz - 16) { - actor->spr.pos.Z = actor->user.loz + tileTopOffset(actor->spr.picnum); + auto tex = TexMan.GetGameTexture(actor->spr.spritetexture()); + actor->spr.pos.Z = actor->user.loz + tex->GetDisplayTopOffset(); actor->user.loz = actor->spr.pos.Z; // leave 8 pixels above the ground