From 738c133d05ceb40eaecd971e39a1303b64d81f3d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 5 Aug 2022 23:48:43 +0200 Subject: [PATCH] - animation precaching cleanup. No need to handle animations on the,game side. markTileForPrecache already handles this - now also for oscillating animations. --- source/core/precache.cpp | 4 +-- source/core/textures/buildtiles.cpp | 6 ++--- source/core/textures/buildtiles.h | 13 ++++++++- source/games/blood/src/preload.cpp | 18 +------------ source/games/exhumed/src/enginesubs.cpp | 11 -------- source/games/sw/src/cache.cpp | 35 ------------------------- 6 files changed, 18 insertions(+), 69 deletions(-) diff --git a/source/core/precache.cpp b/source/core/precache.cpp index 612c96659..50eb82aff 100644 --- a/source/core/precache.cpp +++ b/source/core/precache.cpp @@ -102,7 +102,7 @@ TMap cachemap; void markTileForPrecache(int tilenum, int palnum) { int i, j; - if ((picanm[tilenum].sf & PICANM_ANIMTYPE_MASK) == PICANM_ANIMTYPE_BACK) + if (picanm[tilenum].type() == PICANM_ANIMTYPE_BACK) { i = tilenum - picanm[tilenum].num; j = tilenum; @@ -110,7 +110,7 @@ void markTileForPrecache(int tilenum, int palnum) else { i = tilenum; - j = tilenum + picanm[tilenum].num; + j = tilenum + picanm[tilenum].num * ((picanm[tilenum].type() == PICANM_ANIMTYPE_OSC) ? 2 : 1); } for (; i <= j; i++) diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index 245a0f123..8206f7872 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -818,9 +818,9 @@ int tileAnimateOfs(int tilenum, int randomize) frametime += Bcrc32(&randomize, 2, 0); } - int curframe = (frametime & 0x7fffffff) >> (picanm[tilenum].sf & PICANM_ANIMSPEED_MASK); + int curframe = (frametime & 0x7fffffff) >> (picanm[tilenum].speed()); - switch (picanm[tilenum].sf & PICANM_ANIMTYPE_MASK) + switch (picanm[tilenum].type()) { case PICANM_ANIMTYPE_FWD: return curframe % (framecount + 1); @@ -869,7 +869,7 @@ void tileUpdateAnimations() { for (int i = 0; i < MAXTILES; i++) { - if (TileFiles.tiledata[i].picanm.sf & PICANM_ANIMTYPE_MASK) + if (TileFiles.tiledata[i].picanm.type()) { int j = i + tileAnimateOfs(i); diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index e4fb55da0..991aec3e6 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -61,6 +61,17 @@ struct picanm_t extra = sf = 0; num = 0; } + + int speed() + { + return sf & PICANM_ANIMSPEED_MASK; + } + + int type() + { + return sf & PICANM_ANIMTYPE_MASK; + } + }; picanm_t tileConvertAnimFormat(int32_t const picanmdisk, int* lo, int* to); @@ -467,7 +478,7 @@ inline void tileUpdatePicnum(int* const tileptr, bool mayrotate = false, int ran { auto& tile = *tileptr; - if (picanm[tile].sf & PICANM_ANIMTYPE_MASK) + if (picanm[tile].type()) tile += tileAnimateOfs(tile, randomize); if (mayrotate && RotTile(tile).newtile != -1) diff --git a/source/games/blood/src/preload.cpp b/source/games/blood/src/preload.cpp index 6b68e9064..ca83998ed 100644 --- a/source/games/blood/src/preload.cpp +++ b/source/games/blood/src/preload.cpp @@ -62,23 +62,7 @@ void tilePrecacheTile(int nTile, int nType, int palette) } while (n--) { - if (picanm[nTile].sf & PICANM_ANIMTYPE_MASK) - { - for (int frame = picanm[nTile].num; frame >= 0; frame--) - { - int tile; - if ((picanm[nTile].sf & PICANM_ANIMTYPE_MASK) == PICANM_ANIMTYPE_BACK) - tile = nTile - frame; - else - tile = nTile + frame; - - markTileForPrecache(tile, palette); - } - } - else - { - markTileForPrecache(nTile, palette); - } + markTileForPrecache(nTile, palette); nTile += 1 + picanm[nTile].num; } } diff --git a/source/games/exhumed/src/enginesubs.cpp b/source/games/exhumed/src/enginesubs.cpp index 06c1f59d4..e6c7ea0a1 100644 --- a/source/games/exhumed/src/enginesubs.cpp +++ b/source/games/exhumed/src/enginesubs.cpp @@ -42,29 +42,20 @@ void precache() { int j = sect.ceilingpicnum; markTileForPrecache(j, sect.ceilingpal); - if (picanm[j].sf & PICANM_ANIMTYPE_MASK) - for (int k = 1; k <= picanm[j].num; k++) markTileForPrecache(j + k, sect.ceilingpal); j = sect.floorpicnum; markTileForPrecache(j, sect.floorpal); - if (picanm[j].sf & PICANM_ANIMTYPE_MASK) - for (int k = 1; k <= picanm[j].num; k++) markTileForPrecache(j + k, sect.floorpal); } for(auto& wal : wall) { int j = wal.picnum; markTileForPrecache(j, wal.pal); - if (picanm[j].sf & PICANM_ANIMTYPE_MASK) - for (int k = 1; k <= picanm[j].num; k++) markTileForPrecache(j + k, wal.pal); if (wal.twoSided()) { j = wal.overpicnum; markTileForPrecache(j, wal.pal); - if (picanm[j].sf & PICANM_ANIMTYPE_MASK) - for (int k = 1; k <= picanm[j].num; k++) markTileForPrecache(j + k, wal.pal); - } } @@ -73,8 +64,6 @@ void precache() { int j = ac->spr.picnum; markTileForPrecache(j, ac->spr.pal); - if (picanm[j].sf & PICANM_ANIMTYPE_MASK) - for (int k = 1; k <= picanm[j].num; k++) markTileForPrecache(j + k, ac->spr.pal); } precacheMarkedTiles(); } diff --git a/source/games/sw/src/cache.cpp b/source/games/sw/src/cache.cpp index 9f40f41a9..631217cbc 100644 --- a/source/games/sw/src/cache.cpp +++ b/source/games/sw/src/cache.cpp @@ -80,54 +80,19 @@ void precacheMap(void) j = sec.ceilingpicnum; markTileForPrecache(j, sec.ceilingpal); - if ((picanm[j].sf & PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - markTileForPrecache(j + i, sec.ceilingpal); - } - } - j = sec.floorpicnum; - markTileForPrecache(j, sec.floorpal); - - if ((picanm[j].sf & PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - markTileForPrecache(j + i, sec.floorpal); - } - } - } for (auto& wal : wall) { j = wal.picnum; - markTileForPrecache(j, wal.pal); - if ((picanm[j].sf & PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - markTileForPrecache(j + i, wal.pal); - } - } - if (wal.overpicnum > 0 && wal.overpicnum < MAXTILES) { j = wal.overpicnum; markTileForPrecache(j, wal.pal); - - if ((picanm[j].sf & PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT) - { - for (i = 1; i <= picanm[j].num; i++) - { - markTileForPrecache(j + i, wal.pal); - } - } } } }