From 32250f704fc956b9ae235d6d96fd87079686590f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 Apr 2021 12:42:59 +0200 Subject: [PATCH] - mograted Blood's precaching to the backend's implementation. --- source/games/blood/src/fx.cpp | 6 +- source/games/blood/src/gib.cpp | 4 +- source/games/blood/src/misc.h | 6 +- source/games/blood/src/preload.cpp | 256 +++++++++++++---------------- source/games/blood/src/qav.cpp | 4 +- source/games/blood/src/qav.h | 2 +- source/games/blood/src/seq.cpp | 8 +- source/games/blood/src/seq.h | 4 +- source/games/blood/src/weapon.cpp | 4 +- 9 files changed, 134 insertions(+), 160 deletions(-) diff --git a/source/games/blood/src/fx.cpp b/source/games/blood/src/fx.cpp index b78946a40..9ee8ec4fe 100644 --- a/source/games/blood/src/fx.cpp +++ b/source/games/blood/src/fx.cpp @@ -345,13 +345,13 @@ void fxSpawnEjectingShell(spritetype *pSprite, int z, int a3, int a4) } } -void fxPrecache(HitList &hits) +void fxPrecache() { for (int i = 0; i < kFXMax; i++) { - tilePrecacheTile(gFXData[i].at12, 0, hits); + tilePrecacheTile(gFXData[i].at12, 0, 0); if (gFXData[i].at2) - seqPrecacheId(gFXData[i].at2, hits); + seqPrecacheId(gFXData[i].at2, 0); } } diff --git a/source/games/blood/src/gib.cpp b/source/games/blood/src/gib.cpp index 449c6da8b..4e4f68264 100644 --- a/source/games/blood/src/gib.cpp +++ b/source/games/blood/src/gib.cpp @@ -501,7 +501,7 @@ void GibWall(int nWall, GIBTYPE nGibType, CGibVelocity *pVel) } } -void gibPrecache(HitList &hits) +void gibPrecache() { for (int i = 0; i < kGibMax; i++) { @@ -511,7 +511,7 @@ void gibPrecache(HitList &hits) for (int j = 0; j < gibList[i].atc; j++) { if (pThing[j].Kills >= 0) - tilePrecacheTile(pThing[j].Kills, -1, hits); + tilePrecacheTile(pThing[j].Kills, -1, 0); } } } diff --git a/source/games/blood/src/misc.h b/source/games/blood/src/misc.h index 09ce772d8..0a2ad62fa 100644 --- a/source/games/blood/src/misc.h +++ b/source/games/blood/src/misc.h @@ -27,8 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -using HitList = FixedBitArray; - void playlogos(); unsigned int qrand(void); int wrand(void); @@ -56,7 +54,7 @@ char WeaponUpgrade(PLAYER *pPlayer, char newWeapon); void WeaponProcess(PLAYER *pPlayer); void WeaponUpdateState(PLAYER* pPlayer); void teslaHit(spritetype *pMissile, int a2); -void WeaponPrecache(HitList &hits); +void WeaponPrecache(); struct ZONE { int x, y, z; @@ -124,7 +122,7 @@ extern int nPrecacheCount; int tileInit(char a1, const char *a2); void tileProcessGLVoxels(void); -void tilePrecacheTile(int nTile, int nType, HitList& hits); +void tilePrecacheTile(int nTile, int nType, int palette); char tileGetSurfType(int hit); diff --git a/source/games/blood/src/preload.cpp b/source/games/blood/src/preload.cpp index f64f5521f..06e6703d6 100644 --- a/source/games/blood/src/preload.cpp +++ b/source/games/blood/src/preload.cpp @@ -32,11 +32,11 @@ BEGIN_BLD_NS int nPrecacheCount; -void fxPrecache(HitList &hits); -void gibPrecache(HitList &hits); +void fxPrecache(); +void gibPrecache(); -void tilePrecacheTile(int nTile, int nType, HitList &hits) +void tilePrecacheTile(int nTile, int nType, int palette) { int n = 1; switch (picanm[nTile].extra & 7) @@ -65,20 +65,13 @@ void tilePrecacheTile(int nTile, int nType, HitList &hits) tile = nTile - frame; else tile = nTile + frame; - if (!hits[tile]) - { - nPrecacheCount++; - hits.Set(tile); - } + + markTileForPrecache(tile, palette); } } else { - if (!hits[nTile]) - { - nPrecacheCount++; - hits.Set(nTile); - } + markTileForPrecache(nTile, palette); } nTile += 1 + picanm[nTile].num; } @@ -87,34 +80,34 @@ void tilePrecacheTile(int nTile, int nType, HitList &hits) // To do: This needs to handle the sprite palettes as well to properly precache the needed content. -void viewPrecacheTiles(HitList &hits) +void viewPrecacheTiles() { - tilePrecacheTile(2173, 0, hits); - tilePrecacheTile(2200, 0, hits); - tilePrecacheTile(2201, 0, hits); - tilePrecacheTile(2202, 0, hits); - tilePrecacheTile(2207, 0, hits); - tilePrecacheTile(2208, 0, hits); - tilePrecacheTile(2209, 0, hits); - tilePrecacheTile(2229, 0, hits); - tilePrecacheTile(2260, 0, hits); - tilePrecacheTile(2559, 0, hits); - tilePrecacheTile(2169, 0, hits); - tilePrecacheTile(2578, 0, hits); - tilePrecacheTile(2586, 0, hits); - tilePrecacheTile(2602, 0, hits); + tilePrecacheTile(2173, 0, 0); + tilePrecacheTile(2200, 0, 0); + tilePrecacheTile(2201, 0, 0); + tilePrecacheTile(2202, 0, 0); + tilePrecacheTile(2207, 0, 0); + tilePrecacheTile(2208, 0, 0); + tilePrecacheTile(2209, 0, 0); + tilePrecacheTile(2229, 0, 0); + tilePrecacheTile(2260, 0, 0); + tilePrecacheTile(2559, 0, 0); + tilePrecacheTile(2169, 0, 0); + tilePrecacheTile(2578, 0, 0); + tilePrecacheTile(2586, 0, 0); + tilePrecacheTile(2602, 0, 0); for (int i = 0; i < 10; i++) { - tilePrecacheTile(2190 + i, 0, hits); - tilePrecacheTile(2230 + i, 0, hits); - tilePrecacheTile(2240 + i, 0, hits); - tilePrecacheTile(2250 + i, 0, hits); - tilePrecacheTile(kSBarNumberHealth + i, 0, hits); - tilePrecacheTile(kSBarNumberAmmo + i, 0, hits); - tilePrecacheTile(kSBarNumberInv + i, 0, hits); - tilePrecacheTile(kSBarNumberArmor1 + i, 0, hits); - tilePrecacheTile(kSBarNumberArmor2 + i, 0, hits); - tilePrecacheTile(kSBarNumberArmor3 + i, 0, hits); + tilePrecacheTile(2190 + i, 0, 0); + tilePrecacheTile(2230 + i, 0, 0); + tilePrecacheTile(2240 + i, 0, 0); + tilePrecacheTile(2250 + i, 0, 0); + tilePrecacheTile(kSBarNumberHealth + i, 0, 0); + tilePrecacheTile(kSBarNumberAmmo + i, 0, 0); + tilePrecacheTile(kSBarNumberInv + i, 0, 0); + tilePrecacheTile(kSBarNumberArmor1 + i, 0, 0); + tilePrecacheTile(kSBarNumberArmor2 + i, 0, 0); + tilePrecacheTile(kSBarNumberArmor3 + i, 0, 0); } /* for (int i = 0; i < 5; i++) @@ -125,54 +118,55 @@ void viewPrecacheTiles(HitList &hits) */ for (int i = 0; i < 6; i++) { - tilePrecacheTile(2220 + i, 0, hits); - tilePrecacheTile(2552 + i, 0, hits); + tilePrecacheTile(2220 + i, 0, 0); + tilePrecacheTile(2552 + i, 0, 0); } } -void PrecacheDude(spritetype *pSprite, HitList &hits) +void PrecacheDude(spritetype *pSprite) { + int palette = pSprite->pal; DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type); - seqPrecacheId(pDudeInfo->seqStartID , hits); - seqPrecacheId(pDudeInfo->seqStartID+5, hits); - seqPrecacheId(pDudeInfo->seqStartID+1, hits); - seqPrecacheId(pDudeInfo->seqStartID+2, hits); + seqPrecacheId(pDudeInfo->seqStartID , palette); + seqPrecacheId(pDudeInfo->seqStartID+5, palette); + seqPrecacheId(pDudeInfo->seqStartID+1, palette); + seqPrecacheId(pDudeInfo->seqStartID+2, palette); switch (pSprite->type) { case kDudeCultistTommy: case kDudeCultistShotgun: case kDudeCultistTesla: case kDudeCultistTNT: - seqPrecacheId(pDudeInfo->seqStartID+6 , hits); - seqPrecacheId(pDudeInfo->seqStartID+7 , hits); - seqPrecacheId(pDudeInfo->seqStartID+8 , hits); - seqPrecacheId(pDudeInfo->seqStartID+9 , hits); - seqPrecacheId(pDudeInfo->seqStartID+13, hits); - seqPrecacheId(pDudeInfo->seqStartID+14, hits); - seqPrecacheId(pDudeInfo->seqStartID+15, hits); + seqPrecacheId(pDudeInfo->seqStartID+6 , palette); + seqPrecacheId(pDudeInfo->seqStartID+7 , palette); + seqPrecacheId(pDudeInfo->seqStartID+8 , palette); + seqPrecacheId(pDudeInfo->seqStartID+9 , palette); + seqPrecacheId(pDudeInfo->seqStartID+13, palette); + seqPrecacheId(pDudeInfo->seqStartID+14, palette); + seqPrecacheId(pDudeInfo->seqStartID+15, palette); break; case kDudeZombieButcher: case kDudeGillBeast: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); - seqPrecacheId(pDudeInfo->seqStartID+9, hits); - seqPrecacheId(pDudeInfo->seqStartID+10, hits); - seqPrecacheId(pDudeInfo->seqStartID+11, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); + seqPrecacheId(pDudeInfo->seqStartID+9, palette); + seqPrecacheId(pDudeInfo->seqStartID+10, palette); + seqPrecacheId(pDudeInfo->seqStartID+11, palette); break; case kDudeGargoyleStatueFlesh: case kDudeGargoyleStatueStone: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+6, hits); //??? + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); //??? fallthrough__; case kDudeGargoyleFlesh: case kDudeGargoyleStone: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); - seqPrecacheId(pDudeInfo->seqStartID+9, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); + seqPrecacheId(pDudeInfo->seqStartID+9, palette); break; case kDudePhantasm: case kDudeHellHound: @@ -181,88 +175,89 @@ void PrecacheDude(spritetype *pSprite, HitList &hits) case kDudeSpiderBlack: case kDudeSpiderMother: case kDudeTchernobog: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); break; case kDudeCerberusTwoHead: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); fallthrough__; case kDudeHand: case kDudeBoneEel: case kDudeBat: case kDudeRat: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); break; case kDudeCultistBeast: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); break; case kDudeZombieAxeBuried: - seqPrecacheId(pDudeInfo->seqStartID+12, hits); - seqPrecacheId(pDudeInfo->seqStartID+9, hits); + seqPrecacheId(pDudeInfo->seqStartID+12, palette); + seqPrecacheId(pDudeInfo->seqStartID+9, palette); fallthrough__; case kDudeZombieAxeLaying: - seqPrecacheId(pDudeInfo->seqStartID+10, hits); + seqPrecacheId(pDudeInfo->seqStartID+10, palette); fallthrough__; case kDudeZombieAxeNormal: - seqPrecacheId(pDudeInfo->seqStartID+6, hits); - seqPrecacheId(pDudeInfo->seqStartID+7, hits); - seqPrecacheId(pDudeInfo->seqStartID+8, hits); - seqPrecacheId(pDudeInfo->seqStartID+11, hits); - seqPrecacheId(pDudeInfo->seqStartID+13, hits); - seqPrecacheId(pDudeInfo->seqStartID+14, hits); + seqPrecacheId(pDudeInfo->seqStartID+6, palette); + seqPrecacheId(pDudeInfo->seqStartID+7, palette); + seqPrecacheId(pDudeInfo->seqStartID+8, palette); + seqPrecacheId(pDudeInfo->seqStartID+11, palette); + seqPrecacheId(pDudeInfo->seqStartID+13, palette); + seqPrecacheId(pDudeInfo->seqStartID+14, palette); break; } } -void PrecacheThing(spritetype *pSprite, HitList &hits) { +void PrecacheThing(spritetype *pSprite) +{ + int palette = pSprite->pal; switch (pSprite->type) { case kThingGlassWindow: // worthless... case kThingFluorescent: - seqPrecacheId(12, hits); + seqPrecacheId(12, palette); break; case kThingSpiderWeb: - seqPrecacheId(15, hits); + seqPrecacheId(15, palette); break; case kThingMetalGrate: - seqPrecacheId(21, hits); + seqPrecacheId(21, palette); break; case kThingFlammableTree: - seqPrecacheId(25, hits); - seqPrecacheId(26, hits); + seqPrecacheId(25, palette); + seqPrecacheId(26, palette); break; case kTrapMachinegun: - seqPrecacheId(38, hits); - seqPrecacheId(40, hits); - seqPrecacheId(28, hits); + seqPrecacheId(38, palette); + seqPrecacheId(40, palette); + seqPrecacheId(28, palette); break; case kThingObjectGib: //case kThingObjectExplode: weird that only gib object is precached and this one is not break; } - tilePrecacheTile(pSprite->picnum, -1, hits); + tilePrecacheTile(pSprite->picnum, -1, palette); } -void PreloadTiles(HitList & hits) +void PreloadCache() { - nPrecacheCount = 0; + if (!r_precache) return; int skyTile = -1; - hits.Zero(); // Fonts for (int i = 0; i < numsectors; i++) { - tilePrecacheTile(sector[i].floorpicnum, 0, hits); - tilePrecacheTile(sector[i].ceilingpicnum, 0, hits); + tilePrecacheTile(sector[i].floorpicnum, 0, sector[i].floorpal); + tilePrecacheTile(sector[i].ceilingpicnum, 0, sector[i].ceilingpal); if ((sector[i].ceilingstat&1) != 0 && skyTile == -1) skyTile = sector[i].ceilingpicnum; } for (int i = 0; i < numwalls; i++) { - tilePrecacheTile(wall[i].picnum, 0, hits); + tilePrecacheTile(wall[i].picnum, 0, wall[i].pal); if (wall[i].overpicnum >= 0) - tilePrecacheTile(wall[i].overpicnum, 0, hits); + tilePrecacheTile(wall[i].overpicnum, 0, wall[i].pal); } for (int i = 0; i < kMaxSprites; i++) { @@ -272,13 +267,13 @@ void PreloadTiles(HitList & hits) switch (pSprite->statnum) { case kStatDude: - PrecacheDude(pSprite, hits); + PrecacheDude(pSprite); break; case kStatThing: - PrecacheThing(pSprite, hits); + PrecacheThing(pSprite); break; default: - tilePrecacheTile(pSprite->picnum, -1, hits); + tilePrecacheTile(pSprite->picnum, -1, pSprite->pal); break; } } @@ -287,57 +282,38 @@ void PreloadTiles(HitList & hits) // Precache common SEQs for (int i = 0; i < 100; i++) { - seqPrecacheId(i, hits); + seqPrecacheId(i, 0); } - tilePrecacheTile(1147, -1, hits); // water drip - tilePrecacheTile(1160, -1, hits); // blood drip + tilePrecacheTile(1147, -1, 0); // water drip + tilePrecacheTile(1160, -1, 0); // blood drip // Player SEQs - seqPrecacheId(dudeInfo[31].seqStartID+6, hits); - seqPrecacheId(dudeInfo[31].seqStartID+7, hits); - seqPrecacheId(dudeInfo[31].seqStartID+8, hits); - seqPrecacheId(dudeInfo[31].seqStartID+9, hits); - seqPrecacheId(dudeInfo[31].seqStartID+10, hits); - seqPrecacheId(dudeInfo[31].seqStartID+14, hits); - seqPrecacheId(dudeInfo[31].seqStartID+15, hits); - seqPrecacheId(dudeInfo[31].seqStartID+12, hits); - seqPrecacheId(dudeInfo[31].seqStartID+16, hits); - seqPrecacheId(dudeInfo[31].seqStartID+17, hits); - seqPrecacheId(dudeInfo[31].seqStartID+18, hits); + seqPrecacheId(dudeInfo[31].seqStartID+6, 0); + seqPrecacheId(dudeInfo[31].seqStartID+7, 0); + seqPrecacheId(dudeInfo[31].seqStartID+8, 0); + seqPrecacheId(dudeInfo[31].seqStartID+9, 0); + seqPrecacheId(dudeInfo[31].seqStartID+10, 0); + seqPrecacheId(dudeInfo[31].seqStartID+14, 0); + seqPrecacheId(dudeInfo[31].seqStartID+15, 0); + seqPrecacheId(dudeInfo[31].seqStartID+12, 0); + seqPrecacheId(dudeInfo[31].seqStartID+16, 0); + seqPrecacheId(dudeInfo[31].seqStartID+17, 0); + seqPrecacheId(dudeInfo[31].seqStartID+18, 0); if (skyTile > -1 && skyTile < kMaxTiles) { for (int i = 1; i < gSkyCount; i++) - tilePrecacheTile(skyTile+i, 0, hits); + tilePrecacheTile(skyTile+i, 0, 0); } - WeaponPrecache(hits); - viewPrecacheTiles(hits); - fxPrecache(hits); - gibPrecache(hits); + WeaponPrecache(); + viewPrecacheTiles(); + fxPrecache(); + gibPrecache(); I_GetEvent(); -} - -void PreloadCache() -{ - if (!r_precache) return; - HitList hits; - PreloadTiles(hits); - int cnt = 0; - int percentDisplayed = -1; - - for (int i = 0; i < kMaxTiles; i++) - { - if (hits[i]) - { - PrecacheHardwareTextures(i); - - if ((++cnt & 7) == 0) - I_GetEvent(); - } - } + precacheMarkedTiles(); } END_BLD_NS diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index fab15a288..3194b30cd 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -146,14 +146,14 @@ void QAV::Play(int start, int end, int nCallback, void *pData) } } -void QAV::Precache(HitList &hits) +void QAV::Precache(int palette) { for (int i = 0; i < nFrames; i++) { for (int j = 0; j < 8; j++) { if (frames[i].tiles[j].picnum >= 0) - tilePrecacheTile(frames[i].tiles[j].picnum, 0, hits); + tilePrecacheTile(frames[i].tiles[j].picnum, 0, palette); } } } diff --git a/source/games/blood/src/qav.h b/source/games/blood/src/qav.h index 07062c67e..8b73ca51c 100644 --- a/source/games/blood/src/qav.h +++ b/source/games/blood/src/qav.h @@ -82,7 +82,7 @@ struct QAV void Draw(int ticks, int stat, int shade, int palnum, bool in3dscene); void Draw(double x, double y, int ticks, int stat, int shade, int palnum, bool in3dscene); void Play(int, int, int, void *); - void Precache(HitList &hits); + void Precache(int palette = 0); }; #pragma pack(pop) diff --git a/source/games/blood/src/seq.cpp b/source/games/blood/src/seq.cpp index 7ea06fbdf..7024d25ea 100644 --- a/source/games/blood/src/seq.cpp +++ b/source/games/blood/src/seq.cpp @@ -102,20 +102,20 @@ static void (*seqClientCallback[])(int, DBloodActor*) = { // //--------------------------------------------------------------------------- -void Seq::Precache(HitList& hits) +void Seq::Precache(int palette) { if (memcmp(signature, "SEQ\x1a", 4) != 0) I_Error("Invalid sequence"); if ((version & 0xff00) != 0x300) I_Error("Obsolete sequence version"); for (int i = 0; i < nFrames; i++) - tilePrecacheTile(seqGetTile(&frames[i]), -1, hits); + tilePrecacheTile(seqGetTile(&frames[i]), -1, palette); } -void seqPrecacheId(int id, HitList& hits) +void seqPrecacheId(int id, int palette) { auto pSeq = getSequence(id); - if (pSeq) pSeq->Precache(hits); + if (pSeq) pSeq->Precache(palette); } //--------------------------------------------------------------------------- diff --git a/source/games/blood/src/seq.h b/source/games/blood/src/seq.h index 481431c11..724f5b081 100644 --- a/source/games/blood/src/seq.h +++ b/source/games/blood/src/seq.h @@ -59,7 +59,7 @@ struct Seq { short soundId; int flags; SEQFRAME frames[1]; - void Precache(HitList&); + void Precache(int palette); bool isLooping() { @@ -96,7 +96,7 @@ inline int seqGetTile(SEQFRAME* pFrame) } int seqRegisterClient(void(*pClient)(int, int)); -void seqPrecacheId(int id, HitList& hits); +void seqPrecacheId(int id, int palette); SEQINST* GetInstance(int a1, int a2); void UnlockInstance(SEQINST* pInst); void seqSpawn(int a1, int a2, int a3, int a4 = -1); diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index b720fbb80..8e168f2ff 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -237,12 +237,12 @@ void WeaponInit(void) } } -void WeaponPrecache(HitList &hits) +void WeaponPrecache() { for (int i = 0; i < kQAVEnd; i++) { if (weaponQAV[i]) - weaponQAV[i]->Precache(hits); + weaponQAV[i]->Precache(); } }