From 1b2a249243611071a3b2b6438f3c1161d3cbb25b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 20 May 2023 18:57:19 +0200 Subject: [PATCH] - got rid of all tile index constants in Exhumed. --- source/games/exhumed/src/2d.cpp | 4 ++-- source/games/exhumed/src/bullet.cpp | 2 +- source/games/exhumed/src/exhumed.cpp | 18 +++++++++++++++--- source/games/exhumed/src/exhumed.h | 2 +- source/games/exhumed/src/menu.cpp | 4 ++-- source/games/exhumed/src/namelist.h | 8 +++++++- source/games/exhumed/src/names.h | 2 ++ source/games/exhumed/src/object.cpp | 12 ++++++------ source/games/exhumed/src/ramses.cpp | 20 ++++++++++---------- source/games/exhumed/src/texidsdef.h | 27 ++++++++++++++++++++++++++- source/games/exhumed/src/view.cpp | 2 +- 11 files changed, 73 insertions(+), 28 deletions(-) diff --git a/source/games/exhumed/src/2d.cpp b/source/games/exhumed/src/2d.cpp index a2f1bea32..0ed2d76ef 100644 --- a/source/games/exhumed/src/2d.cpp +++ b/source/games/exhumed/src/2d.cpp @@ -125,10 +125,10 @@ void menu_DoPlasma() if (!PlasmaBuffer) { - auto pixels = GetWritablePixels(tileGetTextureID(kPlasmaTile1)); + auto pixels = GetWritablePixels(aTexIds[kTexPlasmaTile1]); memset(pixels, 96, kPlasmaWidth * kPlasmaHeight); - PlasmaBuffer = GetWritablePixels(tileGetTextureID(kPlasmaTile2)); + PlasmaBuffer = GetWritablePixels(aTexIds[kTexPlasmaTile2]); memset(PlasmaBuffer, 96, kPlasmaWidth * kPlasmaHeight); nSmokeLeft = 160 - logowidth / 2; diff --git a/source/games/exhumed/src/bullet.cpp b/source/games/exhumed/src/bullet.cpp index 983bb019e..036a7dcd1 100644 --- a/source/games/exhumed/src/bullet.cpp +++ b/source/games/exhumed/src/bullet.cpp @@ -463,7 +463,7 @@ HITSPRITE: else if (pHitWall != nullptr) { HITWALL: - if (pHitWall->walltexture == tileGetTextureID(kEnergy1)) + if (pHitWall->walltexture == aTexIds[kTexEnergy1]) { if (pHitWall->twoSided()) { diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 4f5ee2dff..34adf3505 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -222,7 +222,7 @@ void DrawClock() { int ebp = 49; - auto pixels = GetWritablePixels(tileGetTextureID(kClockTile)); + auto pixels = GetWritablePixels(aTexIds[kTexClockTile]); memset(pixels, TRANSPARENT_INDEX, 4096); @@ -237,11 +237,11 @@ void DrawClock() while (nVal) { int v2 = nVal & 0xF; - auto texid = tileGetTextureID(v2 + kClockSymbol1); + auto texid = aTexIds[v2 + kTexClockSymbol1]; auto tex = TexMan.GetGameTexture(texid); int yPos = 32 - tex->GetTexelHeight() / 2; - CopyTileToBitmap(texid, tileGetTextureID(kClockTile), ebp - tex->GetTexelWidth() / 2, yPos); + CopyTileToBitmap(texid, aTexIds[kTexClockTile], ebp - tex->GetTexelWidth() / 2, yPos); ebp -= 15; @@ -389,6 +389,18 @@ static void SetTileNames(TilesetBuildInfo& info) void GameInterface::SetupSpecialTextures(TilesetBuildInfo& info) { + // This is the ONLY place that should use tile indices! + enum + { + kPlasmaTile1 = 4092, + kPlasmaTile2 = 4093, + kClockTile = 3603, + kEnergy1 = 3604, + kEnergy2 = 3605, + kTileLoboLaptop = 3623, + kTileRamsesWorkTile = 591, + }; + SetTileNames(info); info.CreateWritable(kPlasmaTile1, kPlasmaWidth, kPlasmaHeight); info.CreateWritable(kPlasmaTile2, kPlasmaWidth, kPlasmaHeight); diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 8da51d8e5..bc13e8b8d 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -91,7 +91,7 @@ void InitEnergyTile(); void setvalidpic(DExhumedActor* actor) { // all we want here is setting it to something that passes renderer validation. This is never used to draw the sprite. - actor->spr.setspritetexture(tileGetTextureID(1)); + actor->spr.setspritetexture(aTexIds[kTexTorch1]); } extern int EndLevel; diff --git a/source/games/exhumed/src/menu.cpp b/source/games/exhumed/src/menu.cpp index 926283fb9..2349e183b 100644 --- a/source/games/exhumed/src/menu.cpp +++ b/source/games/exhumed/src/menu.cpp @@ -91,8 +91,8 @@ void DoEnergyTile() { nButtonColor += nButtonColor < 0 ? 8 : 0; - auto energy1 = GetWritablePixels(tileGetTextureID(kEnergy1)); - auto energy2 = GetWritablePixels(tileGetTextureID(kEnergy2)); + auto energy1 = GetWritablePixels(aTexIds[kTexEnergy1]); + auto energy2 = GetWritablePixels(aTexIds[kTexEnergy2]); uint8_t* ptr1 = energy1 + 1984; uint8_t* ptr2 = energy1 + 2048; diff --git a/source/games/exhumed/src/namelist.h b/source/games/exhumed/src/namelist.h index d88c26f26..6c087ada9 100644 --- a/source/games/exhumed/src/namelist.h +++ b/source/games/exhumed/src/namelist.h @@ -5,7 +5,13 @@ x(WeaponSpriteM60, 490) x(WeaponSpriteFlamethrower, 491) x(TileRamsesGold, 590) x(TileRamsesWorkTile, 591) -x(TileRamsesNormal, 592) +x(TileRamsesNormal1, 592) +x(TileRamsesNormal2, 593) +x(TileRamsesNormal3, 594) +x(TileRamsesNormal4, 595) +x(TileRamsesMouth1, 598) +x(TileRamsesMouth2, 599) +x(TileRamsesMouth3, 600) x(TileStatusBar, 657) x(KeyIcon1, 675) x(KeyIcon2, 679) diff --git a/source/games/exhumed/src/names.h b/source/games/exhumed/src/names.h index 2b41a34dd..a6d69cbc2 100644 --- a/source/games/exhumed/src/names.h +++ b/source/games/exhumed/src/names.h @@ -20,12 +20,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS +/* #define x(a, b) k##a = b, enum { #include "namelist.h" }; #undef x +*/ END_PS_NS diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index 4ae22a026..d1e96084c 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -1398,7 +1398,7 @@ DExhumedActor* BuildSpark(DExhumedActor* pActor, int nVal) if (nVal >= 2) { - pSpark->spr.setspritetexture(aTexIds[kTexENERGY2]); + pSpark->spr.setspritetexture(aTexIds[kTexEnergy2]); nSmokeSparks++; if (nVal == 3) @@ -1466,7 +1466,7 @@ void AISpark::Tick(RunListEvent* ev) BuildSpark(pActor, 2); } - if (pActor->spr.spritetexture() == aTexIds[kTexENERGY2]) { + if (pActor->spr.spritetexture() == aTexIds[kTexEnergy2]) { return; } @@ -1486,7 +1486,7 @@ void AISpark::Tick(RunListEvent* ev) pActor->vel.Y = 0; pActor->vel.Z = 0; - if (pActor->spr.spritetexture() == aTexIds[kTexENERGY2]) { + if (pActor->spr.spritetexture() == aTexIds[kTexEnergy2]) { nSmokeSparks--; } @@ -2590,7 +2590,7 @@ void PostProcess() } else // nMap == kMap20) { - auto texid3603 = tileGetTextureID(kClockTile); + auto clocktile = aTexIds[kTexClockTile]; for(auto& sect: sector) { sect.pSoundSect = § @@ -2598,7 +2598,7 @@ void PostProcess() for(auto& wal : sect.walls) { - if (wal.walltexture == texid3603) + if (wal.walltexture == clocktile) { wal.pal = 1; auto pActor = insertActor(§, 407); @@ -2610,7 +2610,7 @@ void PostProcess() ExhumedSpriteIterator it; while (auto act = it.Next()) { - if (act->spr.statnum < kMaxStatus && act->spr.spritetexture() == texid3603) + if (act->spr.statnum < kMaxStatus && act->spr.spritetexture() == clocktile) { ChangeActorStat(act, 407); act->spr.pal = 1; diff --git a/source/games/exhumed/src/ramses.cpp b/source/games/exhumed/src/ramses.cpp index 4ead17919..f1d3eadc7 100644 --- a/source/games/exhumed/src/ramses.cpp +++ b/source/games/exhumed/src/ramses.cpp @@ -75,8 +75,8 @@ void InitSpiritHead() } } - auto pTile = GetRawPixels(tileGetTextureID(kTileRamsesNormal)); // Ramses Normal Head - auto pGold = GetRawPixels(tileGetTextureID(kTileRamsesGold)); + auto pTile = GetRawPixels(aTexIds[kTexTileRamsesNormal1]); // Ramses Normal Head + auto pGold = GetRawPixels(aTexIds[kTexTileRamsesGold]); for (int x = 0; x < 97; x++) { for (int y = 0; y < 106; y++) @@ -117,7 +117,7 @@ void InitSpiritHead() nHeadStage = 0; // work tile is twice as big as the normal head size - auto Worktile = GetWritablePixels(tileGetTextureID(kTileRamsesWorkTile)); + auto Worktile = GetWritablePixels(aTexIds[kTexTileRamsesWorkTile]); pSpiritSpr->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE; @@ -171,7 +171,7 @@ void DimSector(sectortype* pSector) void CopyHeadToWorkTile(int nTile, uint8_t* Worktile) { - const uint8_t* pSrc = GetRawPixels(tileGetTextureID(nTile)); + const uint8_t* pSrc = GetRawPixels(aTexIds[nTile]); uint8_t *pDest = &Worktile[212 * 49 + 53]; for (unsigned i = 0; i < kSpiritY; i++) @@ -193,7 +193,7 @@ void DoSpiritHead() { static int dimSectCount = 0; auto pSpiritSpr = pSpiritSprite; - auto Worktile = GetWritablePixels(tileGetTextureID(kTileRamsesWorkTile)); + auto Worktile = GetWritablePixels(aTexIds[kTexTileRamsesWorkTile]); const auto pPlayer = &PlayerList[0]; const auto pPlayerActor = pPlayer->pActor; @@ -242,10 +242,10 @@ void DoSpiritHead() word_964E8 = RandomSize(5) + 4; } - int tilenum = kTileRamsesNormal; + int tilenum = kTexTileRamsesNormal1; if (--word_964EC < 3) { - tilenum = 593; + tilenum = kTexTileRamsesNormal2; if (word_964EC <= 0) word_964EC = RandomSize(6) + 4; } @@ -262,7 +262,7 @@ void DoSpiritHead() if (nMouthTile != 0) { - FTextureID srctile = tileGetTextureID(nMouthTile + 598); + FTextureID srctile = aTexIds[nMouthTile + kTexTileRamsesMouth1]; auto src = GetRawPixels(srctile); auto tex = TexMan.GetGameTexture(srctile); int sizx = tex->GetTexelWidth(); @@ -424,7 +424,7 @@ void DoSpiritHead() } if (PlayClock - lHeadStartClock > 600) - CopyHeadToWorkTile(590, Worktile); + CopyHeadToWorkTile(kTexTileRamsesGold, Worktile); if (nCount < (15 * nPixels) / 16) { SoundBigEntrance(); @@ -432,7 +432,7 @@ void DoSpiritHead() AddFlash(pSpiritSpr->sector(), pSpiritSpr->spr.pos, 128); nHeadStage = 3; TintPalette(255, 255, 255); - CopyHeadToWorkTile(kTileRamsesNormal, Worktile); + CopyHeadToWorkTile(kTexTileRamsesNormal1, Worktile); } } break; diff --git a/source/games/exhumed/src/texidsdef.h b/source/games/exhumed/src/texidsdef.h index 5eca22cbb..c2581d430 100644 --- a/source/games/exhumed/src/texidsdef.h +++ b/source/games/exhumed/src/texidsdef.h @@ -1,5 +1,4 @@ // list of textures that get referenced directly in game code. -x(ENERGY2) x(Spark1) x(Spark2) x(Playermarker1) @@ -36,3 +35,29 @@ x(Urn4) x(SkullHead) x(SkullJaw) x(TileLoboLaptop) +x(Energy1) +x(Energy2) +x(ClockSymbol1) +x(ClockSymbol2) +x(ClockSymbol3) +x(ClockSymbol4) +x(ClockSymbol5) +x(ClockSymbol6) +x(ClockSymbol7) +x(ClockSymbol8) +x(ClockSymbol9) +x(ClockSymbol10) +x(ClockSymbol11) +x(ClockSymbol12) +x(ClockSymbol13) +x(ClockSymbol14) +x(ClockSymbol15) +x(ClockSymbol16) +x(TileRamsesNormal1) +x(TileRamsesNormal2) +x(TileRamsesNormal3) +x(TileRamsesNormal4) +x(TileRamsesGold) +x(TileRamsesMouth1) +x(TileRamsesMouth2) +x(TileRamsesMouth3) diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 9cacfc4ec..63d9ed677 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -307,7 +307,7 @@ void GameInterface::processSprites(tspriteArray& tsprites, const DVector3& view, pTSprite->pal = RemapPLU(pTSprite->pal); // PowerSlaveGDX: Torch bouncing fix - if ((pTSprite->picnum == kTorch1 || pTSprite->picnum == kTorch2) && (pTSprite->cstat & CSTAT_SPRITE_YCENTER) == 0) + if ((pTSprite->spritetexture() == aTexIds[kTexTorch1] || pTSprite->spritetexture() == aTexIds[kTexTorch2]) && (pTSprite->cstat & CSTAT_SPRITE_YCENTER) == 0) { pTSprite->cstat |= CSTAT_SPRITE_YCENTER; auto tex = TexMan.GetGameTexture(pTSprite->spritetexture());