mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-25 22:10:59 +00:00
soft: preserve cache on free slots in image and models list
This commit is contained in:
parent
35d598bce6
commit
aa6032f00f
3 changed files with 80 additions and 7 deletions
|
@ -587,6 +587,7 @@ void R_ShutdownImages(void);
|
|||
image_t *R_FindImage(char *name, imagetype_t type);
|
||||
byte *Get_BestImageSize(const image_t *image, int *req_width, int *req_height);
|
||||
void R_FreeUnusedImages(void);
|
||||
qboolean R_ImageHasFreeSpace(void);
|
||||
|
||||
void R_InitSkyBox(model_t *loadmodel);
|
||||
void R_IMFlatShadedQuad( vec3_t a, vec3_t b, vec3_t c, vec3_t d, int color, float alpha );
|
||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define MAX_RIMAGES 1024
|
||||
static image_t r_images[MAX_RIMAGES];
|
||||
static int numr_images;
|
||||
static int image_max = 0;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -33,12 +34,13 @@ R_ImageList_f
|
|||
void
|
||||
R_ImageList_f (void)
|
||||
{
|
||||
int i;
|
||||
int i, used, texels;
|
||||
image_t *image;
|
||||
int texels;
|
||||
qboolean freeup;
|
||||
|
||||
R_Printf(PRINT_ALL, "------------------\n");
|
||||
texels = 0;
|
||||
used = 0;
|
||||
|
||||
for (i=0, image=r_images ; i<numr_images ; i++, image++)
|
||||
{
|
||||
|
@ -47,6 +49,7 @@ R_ImageList_f (void)
|
|||
if (image->registration_sequence == registration_sequence)
|
||||
{
|
||||
in_use = "*";
|
||||
used++;
|
||||
}
|
||||
|
||||
if (image->registration_sequence <= 0)
|
||||
|
@ -76,6 +79,8 @@ R_ImageList_f (void)
|
|||
image->width, image->height, in_use);
|
||||
}
|
||||
R_Printf(PRINT_ALL, "Total texel count: %i\n", texels);
|
||||
freeup = R_ImageHasFreeSpace();
|
||||
R_Printf(PRINT_ALL, "Used %d of %d images%s.\n", used, image_max, freeup ? ", has free space" : "");
|
||||
}
|
||||
|
||||
//=======================================================
|
||||
|
@ -727,6 +732,33 @@ R_FreeUnusedImages (void)
|
|||
}
|
||||
}
|
||||
|
||||
qboolean
|
||||
R_ImageHasFreeSpace(void)
|
||||
{
|
||||
int i, used;
|
||||
image_t *image;
|
||||
|
||||
used = 0;
|
||||
|
||||
for (i = 0, image = r_images; i < numr_images; 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 (numr_images + used) < MAX_RIMAGES;
|
||||
}
|
||||
|
||||
static struct texture_buffer {
|
||||
image_t image;
|
||||
byte buffer[4096];
|
||||
|
|
|
@ -34,11 +34,38 @@ static byte mod_novis[MAX_MAP_LEAFS/8];
|
|||
#define MAX_MOD_KNOWN 512
|
||||
static model_t mod_known[MAX_MOD_KNOWN];
|
||||
static int mod_numknown;
|
||||
static int mod_max = 0;
|
||||
|
||||
int registration_sequence;
|
||||
|
||||
//===============================================================================
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
|
@ -48,11 +75,13 @@ Mod_Modellist_f
|
|||
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++)
|
||||
{
|
||||
|
@ -61,6 +90,7 @@ Mod_Modellist_f (void)
|
|||
if (mod->registration_sequence == registration_sequence)
|
||||
{
|
||||
in_use = "*";
|
||||
used ++;
|
||||
}
|
||||
|
||||
if (!mod->name[0])
|
||||
|
@ -70,6 +100,9 @@ Mod_Modellist_f (void)
|
|||
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" : "");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -80,6 +113,7 @@ Mod_Init
|
|||
void
|
||||
Mod_Init (void)
|
||||
{
|
||||
mod_max = 0;
|
||||
memset (mod_novis, 0xff, sizeof(mod_novis));
|
||||
}
|
||||
|
||||
|
@ -1375,14 +1409,20 @@ RE_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])
|
||||
continue;
|
||||
if (mod->registration_sequence != registration_sequence)
|
||||
{ // don't need this model
|
||||
Hunk_Free (mod->extradata);
|
||||
memset (mod, 0, sizeof(*mod));
|
||||
{
|
||||
// don't need this model
|
||||
Mod_Free (mod);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue