From 0bacb05c1bca204ef5fa534f2fdc6cf53f34e3c6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 7 Dec 2022 15:57:28 +0100 Subject: [PATCH] - wrapped hiofs in a getter function. This makes it a lot easier later to refactor. --- source/core/gamefuncs.cpp | 18 ++++++++++-------- source/core/rendering/scene/hw_sprites.cpp | 13 +++++++------ source/core/rendering/scene/hw_walls.cpp | 7 ++++--- source/core/textures/buildtiles.cpp | 8 ++++++++ source/core/textures/buildtiles.h | 1 + 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index b133ac230..d3716abee 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -205,10 +205,11 @@ void GetWallSpritePosition(const spritetypebase* spr, const DVector2& pos, DVect auto tex = TexMan.GetGameTexture(spr->spritetexture()); double width, xoffset; - if (render && hw_hightile && TileFiles.tiledata[spr->picnum].hiofs.xsize) + TileOffs* tofs; + if (render && hw_hightile && (tofs = GetHiresOffset(spr->spritetexture()))) { - width = TileFiles.tiledata[spr->picnum].hiofs.xsize; - xoffset = (TileFiles.tiledata[spr->picnum].hiofs.xoffs + spr->xoffset); + width = tofs->xsize; + xoffset = (tofs->xoffs + spr->xoffset); } else { @@ -244,12 +245,13 @@ void TGetFlatSpritePosition(const spritetypebase* spr, const DVector2& pos, DVec int xo = heinum ? 0 : spr->xoffset; int yo = heinum ? 0 : spr->yoffset; - if (render && hw_hightile && TileFiles.tiledata[spr->picnum].hiofs.xsize) + TileOffs* tofs; + if (render && hw_hightile && (tofs = GetHiresOffset(spr->spritetexture()))) { - width = TileFiles.tiledata[spr->picnum].hiofs.xsize * xrepeat; - height = TileFiles.tiledata[spr->picnum].hiofs.ysize * yrepeat; - leftofs = (TileFiles.tiledata[spr->picnum].hiofs.xoffs + xo) * xrepeat; - topofs = (TileFiles.tiledata[spr->picnum].hiofs.yoffs + yo) * yrepeat; + width = tofs->xsize * xrepeat; + height = tofs->ysize * yrepeat; + leftofs = (tofs->xoffs + xo) * xrepeat; + topofs = (tofs->yoffs + yo) * yrepeat; } else { diff --git a/source/core/rendering/scene/hw_sprites.cpp b/source/core/rendering/scene/hw_sprites.cpp index ccf8bb331..3d5b86c35 100644 --- a/source/core/rendering/scene/hw_sprites.cpp +++ b/source/core/rendering/scene/hw_sprites.cpp @@ -343,15 +343,16 @@ void HWSprite::Process(HWDrawInfo* di, tspritetype* spr, sectortype* sector, int if (modelframe == 0) { int flags = spr->cstat; - int tilenum = spr->picnum; int xsize, ysize, tilexoff, tileyoff; - if (hw_hightile && TileFiles.tiledata[tilenum].hiofs.xsize) + TileOffs* tofs; + + if (hw_hightile && (tofs = GetHiresOffset(spr->spritetexture()))) { - xsize = TileFiles.tiledata[tilenum].hiofs.xsize; - ysize = TileFiles.tiledata[tilenum].hiofs.ysize; - tilexoff = TileFiles.tiledata[tilenum].hiofs.xoffs; - tileyoff = TileFiles.tiledata[tilenum].hiofs.yoffs; + xsize = tofs->xsize; + ysize = tofs->ysize; + tilexoff = tofs->xoffs; + tileyoff = tofs->yoffs; } else { diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index c3407156c..6ce704d1b 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -1163,11 +1163,12 @@ void HWWall::ProcessWallSprite(HWDrawInfo* di, tspritetype* spr, sectortype* sec SetSpriteTranslucency(Sprite, alpha, RenderStyle); + TileOffs* tofs; int height, topofs; - if (hw_hightile && TileFiles.tiledata[spr->picnum].hiofs.xsize) + if (hw_hightile && (tofs = GetHiresOffset(spr->spritetexture()))) { - height = TileFiles.tiledata[spr->picnum].hiofs.ysize; - topofs = (TileFiles.tiledata[spr->picnum].hiofs.yoffs + spr->yoffset); + height = tofs->ysize; + topofs = tofs->yoffs + spr->yoffset; } else { diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index 3edf86661..622317b07 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -810,3 +810,11 @@ void walltype::setovertexture(FTextureID tex) if (p) overpicnum = *p; else overpicnum = -1; // unlike the others this one can be invalid. } + +TileOffs* GetHiresOffset(FTextureID tex) +{ + // fixme: This must return nullptr if the tile has no replacement. + auto p = TileFiles.textotile.CheckKey(tex.GetIndex()); + if (p && TileFiles.tiledata[*p].hiofs.xsize != 0) return &TileFiles.tiledata[*p].hiofs; + else return nullptr; +} diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index c10fb5ffe..6a667e6b0 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -430,6 +430,7 @@ void tileUpdateAnimations(); const uint8_t* GetRawPixels(FTextureID texid); uint8_t* GetWritablePixels(FTextureID texid); void InvalidateTexture(FTextureID num); +TileOffs* GetHiresOffset(FTextureID num); class FGameTexture; bool PickTexture(FGameTexture* tex, int paletteid, TexturePick& pick, bool wantindexed = false);