- rewrote SW's precaching code.

* made it palette aware
* use backend facilities to track precached data.
* fixes bug in animation precaching loops - they only precached the base index over and over again.
This commit is contained in:
Christoph Oelckers 2021-04-11 10:20:52 +02:00
parent 9fd3ab6b5e
commit 387c62d584
5 changed files with 392 additions and 446 deletions

View file

@ -48,17 +48,95 @@ BEGIN_SW_NS
// It will save out the tile and sound number every time one caches. // It will save out the tile and sound number every time one caches.
// //
// sw -map $bullet -cacheprint > foofile // sw -map $bullet -cacheprint > foofile
extern bool PreCaching;
void PreCacheTable(short table[], int num); void PreCacheRange(int start_pic, int end_pic, int pal = 0)
void PreCacheGhost(void); {
for (int j = start_pic; j <= end_pic; j++)
{
markTileForPrecache(j, pal);
}
}
void void PreCacheOverride(void)
SetupPreCache(void)
{ {
if (PreCaching) int i;
StatIterator it(STAT_CEILING_FLOOR_PIC_OVERRIDE);
while ((i = it.NextIndex()) >= 0)
{ {
precache(); int j = SPRITE_TAG2(i);
if(j >= 0 && j <= MAXTILES)
markTileForPrecache(j, 0);
}
}
void precacheMap(void)
{
int i;
int j;
SECTORp sectp;
WALLp wp;
SPRITEp sp;
for (sectp = sector; sectp < &sector[numsectors]; sectp++)
{
j = sectp->ceilingpicnum;
markTileForPrecache(j, sectp->ceilingpal);
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
markTileForPrecache(j + i, sectp->ceilingpal);
}
}
j = sectp->floorpicnum;
markTileForPrecache(j, sectp->floorpal);
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
markTileForPrecache(j + i, sectp->floorpal);
}
}
}
for (wp = wall; wp < &wall[numwalls]; wp++)
{
j = wp->picnum;
markTileForPrecache(j, wp->pal);
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
markTileForPrecache(j + i, wp->pal);
}
}
if (wp->overpicnum > 0 && wp->overpicnum < MAXTILES)
{
j = wp->overpicnum;
markTileForPrecache(j, wp->pal);
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
markTileForPrecache(j + i, wp->pal);
}
}
}
}
}
void SetupPreCache(void)
{
precacheMap();
// actors cache ranges are called from SpriteSetup // actors cache ranges are called from SpriteSetup
@ -102,8 +180,6 @@ SetupPreCache(void)
PreCacheRange(1850,1859); PreCacheRange(1850,1859);
// bullet smoke // bullet smoke
PreCacheRange(1748,1753); PreCacheRange(1748,1753);
// small blue font
PreCacheRange(2930,3023);
// gas can // gas can
PreCacheRange(3038,3042); PreCacheRange(3038,3042);
// lava *** animated tiles, can be deleted now *** // lava *** animated tiles, can be deleted now ***
@ -140,175 +216,140 @@ SetupPreCache(void)
// bullet splashes // bullet splashes
PreCacheRange(772,776); PreCacheRange(772,776);
} }
void PreCacheRipper(int pal)
{
PreCacheRange(1580, 1644, pal);
} }
void PreCacheRipper(void) void PreCacheRipper2(int pal)
{ {
PreCacheRange(1580, 1644); PreCacheRange(4320, 4427, pal);
} }
void PreCacheRipper2(void) void PreCacheGhost(int pal)
{ {
PreCacheRange(4320, 4427); PreCacheRange(4277, 4312, pal);
} }
void PreCacheCoolie(void) void PreCacheCoolie(int pal)
{ {
PreCacheGhost(); PreCacheGhost(pal);
PreCacheRange(1400, 1440); PreCacheRange(1400, 1440, pal);
PreCacheRange(4260, 4276); // coolie explode PreCacheRange(4260, 4276, pal); // coolie explode
} }
void PreCacheGhost(void) void PreCacheSerpent(int pal)
{ {
PreCacheRange(4277, 4312); PreCacheRange(960, 1016, pal);
PreCacheRange(1300, 1314, pal);
} }
void PreCacheSerpent(void) void PreCacheGuardian(int pal)
{ {
PreCacheRange(960, 1016); PreCacheRange(1469,1497, pal);
PreCacheRange(1300, 1314);
} }
void PreCacheGuardian(void) void PreCacheNinja(int pal)
{ {
PreCacheRange(1469,1497); PreCacheRange(4096, 4239, pal);
} }
void PreCacheNinja(void) void PreCacheNinjaGirl(int pal)
{ {
PreCacheRange(4096, 4239); PreCacheRange(5162, 5260, pal);
} }
void PreCacheNinjaGirl(void) void PreCacheSumo(int pal)
{ {
PreCacheRange(5162, 5260); PreCacheRange(4490, 4544, pal);
} }
void PreCacheSumo(void) void PreCacheZilla(int pal)
{ {
PreCacheRange(4490, 4544); PreCacheRange(4490, 4544, pal);
} }
void PreCacheZilla(void) void PreCacheEel(int pal)
{ {
PreCacheRange(4490, 4544); PreCacheRange(4430, 4479, pal);
} }
void PreCacheEel(void) void PreCacheToiletGirl(int pal)
{ {
PreCacheRange(4430, 4479); PreCacheRange(5023, 5027, pal);
} }
void PreCacheToiletGirl(void) void PreCacheWashGirl(int pal)
{ {
PreCacheRange(5023, 5027); PreCacheRange(5032, 5035, pal);
} }
void PreCacheWashGirl(void) void PreCacheCarGirl(int pal)
{ {
PreCacheRange(5032, 5035); PreCacheRange(4594,4597, pal);
} }
void PreCacheCarGirl(void) void PreCacheMechanicGirl(int pal)
{ {
PreCacheRange(4594,4597); PreCacheRange(4590,4593, pal);
} }
void PreCacheMechanicGirl(void) void PreCacheSailorGirl(int pal)
{ {
PreCacheRange(4590,4593); PreCacheRange(4600,4602, pal);
} }
void PreCacheSailorGirl(void) void PreCachePruneGirl(int pal)
{ {
PreCacheRange(4600,4602); PreCacheRange(4604,4604, pal);
} }
void PreCachePruneGirl(void) void PreCacheTrash(int pal)
{ {
PreCacheRange(4604,4604); PreCacheRange(2540, 2546, pal);
} }
void PreCacheTrash(void) void PreCacheBunny(int pal)
{ {
PreCacheRange(2540, 2546); PreCacheRange(4550, 4584, pal);
} }
void PreCacheBunny(void) void PreCacheSkel(int pal)
{ {
PreCacheRange(4550, 4584); PreCacheRange(1320, 1396, pal);
} }
void PreCacheSkel(void) void PreCacheHornet(int pal)
{ {
PreCacheRange(1320, 1396); PreCacheRange(800, 811, pal);
} }
void PreCacheHornet(void) void PreCacheSkull(int pal)
{ {
PreCacheRange(800, 811); PreCacheRange(820, 854, pal);
} }
void PreCacheSkull(void) void PreCacheBetty(int pal)
{ {
PreCacheRange(820, 854); PreCacheRange(817, 819, pal);
} }
void PreCacheBetty(void) void PreCachePachinko(int pal)
{ {
PreCacheRange(817, 819); PreCacheRange(618,623, pal);
} PreCacheRange(618,623, pal);
PreCacheRange(4768,4790, pal);
void PreCachePachinko(void) PreCacheRange(4792,4814, pal);
{ PreCacheRange(4816,4838, pal);
PreCacheRange(618,623); PreCacheRange(4840,4863, pal);
PreCacheRange(618,623);
PreCacheRange(4768,4790);
PreCacheRange(4792,4814);
PreCacheRange(4816,4838);
PreCacheRange(4840,4863);
}
void
PreCacheTable(short table[], int num)
{
short j;
for (j = 0; j < num; j++)
{
SET(gotpic[table[j]>>3], 1<<(table[j]&7));
}
}
void
PreCacheRange(short start_pic, short end_pic)
{
short j;
for (j = start_pic; j <= end_pic; j++)
{
SET(gotpic[j>>3], 1<<(j&7));
}
}
void PreCacheOverride(void)
{
int i;
StatIterator it(STAT_CEILING_FLOOR_PIC_OVERRIDE);
while ((i = it.NextIndex()) >= 0)
{
ASSERT(SPRITE_TAG2(i) >= 0 && SPRITE_TAG2(i) <= MAXTILES);
SET_GOTPIC(SPRITE_TAG2(i));
}
} }
void void
PreCacheActor(void) PreCacheActor(void)
{ {
int i; int i;
short pic; int pic;
for (i=0; i < MAXSPRITES; i++) for (i=0; i < MAXSPRITES; i++)
{ {
@ -323,100 +364,100 @@ PreCacheActor(void)
switch (pic) switch (pic)
{ {
case COOLIE_RUN_R0: case COOLIE_RUN_R0:
PreCacheCoolie(); PreCacheCoolie(sprite[i].pal);
break; break;
case NINJA_RUN_R0: case NINJA_RUN_R0:
case NINJA_CRAWL_R0: case NINJA_CRAWL_R0:
PreCacheNinja(); PreCacheNinja(sprite[i].pal);
break; break;
case GORO_RUN_R0: case GORO_RUN_R0:
PreCacheGuardian(); PreCacheGuardian(sprite[i].pal);
break; break;
case 1441: case 1441:
case COOLG_RUN_R0: case COOLG_RUN_R0:
PreCacheGhost(); PreCacheGhost(sprite[i].pal);
break; break;
case EEL_RUN_R0: case EEL_RUN_R0:
PreCacheEel(); PreCacheEel(sprite[i].pal);
break; break;
case SUMO_RUN_R0: case SUMO_RUN_R0:
PreCacheZilla(); PreCacheZilla(sprite[i].pal);
break; break;
case ZILLA_RUN_R0: case ZILLA_RUN_R0:
PreCacheSumo(); PreCacheSumo(sprite[i].pal);
break; break;
case TOILETGIRL_R0: case TOILETGIRL_R0:
PreCacheToiletGirl(); PreCacheToiletGirl(sprite[i].pal);
break; break;
case WASHGIRL_R0: case WASHGIRL_R0:
PreCacheWashGirl(); PreCacheWashGirl(sprite[i].pal);
break; break;
case CARGIRL_R0: case CARGIRL_R0:
PreCacheCarGirl(); PreCacheCarGirl(sprite[i].pal);
break; break;
case MECHANICGIRL_R0: case MECHANICGIRL_R0:
PreCacheMechanicGirl(); PreCacheMechanicGirl(sprite[i].pal);
break; break;
case SAILORGIRL_R0: case SAILORGIRL_R0:
PreCacheSailorGirl(); PreCacheSailorGirl(sprite[i].pal);
break; break;
case PRUNEGIRL_R0: case PRUNEGIRL_R0:
PreCachePruneGirl(); PreCachePruneGirl(sprite[i].pal);
break; break;
case TRASHCAN: case TRASHCAN:
PreCacheTrash(); PreCacheTrash(sprite[i].pal);
break; break;
case BUNNY_RUN_R0: case BUNNY_RUN_R0:
PreCacheBunny(); PreCacheBunny(sprite[i].pal);
break; break;
case RIPPER_RUN_R0: case RIPPER_RUN_R0:
PreCacheRipper(); PreCacheRipper(sprite[i].pal);
break; break;
case RIPPER2_RUN_R0: case RIPPER2_RUN_R0:
PreCacheRipper2(); PreCacheRipper2(sprite[i].pal);
break; break;
case SERP_RUN_R0: case SERP_RUN_R0:
PreCacheSerpent(); PreCacheSerpent(sprite[i].pal);
break; break;
case LAVA_RUN_R0: case LAVA_RUN_R0:
break; break;
case SKEL_RUN_R0: case SKEL_RUN_R0:
PreCacheSkel(); PreCacheSkel(sprite[i].pal);
break; break;
case HORNET_RUN_R0: case HORNET_RUN_R0:
PreCacheHornet(); PreCacheHornet(sprite[i].pal);
break; break;
case SKULL_R0: case SKULL_R0:
PreCacheSkull(); PreCacheSkull(sprite[i].pal);
break; break;
case BETTY_R0: case BETTY_R0:
PreCacheBetty(); PreCacheBetty(sprite[i].pal);
break; break;
case GIRLNINJA_RUN_R0: case GIRLNINJA_RUN_R0:
PreCacheNinjaGirl(); PreCacheNinjaGirl(sprite[i].pal);
break; break;
case 623: // Pachinko win light case 623: // Pachinko win light
@ -424,8 +465,11 @@ PreCacheActor(void)
case PACHINKO2: case PACHINKO2:
case PACHINKO3: case PACHINKO3:
case PACHINKO4: case PACHINKO4:
PreCachePachinko(); PreCachePachinko(sprite[i].pal);
break; break;
default:
markTileForPrecache(pic, sprite[i].pal);
} }
} }
} }
@ -433,103 +477,15 @@ PreCacheActor(void)
void DoTheCache(void) void DoTheCache(void)
{ {
int i, cnt=0; if (r_precache)
{
SetupPreCache();
PreCacheActor(); PreCacheActor();
PreCacheOverride(); PreCacheOverride();
precacheMarkedTiles();
for (i = 0; i < MAXTILES; i++)
{
if ((TEST(gotpic[i>>3], 1<<(i&7))) && (!tilePtr(i)))
{
// Without palettes this is rather useless...
if (r_precache) PrecacheHardwareTextures(i);
cnt++;
} }
} }
memset(gotpic,0,sizeof(gotpic));
}
void
precache(void)
{
int i;
short j;
SECTORp sectp;
WALLp wp;
SPRITEp sp;
memset(gotpic,0,sizeof(gotpic));
for (sectp = sector; sectp < &sector[numsectors]; sectp++)
{
j = sectp->ceilingpicnum;
SET(gotpic[j>>3], 1<<(j&7));
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
}
}
j = sectp->floorpicnum;
SET(gotpic[j>>3], 1<<(j&7));
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
}
}
}
for (wp = wall; wp < &wall[numwalls]; wp++)
{
j = wp->picnum;
SET(gotpic[j>>3], 1<<(j&7));
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
}
}
if (wp->overpicnum > 0 && wp->overpicnum < MAXTILES)
{
j = wp->overpicnum;
SET(gotpic[j>>3], 1<<(j&7));
if (TEST(picanm[j].sf, PICANM_ANIMTYPE_MASK) >> PICANM_ANIMTYPE_SHIFT)
{
for (i = 1; i <= picanm[j].num; i++)
{
SET(gotpic[(j+i)>>3], 1<<((j+i)&7));
}
}
}
}
for (sp = sprite; sp < &sprite[MAXSPRITES]; sp++)
{
if (sp->statnum < MAXSTATUS)
{
j = sp->picnum;
SET(gotpic[j>>3], 1<<(j&7));
}
}
}
END_SW_NS END_SW_NS

View file

@ -106,7 +106,6 @@ bool NewGame = false;
bool FinishedLevel = false; bool FinishedLevel = false;
short screenpeek = 0; short screenpeek = 0;
bool PreCaching = true;
int GodMode = false; int GodMode = false;
short Skill = 2; short Skill = 2;
short TotalKillable; short TotalKillable;
@ -363,8 +362,6 @@ void InitLevel(MapRecord *maprec)
STAT_NewLevel(currentLevel->fileName); STAT_NewLevel(currentLevel->fileName);
Player[0].angle.ang = buildang(ang); Player[0].angle.ang = buildang(ang);
SetupPreCache();
if (sector[0].extra != -1) if (sector[0].extra != -1)
{ {
NormalVisibility = g_visibility = sector[0].extra; NormalVisibility = g_visibility = sector[0].extra;

View file

@ -11,10 +11,7 @@ enum
CACHE_SOUND_PLAY =1 CACHE_SOUND_PLAY =1
}; };
void SetupPreCache(void);
void PreCacheRange(short start_pic, short end_pic);
void DoTheCache(void); void DoTheCache(void);
void precache(void);
void InitCheats(); void InitCheats();

View file

@ -990,7 +990,6 @@ bool GameInterface::LoadGame()
} }
#endif #endif
SetupPreCache();
DoTheCache(); DoTheCache();
// this is ok - just duplicating sector list with pointers // this is ok - just duplicating sector list with pointers

View file

@ -1187,9 +1187,6 @@ ActorSpawn(SPRITEp sp)
case 1441: case 1441:
case COOLG_RUN_R0: case COOLG_RUN_R0:
{ {
//PreCacheGhost();
if (!ActorTestSpawn(sp)) if (!ActorTestSpawn(sp))
{ {
KillSprite(SpriteNum); KillSprite(SpriteNum);