From 83dfd77bd03b0267cabc4f5256c2827bd1c6dc9f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 2 Jan 2023 22:01:13 +0100 Subject: [PATCH] - eliminate picnums in QAV code. --- source/games/blood/src/qav.cpp | 23 ++++++++++++----------- source/games/blood/src/qav.h | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index fba44b4f9..760fa6b5f 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -62,12 +62,12 @@ static void qavInitTileFinderMap() { // Interpolate between frames if the picnums match. This is safest but could miss interpolations between suitable picnums. qavPrevTileFinders.Insert("picnum", [](FRAMEINFO* const thisFrame, FRAMEINFO* const prevFrame, const int i) -> TILE_FRAME* { - return prevFrame->tiles[i].picnum == thisFrame->tiles[i].picnum ? &prevFrame->tiles[i] : nullptr; + return prevFrame->tiles[i].texid == thisFrame->tiles[i].texid ? &prevFrame->tiles[i] : nullptr; }); // Interpolate between frames if the picnum is valid. This can be problematic if tile indices change between frames. qavPrevTileFinders.Insert("index", [](FRAMEINFO* const thisFrame, FRAMEINFO* const prevFrame, const int i) -> TILE_FRAME* { - return prevFrame->tiles[i].picnum > 0 ? &prevFrame->tiles[i] : nullptr; + return prevFrame->tiles[i].texid.isValid() ? &prevFrame->tiles[i] : nullptr; }); // Find previous frame by iterating all previous frame's tiles and return on first matched x coordinate. @@ -123,12 +123,12 @@ void GameInterface::RemoveQAVInterpProps(const int res_id) // //--------------------------------------------------------------------------- -void DrawFrame(double x, double y, double z, double a, double alpha, int picnum, int stat, int shade, int palnum, bool to3dview) +void DrawFrame(double x, double y, double z, double a, double alpha, FTextureID texid, int stat, int shade, int palnum, bool to3dview) { + double scale = z * (1. / 65536.); if (!to3dview) { - auto tex = tileGetTexture(picnum); - double scale = z * (1. / 65536.); + auto tex = TexMan.GetGameTexture(texid); int renderstyle = (stat & RS_NOMASK) ? STYLE_Normal : STYLE_Translucent; int pin = (stat & kQavOrientationLeft) ? -1 : (stat & RS_ALIGN_R) ? 1 : 0; auto translation = TRANSLATION(Translation_Remap, palnum); @@ -153,7 +153,7 @@ void DrawFrame(double x, double y, double z, double a, double alpha, int picnum, if ((stat & kQavOrientationLeft)) stat |= RS_ALIGN_L; stat &= ~kQavOrientationLeft; - hud_drawsprite(x, y, z, a, picnum, shade, palnum, stat, alpha); + hud_drawsprite(x, y, scale, a, texid, shade, palnum, stat, alpha); } } @@ -180,7 +180,7 @@ void QAV::Draw(int ticks, int stat, int shade, int palnum, bool to3dview, double for (int i = 0; i < 8; i++) { - if (thisFrame->tiles[i].picnum > 0) + if (thisFrame->tiles[i].texid.isValid()) { TILE_FRAME* const thisTile = &thisFrame->tiles[i]; TILE_FRAME* const prevTile = interpolate && interpdata->CanInterpFrameTile(nFrame, i) ? interpdata->PrevTileFinder(thisFrame, prevFrame, i) : nullptr; @@ -215,7 +215,7 @@ void QAV::Draw(int ticks, int stat, int shade, int palnum, bool to3dview, double tileAlpha = (tileStat & RS_TRANS1) ? glblend[0].def[!!(tileStat & RS_TRANS2)].alpha : 1.f; } - DrawFrame(tileX + x, tileY + y, tileZ, (angle - tileA).Degrees(), tileAlpha, thisTile->picnum, tileStat, tileShade + shade, (palnum <= 0 ? thisTile->palnum : palnum), to3dview); + DrawFrame(tileX + x, tileY + y, tileZ, (angle - tileA).Degrees(), tileAlpha, thisTile->texid, tileStat, tileShade + shade, (palnum <= 0 ? thisTile->palnum : palnum), to3dview); } } } @@ -294,8 +294,8 @@ void QAV::Precache(int palette) { for (int j = 0; j < 8; j++) { - if (frames[i].tiles[j].picnum >= 0) - tilePrecacheTile(frames[i].tiles[j].picnum, 0, palette); + if (frames[i].tiles[j].texid.isValid()) + markTextureForPrecache(frames[i].tiles[j].texid, palette); } } } @@ -410,7 +410,8 @@ QAV* getQAV(int res_id) // Read TILE_FRAME data. for (int j = 0; j < 8; j++) { - qavdata->frames[i].tiles[j].picnum = fr.ReadInt32(); + int tile = fr.ReadInt32(); + qavdata->frames[i].tiles[j].texid = tile <= 0 ? FNullTextureID() : tileGetTextureID(tile); qavdata->frames[i].tiles[j].x = fr.ReadInt32(); qavdata->frames[i].tiles[j].y = fr.ReadInt32(); qavdata->frames[i].tiles[j].z = fr.ReadInt32(); diff --git a/source/games/blood/src/qav.h b/source/games/blood/src/qav.h index d81d8016d..927637721 100644 --- a/source/games/blood/src/qav.h +++ b/source/games/blood/src/qav.h @@ -193,7 +193,7 @@ enum struct TILE_FRAME { - int picnum; + FTextureID texid; int x; int y; int z;