diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index f06e2a07b..c2ba3da3a 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -4274,7 +4274,7 @@ void polymost_initosdfuncs(void) { } -static void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) +void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) { // dapicnum and dapalnum are like you'd expect // datype is 0 for a wall/floor/ceiling and 1 for a sprite diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp index 7cd356d61..ab10978bb 100644 --- a/source/games/duke/src/premap_d.cpp +++ b/source/games/duke/src/premap_d.cpp @@ -229,7 +229,7 @@ static void cachegoodsprites(void) // //--------------------------------------------------------------------------- -void cacheit(void) +void cacheit_d(void) { int i, j; diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index b66bfcb11..3410f4c33 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -61,7 +61,7 @@ static void cachespritenum(short i) break; case RRTILE2121: case RRTILE2122: - tloadtile(j, pal); + tloadtile(sprite[i].picnum, pal); break; case TOILET: tloadtile(TOILETBROKE); @@ -398,7 +398,7 @@ static void cachegoodsprites(void) // //--------------------------------------------------------------------------- -static void cacheit(void) +void cacheit_r(void) { short i,j; diff --git a/source/games/duke/src/zz_premap.cpp b/source/games/duke/src/zz_premap.cpp index e00c84a8a..7c14d64c4 100644 --- a/source/games/duke/src/zz_premap.cpp +++ b/source/games/duke/src/zz_premap.cpp @@ -51,424 +51,6 @@ static int32_t g_precacheCount; int32_t g_skillSoundVoice = -1; -static void flag_precache(int32_t tile, int32_t type) -{ - if (!(gotpic[tile>>3] & pow2char[tile&7])) - g_precacheCount++; - gotpic[tile>>3] |= pow2char[tile&7]; - precachehightile[type][tile>>3] |= pow2char[tile&7]; -} - -static void tloadtile(int32_t tilenume, int32_t type) -{ - int32_t i,j; - - if ((picanm[tilenume].sf&PICANM_ANIMTYPE_MASK)==PICANM_ANIMTYPE_BACK) - { - i = tilenume - picanm[tilenume].num; - j = tilenume; - } - else - { - i = tilenume; - j = tilenume + picanm[tilenume].num; - } - - for (; i<=j; i++) - flag_precache(i, type); -} - -static void G_CacheSpriteNum(int32_t i) -{ - char maxc; - int32_t j; - - if (ud.monsters_off && A_CheckEnemySprite(&sprite[i])) return; - - maxc = 1; - - switch (DYNAMICTILEMAP(PN(i))) - { - case HYDRENT__STATIC: - tloadtile(TILE_BROKEFIREHYDRENT,1); - for (j = TILE_TOILETWATER; j < (TILE_TOILETWATER+4); j++) tloadtile(j,1); - break; - case RRTILE2121__STATICRR: - case RRTILE2122__STATICRR: - tloadtile(TILE_BROKEFIREHYDRENT, 1); - break; - case TOILET__STATIC: - tloadtile(TILE_TOILETBROKE,1); - for (j = TILE_TOILETWATER; j < (TILE_TOILETWATER+4); j++) tloadtile(j,1); - break; - case STALL__STATIC: - tloadtile(TILE_STALLBROKE,1); - for (j = TILE_TOILETWATER; j < (TILE_TOILETWATER+4); j++) tloadtile(j,1); - break; - case FORCERIPPLE__STATIC: - if (!RR) break; - maxc = 9; - break; - case RUBBERCAN__STATIC: - maxc = 2; - break; - case TOILETWATER__STATIC: - maxc = 4; - break; - case BUBBASTAND__STATICRR: - for (j = TILE_BUBBASCRATCH; j < (TILE_BUBBASCRATCH+47); j++) tloadtile(j,1); - maxc = 0; - break; - case SBSWIPE__STATICRR: - if (!RRRA) break; - for (j = TILE_BUBBASCRATCH; j <= (TILE_SBSWIPE+47); j++) tloadtile(j,1); - maxc = 0; - break; - case COOT__STATICRR: - for(j = TILE_COOT; j <= (TILE_COOT+217); j++) tloadtile(j,1); - for(j = TILE_COOTJIBA; j < TILE_COOTJIBC+4; j++) tloadtile(j,1); - maxc = 0; - break; - case LTH__STATICRR: - maxc = 105; - for (j = TILE_LTH; j < (TILE_LTH + maxc); j++) tloadtile(j,1); - maxc = 0; - break; - case BILLYRAY__STATICRR: - maxc = 144; - for (j = TILE_BILLYWALK; j < (TILE_BILLYWALK + maxc); j++) tloadtile(j,1); - for (j = TILE_BILLYJIBA; j <= TILE_BILLYJIBB + 4; j++) tloadtile(j,1); - maxc = 0; - break; - case COW__STATICRR: - maxc = 56; - for (j = PN(i); j < (PN(i) + maxc); j++) tloadtile(j,1); - maxc = 0; - break; - case DOGRUN__STATICRR: - for (j = TILE_DOGATTACK; j <= TILE_DOGATTACK + 35; j++) tloadtile(j,1); - for (j = TILE_DOGRUN; j <= TILE_DOGRUN + 121; j++) tloadtile(j,1); - maxc = 0; - break; - case RABBIT__STATICRR: - if (!RRRA) break; - for (j = TILE_RABBIT; j <= TILE_RABBIT + 54; j++) tloadtile(j,1); - for (j = TILE_RABBIT + 56; j <= TILE_RABBIT + 56 + 49; j++) tloadtile(j,1); - for (j = TILE_RABBIT + 56; j <= TILE_RABBIT + 56 + 49; j++) tloadtile(j,1); - maxc = 0; - break; - case BIKERB__STATICRR: - case BIKERBV2__STATICRR: - if (!RRRA) break; - for (j = TILE_BIKERB; j <= TILE_BIKERB + 104; j++) tloadtile(j,1); - maxc = 0; - break; - case BIKER__STATICRR: - if (!RRRA) break; - for (j = TILE_BIKER; j <= TILE_BIKER + 116; j++) tloadtile(j,1); - for (j = TILE_BIKER + 150; j <= TILE_BIKER + 150 + 104; j++) tloadtile(j,1); - maxc = 0; - break; - case CHEER__STATICRR: - if (!RRRA) break; - for (j = TILE_CHEER; j <= TILE_CHEER + 44; j++) tloadtile(j,1); - for (j = TILE_CHEER + 47; j <= TILE_CHEER + 47 + 211; j++) tloadtile(j,1); - for (j = TILE_CHEER + 262; j <= TILE_CHEER + 262 + 72; j++) tloadtile(j,1); - maxc = 0; - break; - case CHEERB__STATICRR: - if (!RRRA) break; - for (j = TILE_CHEERB; j <= TILE_CHEERB + 157 + 83; j++) tloadtile(j,1); - maxc = 0; - break; - case MAMA__STATICRR: - if (!RRRA) break; - for (j = TILE_MAMA; j <= TILE_MAMA + 78; j++) tloadtile(j,1); - for (j = TILE_MAMA + 80; j <= TILE_MAMA + 80 + 7; j++) tloadtile(j,1); - for (j = TILE_MAMA + 90; j <= TILE_MAMA + 90 + 94; j++) tloadtile(j,1); - maxc = 0; - break; - case CHEERBOAT__STATICRR: - if (!RRRA) break; - tloadtile(TILE_CHEERBOAT,1); - maxc = 0; - break; - case HULKBOAT__STATICRR: - if (!RRRA) break; - tloadtile(TILE_HULKBOAT,1); - maxc = 0; - break; - case MINIONBOAT__STATICRR: - if (!RRRA) break; - tloadtile(TILE_MINIONBOAT,1); - maxc = 0; - break; - case BILLYPLAY__STATICRR: - if (!RRRA) break; - for (j = TILE_BILLYPLAY; j <= TILE_BILLYPLAY + 2; j++) tloadtile(j,1); - maxc = 0; - break; - case COOTPLAY__STATICRR: - if (!RRRA) break; - for (j = TILE_COOTPLAY; j <= TILE_COOTPLAY + 4; j++) tloadtile(j,1); - maxc = 0; - break; - case PIG__STATICRR: - case PIGSTAYPUT__STATICRR: - maxc = 69; - break; - case TORNADO__STATICRR: - maxc = 7; - break; - case HEN__STATICRR: - case HENSTAND__STATICRR: - maxc = 34; - break; - case FEMPIC1__STATIC: - if (RR) break; - maxc = 44; - break; - case LIZTROOP__STATIC: - case LIZTROOPRUNNING__STATIC: - case LIZTROOPSHOOT__STATIC: - case LIZTROOPJETPACK__STATIC: - case LIZTROOPONTOILET__STATIC: - case LIZTROOPDUCKING__STATIC: - if (RR) break; - for (j = TILE_LIZTROOP; j < (TILE_LIZTROOP+72); j++) tloadtile(j,1); - for (j=TILE_HEADJIB1; j 1)) - { - maxc = 5; - if (RR) - { - for (j = TILE_APLAYER; j < TILE_APLAYER+220; j++) tloadtile(j,1); - for (j = TILE_DUKEGUN; j < TILE_DUKELEG+4; j++) tloadtile(j,1); - } - else - for (j = 1420; j < 1420+106; j++) tloadtile(j,1); - } - break; - case ATOMICHEALTH__STATIC: - maxc = 14; - break; - case DRONE__STATIC: - maxc = RR ? 6 : 10; - break; - case EXPLODINGBARREL__STATIC: - case SEENINE__STATIC: - case OOZFILTER__STATIC: - maxc = 3; - break; - case NUKEBARREL__STATIC: - case CAMERA1__STATIC: - maxc = 5; - break; - // caching of HUD sprites for weapons that may be in the level - case CHAINGUNSPRITE__STATIC: - if (RR) break; - for (j=TILE_CHAINGUN; j<=TILE_CHAINGUN+7; j++) tloadtile(j,1); - break; - case RPGSPRITE__STATIC: - if (RR) break; - for (j=TILE_RPGGUN; j<=TILE_RPGGUN+2; j++) tloadtile(j,1); - break; - case FREEZESPRITE__STATIC: - if (RR) break; - for (j=TILE_FREEZE; j<=TILE_FREEZE+5; j++) tloadtile(j,1); - break; - case GROWSPRITEICON__STATIC: - case SHRINKERSPRITE__STATIC: - if (RR) break; - for (j=TILE_SHRINKER-2; j<=TILE_SHRINKER+5; j++) tloadtile(j,1); - break; - case HBOMBAMMO__STATIC: - case HEAVYHBOMB__STATIC: - if (RR) break; - for (j=TILE_HANDREMOTE; j<=TILE_HANDREMOTE+5; j++) tloadtile(j,1); - break; - case TRIPBOMBSPRITE__STATIC: - if (RR) break; - for (j=TILE_HANDHOLDINGLASER; j<=TILE_HANDHOLDINGLASER+4; j++) tloadtile(j,1); - break; - case SHOTGUNSPRITE__STATIC: - if (RR) break; - tloadtile(TILE_SHOTGUNSHELL,1); - for (j=TILE_SHOTGUN; j<=TILE_SHOTGUN+6; j++) tloadtile(j,1); - break; - case DEVISTATORSPRITE__STATIC: - if (RR) break; - for (j=TILE_DEVISTATOR; j<=TILE_DEVISTATOR+1; j++) tloadtile(j,1); - break; - case VIXEN__STATICRR: - maxc = 214; - for (j = PN(i); j < PN(i) + maxc; j++) tloadtile(j,1); - maxc = 0; - break; - case SBMOVE__STATICRR: - if (RRRA) break; - maxc = 54; - for (j = PN(i); j < PN(i) + maxc; j++) tloadtile(j,1); - maxc = 100; - for (j = TILE_SBMOVE; j < TILE_SBMOVE + maxc; j++) tloadtile(j,1); - maxc = 0; - break; - case HULK__STATICRR: - maxc = 40; - for (j = PN(i) - 41; j < PN(i) + maxc - 41; j++) tloadtile(j,1); - for (j = TILE_HULKJIBA; j <= TILE_HULKJIBC + 4; j++) tloadtile(j,1); - maxc = 0; - break; - case MINION__STATICRR: - maxc = 141; - for (j = PN(i); j < PN(i) + maxc; j++) tloadtile(j,1); - for (j = TILE_MINJIBA; j <= TILE_MINJIBC + 4; j++) tloadtile(j,1); - maxc = 0; - break; - - } - - for (j = PN(i); j < (PN(i)+maxc); j++) tloadtile(j,1); -} - -static void G_PrecacheSprites(void) -{ - int32_t i; - - tloadtile(TILE_BOTTOMSTATUSBAR,1); - if ((g_netServer || ud.multimode > 1)) - tloadtile(TILE_FRAGBAR,1); - - tloadtile(TILE_VIEWSCREEN,1); - - for (i=TILE_STARTALPHANUM; i= 0) - { - tloadtile(wall[i].overpicnum, 0); - } - } - - for (i=0; i>3]) - { - i+=7; - continue; - } - if (gotpic[i>>3] & pow2char[i&7]) - { - // For the hardware renderer precaching the raw pixel data is pointless. - if (videoGetRenderMode() < REND_POLYMOST) - tileLoad(i); - -#ifdef USE_OPENGL - if (r_precache) PrecacheHardwareTextures(i); -#endif - j++; - pc++; - } - else continue; - - if ((j&7) == 0) - G_HandleAsync(); - } - - Bmemset(gotpic, 0, sizeof(gotpic)); - - endtime = timerGetTicks(); - Printf("Cache time: %dms\n", endtime-starttime); -} - extern int32_t fragbarheight(void) { if (ud.screen_size > 0 && !(ud.statusbarflags & STATUSBAR_NOFRAGBAR) @@ -1214,13 +719,6 @@ static void prelevel(char g) if (sector[i].ceilingstat&1) { - if (tilePtr(sector[i].ceilingpicnum) == nullptr) - { - if (sector[i].ceilingpicnum == TILE_LA) - for (bsize_t j = 0; j < 5; j++) - tloadtile(sector[i].ceilingpicnum + j, 0); - } - if (!RR && sector[i].ceilingpicnum == TILE_CLOUDYSKIES) { if (g_cloudCnt < ARRAY_SSIZE(g_cloudSect)) @@ -1492,7 +990,7 @@ static void prelevel(char g) case W_FORCEFIELD__STATIC: if (RR) break; if (pWall->overpicnum == W_FORCEFIELD__STATIC) - for (bsize_t j = 0; j < 3; j++) tloadtile(TILE_W_FORCEFIELD + j, 0); + for (bsize_t j = 0; j < 3; j++) markTileForPrecache(TILE_W_FORCEFIELD + j, 0); if (pWall->shade > 31) pWall->cstat = 0; else @@ -1516,12 +1014,12 @@ static void prelevel(char g) { case WATERTILE2__STATIC: for (bsize_t j = 0; j < 3; j++) - tloadtile(pWall->picnum + j, 0); + markTileForPrecache(pWall->picnum + j, 0); break; case RRTILE1814__STATICRR: case RRTILE1817__STATICRR: - tloadtile(pWall->picnum, 0); + markTileForPrecache(pWall->picnum, 0); break; case RRTILE1939__STATICRR: case RRTILE1986__STATICRR: @@ -1539,12 +1037,12 @@ static void prelevel(char g) case RRTILE2879__STATICRR: case RRTILE2898__STATICRR: case RRTILE2899__STATICRR: - tloadtile(pWall->picnum, 0); + markTileForPrecache(pWall->picnum, 0); break; case TECHLIGHT2__STATIC: - case TECHLIGHT4__STATIC: tloadtile(pWall->picnum, 0); break; + case TECHLIGHT4__STATIC: markTileForPrecache(pWall->picnum, 0); break; case W_TECHWALL1__STATIC: case W_TECHWALL2__STATIC: case W_TECHWALL3__STATIC: @@ -1558,7 +1056,7 @@ static void prelevel(char g) case SCREENBREAK7__STATIC: case SCREENBREAK8__STATIC: for (bssize_t j = TILE_SCREENBREAK6; j < TILE_SCREENBREAK9; j++) - tloadtile(j, 0); + markTileForPrecache(j, 0); animwall[g_animWallCnt].wallnum = i; animwall[g_animWallCnt].tag = -1; @@ -1976,6 +1474,8 @@ static void G_LoadMapHack(char *outbuf, const char *filename) } } +void cacheit_d(); +void cacheit_r(); int G_EnterLevel(int gameMode) { int32_t i, mii; @@ -2110,7 +1610,8 @@ int G_EnterLevel(int gameMode) ud.playerbest = CONFIG_GetMapBestTime(Menu_HaveUserMap() ? boardfilename : mi.fileName.GetChars(), g_loadedMapHack.md4); // G_FadeLoad(0,0,0, 252,0, -28, 4, -1); - G_CacheMapData(); + if (isRR()) cacheit_r(); else cacheit_d(); + //G_CacheMapData(); // G_FadeLoad(0,0,0, 0,252, 28, 4, -2); // Try this first so that it can disable the CD player if no tracks are found. diff --git a/source/games/duke/src/zz_savegame.cpp b/source/games/duke/src/zz_savegame.cpp index 79cbdbe91..a83fb3201 100644 --- a/source/games/duke/src/zz_savegame.cpp +++ b/source/games/duke/src/zz_savegame.cpp @@ -1426,7 +1426,7 @@ static void postloadplayer(int32_t savegamep) { Bmemset(gotpic, 0, sizeof(gotpic)); S_ClearSoundLocks(); - G_CacheMapData(); + //G_CacheMapData(); Mus_ResumeSaved(); Mus_SetPaused(false); diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index f6cbade4e..f8a0534b1 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -464,10 +464,39 @@ void videoShowFrame(int32_t w) twod->Clear(); } +TMap cachemap; + void markTileForPrecache(int tilenum, int palnum) { + int i, j; + if ((picanm[tilenum].sf & PICANM_ANIMTYPE_MASK) == PICANM_ANIMTYPE_BACK) + { + i = tilenum - picanm[tilenum].num; + j = tilenum; + } + else + { + i = tilenum; + j = tilenum + picanm[tilenum].num; + } + + for (; i <= j; i++) + { + int64_t val = i + (int64_t(palnum) << 16); + cachemap.Insert(val, true); + } } +void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype); + void precacheMarkedTiles() { + decltype(cachemap)::Iterator it(cachemap); + decltype(cachemap)::Pair* pair; + while (it.NextPair(pair)) + { + int dapicnum = pair->Key; + int dapalnum = pair->Key >> 32; + polymost_precache(dapicnum, dapalnum, 0); + } }