From fd9a9232af2ba58b3ae2caa63d3fb0d69ad66897 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 20 May 2023 17:50:19 +0200 Subject: [PATCH] - cleanup of Exhumed's 2D code. --- source/games/exhumed/src/2d.cpp | 57 +++++++++++++-------------- source/games/exhumed/src/exhumed.cpp | 15 +++---- source/games/exhumed/src/exhumed.h | 2 +- source/games/exhumed/src/gameloop.cpp | 10 ++--- source/games/exhumed/src/namelist.h | 8 ++++ source/games/exhumed/src/names.h | 10 ----- source/games/exhumed/src/object.cpp | 2 +- source/games/exhumed/src/texidsdef.h | 9 +++++ 8 files changed, 55 insertions(+), 58 deletions(-) diff --git a/source/games/exhumed/src/2d.cpp b/source/games/exhumed/src/2d.cpp index 798acb3bf..5bfdb8ceb 100644 --- a/source/games/exhumed/src/2d.cpp +++ b/source/games/exhumed/src/2d.cpp @@ -51,12 +51,12 @@ BEGIN_PS_NS // //--------------------------------------------------------------------------- -void DrawAbs(int tile, double x, double y, int shade = 0) +void DrawAbs(FGameTexture* tex, double x, double y, int shade = 0) { - DrawTexture(twod, tileGetTexture(tile), x, y, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TopLeft, true, DTA_Color, shadeToLight(shade), TAG_DONE); + DrawTexture(twod, tex, x, y, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TopLeft, true, DTA_Color, shadeToLight(shade), TAG_DONE); } -void DrawRel(FGameTexture* tex, double x, double y, int shade = 0) +void DrawRel(FGameTexture* tex, double x, double y, int shade) { // This is slightly different than what the backend does here, but critical for some graphics. int offx = (int(tex->GetDisplayWidth()) >> 1) + int(tex->GetDisplayLeftOffset()); @@ -64,17 +64,24 @@ void DrawRel(FGameTexture* tex, double x, double y, int shade = 0) DrawTexture(twod, tex, x - offx, y - offy, DTA_FullscreenScale, FSMode_Fit320x200, DTA_TopLeft, true, DTA_Color, shadeToLight(shade), TAG_DONE); } -void DrawRel(int tile, double x, double y, int shade) -{ - DrawRel(tileGetTexture(tile), x, y, shade); -} - enum { kPlasmaWidth = 320, kPlasmaHeight = 80, }; +void DrawLogo() +{ + const auto pLogoTex = TexMan.GetGameTexture(GameLogo()); + DrawRel(pLogoTex, 160, 40); + + // draw the fire urn/lamp thingies + const int urnclock = (I_GetBuildTime() / 16) & 3; + static int urnidx[] = { kTexUrn1, kTexUrn2, kTexUrn3, kTexUrn4, kTexUrn1, kTexUrn2 }; + DrawRel(TexMan.GetGameTexture(aTexIds[urnidx[urnclock]]), 50, 150); + DrawRel(TexMan.GetGameTexture(aTexIds[urnidx[urnclock + 2]]), 270, 150); + +} //--------------------------------------------------------------------------- // // @@ -84,7 +91,8 @@ enum void menu_DoPlasma() { static uint8_t* PlasmaBuffer; - static int nPlasmaTile; + static FGameTexture* nPlasmaTile; + static FGameTexture* nPlasmaTileAlt; static int nSmokeBottom; static int nSmokeRight; static int nSmokeTop; @@ -97,7 +105,8 @@ void menu_DoPlasma() if (!nPlasmaTile) { - nPlasmaTile = kTile4092; + nPlasmaTile = TexMan.GetGameTexture(aTexIds[kTexPlasmaTile1]); + nPlasmaTileAlt = TexMan.GetGameTexture(aTexIds[kTexPlasmaTile2]); plasma_A[5] = {}; plasma_B[5] = {}; plasma_C[5] = {}; @@ -107,7 +116,7 @@ void menu_DoPlasma() const auto pLogoTex = TexMan.GetGameTexture(nLogoTexid); const int logowidth = (int)pLogoTex->GetDisplayWidth(); const int logoheight = (int)pLogoTex->GetDisplayHeight(); - const int ptile = nPlasmaTile; + const auto ptile = nPlasmaTile; const int pclock = I_GetBuildTime(); while (pclock >= nextPlasmaTic || !PlasmaBuffer) @@ -116,10 +125,10 @@ void menu_DoPlasma() if (!PlasmaBuffer) { - auto pixels = GetWritablePixels(tileGetTextureID(kTile4092)); + auto pixels = GetWritablePixels(tileGetTextureID(kPlasmaTile1)); memset(pixels, 96, kPlasmaWidth * kPlasmaHeight); - PlasmaBuffer = GetWritablePixels(tileGetTextureID(kTile4093)); + PlasmaBuffer = GetWritablePixels(tileGetTextureID(kPlasmaTile2)); memset(PlasmaBuffer, 96, kPlasmaWidth * kPlasmaHeight); nSmokeLeft = 160 - logowidth / 2; @@ -139,9 +148,9 @@ void menu_DoPlasma() } } - uint8_t* plasmapix = GetWritablePixels(tileGetTextureID(nPlasmaTile)); + uint8_t* plasmapix = GetWritablePixels(nPlasmaTile->GetID()); uint8_t* r_ebx = plasmapix + 81; - const uint8_t* r_edx = GetWritablePixels(tileGetTextureID(nPlasmaTile ^ 1)) + 81; // flip between value of 4092 and 4093 with xor + const uint8_t* r_edx = GetWritablePixels(nPlasmaTileAlt->GetID()) + 81; // flip between two instances for (int x = 0; x < kPlasmaWidth - 2; x++) { @@ -270,24 +279,12 @@ void menu_DoPlasma() v28[nSmokeOffset] = 175; } - // flip between tile 4092 and 4093 - if (nPlasmaTile == kTile4092) - { - nPlasmaTile = kTile4093; - } - else if (nPlasmaTile == kTile4093) - { - nPlasmaTile = kTile4092; - } + // flip between both instances + std::swap(nPlasmaTile, nPlasmaTileAlt); } DrawAbs(ptile, 0, 0); - DrawRel(pLogoTex, 160, 40); - - // draw the fire urn/lamp thingies - const int urnclock = (pclock / 16) & 3; - DrawRel(kTile3512 + urnclock, 50, 150); - DrawRel(kTile3512 + ((urnclock + 2) & 3), 270, 150); + DrawLogo(); } diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 70cc7e106..4f5ee2dff 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(kTile3603)); + auto pixels = GetWritablePixels(tileGetTextureID(kClockTile)); memset(pixels, TRANSPARENT_INDEX, 4096); @@ -241,7 +241,7 @@ void DrawClock() auto tex = TexMan.GetGameTexture(texid); int yPos = 32 - tex->GetTexelHeight() / 2; - CopyTileToBitmap(texid, tileGetTextureID(kTile3603), ebp - tex->GetTexelWidth() / 2, yPos); + CopyTileToBitmap(texid, tileGetTextureID(kClockTile), ebp - tex->GetTexelWidth() / 2, yPos); ebp -= 15; @@ -390,16 +390,13 @@ static void SetTileNames(TilesetBuildInfo& info) void GameInterface::SetupSpecialTextures(TilesetBuildInfo& info) { SetTileNames(info); - info.CreateWritable(kTile4092, kPlasmaWidth, kPlasmaHeight); - info.CreateWritable(kTile4093, kPlasmaWidth, kPlasmaHeight); + info.CreateWritable(kPlasmaTile1, kPlasmaWidth, kPlasmaHeight); + info.CreateWritable(kPlasmaTile2, kPlasmaWidth, kPlasmaHeight); info.CreateWritable(kTileRamsesWorkTile, kSpiritY * 2, kSpiritX * 2); info.MakeWritable(kTileLoboLaptop); - for(int i = kTile3603; i < kClockSymbol1 + 145; i++) - info.MakeWritable(kTile3603); + info.MakeWritable(kClockTile); info.MakeWritable(kEnergy1); info.MakeWritable(kEnergy2); - for (int i = 0; i < 16; i++) - info.MakeWritable(kClockSymbol1); } //--------------------------------------------------------------------------- @@ -576,7 +573,7 @@ void SerializeState(FSerializer& arc) ("creatureskilled", nCreaturesKilled) ("freeze", nFreeze) ("snakecam", nSnakeCam) - ("clockval", nClockVal) // kTile3603 + ("clockval", nClockVal) ("redticks", nRedTicks) ("alarmticks", nAlarmTicks) ("buttoncolor", nButtonColor) diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index fe7738ac3..8da51d8e5 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -198,7 +198,7 @@ extern char g_modDir[BMAX_PATH]; void G_LoadGroupsInDir(const char* dirname); void G_DoAutoload(const char* dirname); -void DrawRel(int tile, double x, double y, int shade = 0); +void DrawRel(FGameTexture* tile, double x, double y, int shade = 0); void LevelFinished(); // savegame. diff --git a/source/games/exhumed/src/gameloop.cpp b/source/games/exhumed/src/gameloop.cpp index 42899604f..e02b9ec97 100644 --- a/source/games/exhumed/src/gameloop.cpp +++ b/source/games/exhumed/src/gameloop.cpp @@ -107,13 +107,9 @@ void GameInterface::DrawBackground() twod->ClearScreen(); - DrawRel(kSkullHead, 160, 100, 0); - DrawRel(kSkullJaw, 161, 130, 0); - DrawRel(TexMan.GetGameTexture(nLogoTile), 160, 40, 0); - - // draw the fire urn/lamp thingies - DrawRel(kTile3512 + dword_9AB5F, 50, 150, 0); - DrawRel(kTile3512 + ((dword_9AB5F + 2) & 3), 270, 150, 0); + DrawRel(TexMan.GetGameTexture(aTexIds[kTexSkullHead]), 160, 100, 0); + DrawRel(TexMan.GetGameTexture(aTexIds[kTexSkullJaw]), 161, 130, 0); + DrawLogo(); } //--------------------------------------------------------------------------- diff --git a/source/games/exhumed/src/namelist.h b/source/games/exhumed/src/namelist.h index 38c0719f4..d88c26f26 100644 --- a/source/games/exhumed/src/namelist.h +++ b/source/games/exhumed/src/namelist.h @@ -164,3 +164,11 @@ x(Playermarker8, 3578) x(WeaponSpriteSword, 57) x(WeaponSpriteMummy, 3455) + +x(PlasmaTile1, 4092) +x(PlasmaTile2, 4093) +x(ClockTile, 3603) +x(Urn1, 3512) +x(Urn2, 3513) +x(Urn3, 3514) +x(Urn4, 3515) diff --git a/source/games/exhumed/src/names.h b/source/games/exhumed/src/names.h index 654a2cdf8..2b41a34dd 100644 --- a/source/games/exhumed/src/names.h +++ b/source/games/exhumed/src/names.h @@ -18,16 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #pragma once -enum -{ -kTile3000 = 3000, -kTile3512 = 3512, -kTile3593 = 3593, -kTile3603 = 3603, -kTile4092 = 4092, -kTile4093 = 4093, -}; - BEGIN_PS_NS #define x(a, b) k##a = b, diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index afca6ecda..4ae22a026 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -2590,7 +2590,7 @@ void PostProcess() } else // nMap == kMap20) { - auto texid3603 = tileGetTextureID(kTile3603); + auto texid3603 = tileGetTextureID(kClockTile); for(auto& sect: sector) { sect.pSoundSect = § diff --git a/source/games/exhumed/src/texidsdef.h b/source/games/exhumed/src/texidsdef.h index 51ee2d49f..9ffd131d6 100644 --- a/source/games/exhumed/src/texidsdef.h +++ b/source/games/exhumed/src/texidsdef.h @@ -26,3 +26,12 @@ x(AmmoSpriteGrenade) x(WeaponSpriteCobra) x(ExhumedLogo) x(PowerslaveLogo) +x(PlasmaTile1) +x(PlasmaTile2) +x(ClockTile) +x(Urn1) +x(Urn2) +x(Urn3) +x(Urn4) +x(SkullHead) +x(SkullJaw)