update software precache

spit stuff into functions
handle animated textures and flats too
This commit is contained in:
Alug committed 2025-02-16 16:47:06 +01:00
1 parent 095fd0b015
commit 1b58bdc903
2 files changed
+83 -42

No files matched your search

+15 -1
View File
@@ -716,16 +716,30 @@ levelflat_t *levelflats;
//SoM: Other files want this info.
size_t P_PrecacheLevelFlats(void)
{
levelflat_t levelflat;
lumpnum_t lump;
size_t i, flatmem = 0;
INT32 k;
//SoM: 4/18/2000: New flat code to make use of levelflats.
for (i = 0; i < numlevelflats; i++)
{
lump = levelflats[i].lumpnum;
levelflat = levelflats[i];
lump = levelflat.lumpnum;
if (devparm)
flatmem += W_LumpLength(lump);
R_GetFlat(lump);
if (levelflat.speed) // it is an animated flat
{
for (k = 1; k < levelflat.numpics; k++)
{
lump = levelflat.baselumpnum + k;
if (devparm)
flatmem += W_LumpLength(lump);
R_GetFlat(lump);
}
}
}
return flatmem;
+68 -41
View File
@@ -1825,41 +1825,13 @@ INT32 R_TextureNumForName(const char *name)
return i;
}
//
// R_PrecacheLevel
//
// Preloads all relevant graphics for the level.
//
void R_PrecacheLevel(void)
static void R_PrecacheLevelTextures(void)
{
char *texturepresent, *spritepresent;
size_t i, j, k;
lumpnum_t lump;
char *texturepresent;
anim_t *anim;
size_t j;
INT32 h;
thinker_t *th;
spriteframe_t *sf;
// do not flush the memory, Z_Malloc twice with same user will cause error in Z_CheckHeap()
if (rendermode == render_none)
return;
if (demo.playback)
return;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_PrecacheLevel();
return;
}
#endif
// Precache flats.
flatmemory = P_PrecacheLevelFlats();
//
// Precache textures.
//
// no need to precache all software textures in 3D mode
// (note they are still used with the reference software view)
texturepresent = calloc(numtextures, sizeof (*texturepresent));
@@ -1876,6 +1848,22 @@ void R_PrecacheLevel(void)
texturepresent[sides[j].bottomtexture] = 1;
}
// check for animated textures
for (anim = anims; anim < lastanim; anim++)
{
if (!anim->istexture)
continue;
if (!texturepresent[anim->basepic])
continue;
for (h = 1; h < anim->numpics; h++)
{
if (!texturecache[anim->basepic+h])
R_GenerateTexture(anim->basepic+h);
}
}
// Sky texture is always present.
// Note that F_SKY1 is the name used to indicate a sky floor/ceiling as a flat,
// while the sky texture is stored like a wall texture, with a skynum dependent name.
@@ -1893,10 +1881,17 @@ void R_PrecacheLevel(void)
// since we cache entire composite textures
}
free(texturepresent);
}
static void R_PrecacheLevelSprites(void)
{
char *spritepresent;
size_t i, j, k;
lumpnum_t lump;
thinker_t *th;
spriteframe_t *sf;
//
// Precache sprites.
//
spritepresent = calloc(numsprites, sizeof (*spritepresent));
if (spritepresent == NULL) I_Error("%s: Out of memory looking up sprites", "R_PrecacheLevel");
@@ -1918,11 +1913,11 @@ void R_PrecacheLevel(void)
{
sf = &sprites[i].spriteframes[j];
#define cacheang(a) {\
lump = sf->lumppat[a];\
if (devparm)\
spritememory += W_LumpLength(lump);\
W_CachePatchNum(lump, PU_CACHE);\
}
lump = sf->lumppat[a];\
if (devparm)\
spritememory += W_LumpLength(lump);\
W_CachePatchNum(lump, PU_CACHE);\
}
// see R_InitSprites for more about lumppat,lumpid
switch (sf->rotate)
{
@@ -1944,6 +1939,38 @@ void R_PrecacheLevel(void)
}
free(spritepresent);
}
//
// R_PrecacheLevel
//
// Preloads all relevant graphics for the level.
//
void R_PrecacheLevel(void)
{
// do not flush the memory, Z_Malloc twice with same user will cause error in Z_CheckHeap()
if (rendermode == render_none)
return;
if (demo.playback)
return;
#ifdef HWRENDER
if (rendermode == render_opengl)
{
HWR_PrecacheLevel();
return;
}
#endif
// Precache flats.
flatmemory = P_PrecacheLevelFlats();
// Precache textures.
R_PrecacheLevelTextures();
// Precache sprites.
R_PrecacheLevelSprites();
// FIXME: this is no longer correct with OpenGL render mode
CONS_Debug(DBG_SETUP, "Precache level done:\n"