gl1: preserve cache on free slots in image and models list(aa6032f0)

This commit is contained in:
Denis Pauk 2021-09-20 11:22:08 +03:00
parent e3a83c6b32
commit 330830fc38
4 changed files with 101 additions and 9 deletions

View File

@ -28,6 +28,7 @@
image_t gltextures[MAX_GLTEXTURES];
int numgltextures;
static int image_max = 0;
int base_textureid; /* gltextures[i] = base_textureid+i */
extern qboolean scrap_dirty;
extern byte scrap_texels[MAX_SCRAPS][BLOCK_WIDTH * BLOCK_HEIGHT];
@ -292,9 +293,9 @@ R_TextureSolidMode(char *string)
void
R_ImageList_f(void)
{
int i;
int i, used, texels;
image_t *image;
int texels;
qboolean freeup;
const char *palstrings[2] = {
"RGB",
"PAL"
@ -302,14 +303,23 @@ R_ImageList_f(void)
R_Printf(PRINT_ALL, "------------------\n");
texels = 0;
used = 0;
for (i = 0, image = gltextures; i < numgltextures; i++, image++)
{
char *in_use = "";
if (image->texnum <= 0)
{
continue;
}
if (image->registration_sequence == registration_sequence)
{
in_use = "*";
used++;
}
texels += image->upload_width * image->upload_height;
switch (image->type)
@ -331,14 +341,16 @@ R_ImageList_f(void)
break;
}
R_Printf(PRINT_ALL, " %3i %3i %s: %s\n",
R_Printf(PRINT_ALL, " %3i %3i %s: %s %s\n",
image->upload_width, image->upload_height,
palstrings[image->paletted], image->name);
palstrings[image->paletted], image->name, in_use);
}
R_Printf(PRINT_ALL,
"Total texel count (not counting mipmaps): %i\n",
texels);
freeup = R_ImageHasFreeSpace();
R_Printf(PRINT_ALL, "Used %d of %d images%s.\n", used, image_max, freeup ? ", has free space" : "");
}
/*
@ -1367,12 +1379,40 @@ R_FreeUnusedImages(void)
}
}
qboolean
R_ImageHasFreeSpace(void)
{
int i, used;
image_t *image;
used = 0;
for (i = 0, image = gltextures; i < numgltextures; i++, image++)
{
if (!image->name[0])
continue;
if (image->registration_sequence == registration_sequence)
{
used ++;
}
}
if (image_max < used)
{
image_max = used;
}
// should same size of free slots as currently used
return (numgltextures + used) < MAX_GLTEXTURES;
}
void
R_InitImages(void)
{
int i, j;
registration_sequence = 1;
image_max = 0;
/* init intensity conversions */
intensity = ri.Cvar_Get("gl1_intensity", "2", CVAR_ARCHIVE);

View File

@ -30,8 +30,9 @@
int modfilelen;
YQ2_ALIGNAS_TYPE(int) byte mod_novis[MAX_MAP_LEAFS / 8];
model_t mod_known[MAX_MOD_KNOWN];
int mod_numknown;
static model_t mod_known[MAX_MOD_KNOWN];
static int mod_numknown;
static int mod_max = 0;
int registration_sequence;
void LoadSP2(model_t *mod, void *buffer, int modfilelen);
@ -42,6 +43,35 @@ void LM_CreateSurfaceLightmap(msurface_t *surf);
void LM_EndBuildingLightmaps(void);
void LM_BeginBuildingLightmaps(model_t *m);
//===============================================================================
static qboolean
Mod_HasFreeSpace(void)
{
int i, used;
model_t *mod;
used = 0;
for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++)
{
if (!mod->name[0])
continue;
if (mod->registration_sequence == registration_sequence)
{
used ++;
}
}
if (mod_max < used)
{
mod_max = used;
}
// should same size of free slots as currently used
return (mod_numknown + mod_max) < MAX_MOD_KNOWN;
}
mleaf_t *
Mod_PointInLeaf(vec3_t p, model_t *model)
{
@ -95,30 +125,44 @@ Mod_ClusterPVS(int cluster, const model_t *model)
void
Mod_Modellist_f(void)
{
int i;
int i, total, used;
model_t *mod;
int total;
qboolean freeup;
total = 0;
used = 0;
R_Printf(PRINT_ALL, "Loaded models:\n");
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
{
char *in_use = "";
if (mod->registration_sequence == registration_sequence)
{
in_use = "*";
used ++;
}
if (!mod->name[0])
{
continue;
}
R_Printf(PRINT_ALL, "%8i : %s\n", mod->extradatasize, mod->name);
R_Printf(PRINT_ALL, "%8i : %s %s\n",
mod->extradatasize, mod->name, in_use);
total += mod->extradatasize;
}
R_Printf(PRINT_ALL, "Total resident: %i\n", total);
// update statistics
freeup = Mod_HasFreeSpace();
R_Printf(PRINT_ALL, "Used %d of %d models%s.\n", used, mod_max, freeup ? ", has free space" : "");
}
void
Mod_Init(void)
{
mod_max = 0;
memset(mod_novis, 0xff, sizeof(mod_novis));
}
@ -1116,6 +1160,12 @@ RI_EndRegistration(void)
int i;
model_t *mod;
if (Mod_HasFreeSpace() && R_ImageHasFreeSpace())
{
// should be enough space for load next maps
return;
}
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
{
if (!mod->name[0])

View File

@ -291,6 +291,7 @@ void R_InitImages(void);
void R_ShutdownImages(void);
void R_FreeUnusedImages(void);
qboolean R_ImageHasFreeSpace(void);
void R_TextureAlphaMode(char *string);
void R_TextureSolidMode(char *string);

View File

@ -810,6 +810,7 @@ R_InitImages (void)
{
unsigned char * table16to8;
registration_sequence = 1;
image_max = 0;
d_16to8table = NULL;
ri.FS_LoadFile("pics/16to8.dat", (void **)&table16to8);