mirror of
https://github.com/nzp-team/dquakeplus.git
synced 2025-02-16 16:41:03 +00:00
Misc. Additional Memory optimizations for PSP 1000
This commit is contained in:
parent
0d7ca4ea05
commit
3fe3086cc8
14 changed files with 323 additions and 200 deletions
|
@ -320,12 +320,15 @@ Send the intended movement message to the server
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern cvar_t waypoint_mode;
|
extern cvar_t waypoint_mode;
|
||||||
|
qboolean in_game;
|
||||||
float crosshair_opacity;
|
float crosshair_opacity;
|
||||||
void CL_BaseMove (usercmd_t *cmd)
|
void CL_BaseMove (usercmd_t *cmd)
|
||||||
{
|
{
|
||||||
if (cls.signon != SIGNONS)//BLUBS CHANGED HERE
|
if (cls.signon != SIGNONS)//BLUBS CHANGED HERE
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
in_game = true;
|
||||||
|
|
||||||
CL_AdjustAngles ();
|
CL_AdjustAngles ();
|
||||||
|
|
||||||
Q_memset (cmd, 0, sizeof(*cmd));
|
Q_memset (cmd, 0, sizeof(*cmd));
|
||||||
|
|
|
@ -912,7 +912,7 @@ void CL_ParseClientdata (int bits)
|
||||||
|
|
||||||
|
|
||||||
if (bits & SU_WEAPON)
|
if (bits & SU_WEAPON)
|
||||||
i = MSG_ReadByte ();
|
i = MSG_ReadShort ();
|
||||||
else
|
else
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
|
@ -995,7 +995,7 @@ void CL_ParseClientdata (int bits)
|
||||||
if (cl.progress_bar != i)
|
if (cl.progress_bar != i)
|
||||||
cl.progress_bar = i;
|
cl.progress_bar = i;
|
||||||
|
|
||||||
i = MSG_ReadByte ();
|
i = MSG_ReadShort ();
|
||||||
if (cl.stats[STAT_WEAPON2] != i)
|
if (cl.stats[STAT_WEAPON2] != i)
|
||||||
cl.stats[STAT_WEAPON2] = i;
|
cl.stats[STAT_WEAPON2] = i;
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,21 @@ void CL_InitTEnts (void)
|
||||||
{
|
{
|
||||||
cl_sfx_r_exp3 = S_PrecacheSound ("sounds/weapons/r_exp3.wav");
|
cl_sfx_r_exp3 = S_PrecacheSound ("sounds/weapons/r_exp3.wav");
|
||||||
cl_sfx_step[0] = S_PrecacheSound ("sounds/player/footstep1.wav");
|
cl_sfx_step[0] = S_PrecacheSound ("sounds/player/footstep1.wav");
|
||||||
|
|
||||||
|
#ifdef SLIM
|
||||||
|
|
||||||
cl_sfx_step[1] = S_PrecacheSound ("sounds/player/footstep2.wav");
|
cl_sfx_step[1] = S_PrecacheSound ("sounds/player/footstep2.wav");
|
||||||
cl_sfx_step[2] = S_PrecacheSound ("sounds/player/footstep3.wav");
|
cl_sfx_step[2] = S_PrecacheSound ("sounds/player/footstep3.wav");
|
||||||
cl_sfx_step[3] = S_PrecacheSound ("sounds/player/footstep4.wav");
|
cl_sfx_step[3] = S_PrecacheSound ("sounds/player/footstep4.wav");
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
cl_sfx_step[1] = S_PrecacheSound ("sounds/player/footstep1.wav");
|
||||||
|
cl_sfx_step[2] = S_PrecacheSound ("sounds/player/footstep1.wav");
|
||||||
|
cl_sfx_step[3] = S_PrecacheSound ("sounds/player/footstep1.wav");
|
||||||
|
|
||||||
|
#endif // SLIM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Binary file not shown.
|
@ -68,6 +68,8 @@ extern int nanmask;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
#define CLAMP(min, x, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) //johnfitz
|
#define CLAMP(min, x, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) //johnfitz
|
||||||
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||||
|
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||||
|
|
||||||
#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
|
#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
|
||||||
|
|
||||||
|
|
|
@ -773,13 +773,14 @@ char *exitMessage [] =
|
||||||
" X :Yes O : No "
|
" X :Yes O : No "
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern qboolean in_game;
|
||||||
void M_Menu_Exit_f (void)
|
void M_Menu_Exit_f (void)
|
||||||
{
|
{
|
||||||
wasInMenus = (key_dest == key_menu_pause);
|
wasInMenus = (key_dest == key_menu_pause);
|
||||||
key_dest = key_menu_pause;
|
key_dest = key_menu_pause;
|
||||||
m_state = m_exit;
|
m_state = m_exit;
|
||||||
m_entersound = true;
|
m_entersound = true;
|
||||||
|
in_game = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -615,6 +615,29 @@ void PF_sound (void)
|
||||||
volume = G_FLOAT(OFS_PARM3) * 255;
|
volume = G_FLOAT(OFS_PARM3) * 255;
|
||||||
attenuation = G_FLOAT(OFS_PARM4);
|
attenuation = G_FLOAT(OFS_PARM4);
|
||||||
|
|
||||||
|
// AWFUL AWFUL HACK for limiting zombie sound variations
|
||||||
|
#ifndef SLIM
|
||||||
|
char* s = sample;
|
||||||
|
|
||||||
|
if (s[strlen(s) - 6] == 'r' || s[strlen(s) - 6] == 'd' || s[strlen(s) - 6] == 'a' ||
|
||||||
|
s[strlen(s) - 6] == 't' || s[strlen(s) - 6] == 'w') {
|
||||||
|
if (s[strlen(s) - 5] == '1' || s[strlen(s) - 5] == '2' ||
|
||||||
|
s[strlen(s) - 5] == '3' || s[strlen(s) - 5] == '4' ||
|
||||||
|
s[strlen(s) - 5] == '5' || s[strlen(s) - 5] == '6' ||
|
||||||
|
s[strlen(s) - 5] == '7' || s[strlen(s) - 5] == '8' ||
|
||||||
|
s[strlen(s) - 5] == '9') {
|
||||||
|
|
||||||
|
if (s[strlen(s) - 6] == 'r') {
|
||||||
|
sample[strlen(sample) - 6] = 'w';
|
||||||
|
sample[strlen(sample) - 5] = '1';
|
||||||
|
} else {
|
||||||
|
sample[strlen(sample) - 5] = '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SLIM
|
||||||
|
|
||||||
if (volume < 0 || volume > 255)
|
if (volume < 0 || volume > 255)
|
||||||
Sys_Error ("SV_StartSound: volume = %i", volume);
|
Sys_Error ("SV_StartSound: volume = %i", volume);
|
||||||
|
|
||||||
|
@ -2416,6 +2439,30 @@ void PF_precache_sound (void)
|
||||||
G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
|
G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
|
||||||
PR_CheckEmptyString (s);
|
PR_CheckEmptyString (s);
|
||||||
|
|
||||||
|
// AWFUL AWFUL HACK for limiting zombie sound variations
|
||||||
|
#ifndef SLIM
|
||||||
|
|
||||||
|
if (s[strlen(s) - 6] == 'r' || s[strlen(s) - 6] == 'd' || s[strlen(s) - 6] == 'a' ||
|
||||||
|
s[strlen(s) - 6] == 't' || s[strlen(s) - 6] == 'w') {
|
||||||
|
if (s[strlen(s) - 5] == '1' || s[strlen(s) - 5] == '2' ||
|
||||||
|
s[strlen(s) - 5] == '3' || s[strlen(s) - 5] == '4' ||
|
||||||
|
s[strlen(s) - 5] == '5' || s[strlen(s) - 5] == '6' ||
|
||||||
|
s[strlen(s) - 5] == '7' || s[strlen(s) - 5] == '8' ||
|
||||||
|
s[strlen(s) - 5] == '9') {
|
||||||
|
|
||||||
|
if (s[strlen(s) - 6] == 'r') {
|
||||||
|
s[strlen(s) - 6] = 'w';
|
||||||
|
s[strlen(s) - 5] = '1';
|
||||||
|
} else
|
||||||
|
s[strlen(s) - 5] = '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SLIM
|
||||||
|
|
||||||
|
|
||||||
for (i=0 ; i<MAX_SOUNDS ; i++)
|
for (i=0 ; i<MAX_SOUNDS ; i++)
|
||||||
{
|
{
|
||||||
if (!sv.sound_precache[i])
|
if (!sv.sound_precache[i])
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef SLIM
|
#ifdef SLIM
|
||||||
#define PSP_HEAP_SIZE_MB 42
|
#define PSP_HEAP_SIZE_MB 42
|
||||||
#else
|
#else
|
||||||
#define PSP_HEAP_SIZE_MB 18
|
#define PSP_HEAP_SIZE_MB 7
|
||||||
#endif
|
#endif
|
|
@ -2128,12 +2128,17 @@ void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype)
|
||||||
// HACK HACK HACK
|
// HACK HACK HACK
|
||||||
sprintf (model2, "%s.mdl_%i", model, i);
|
sprintf (model2, "%s.mdl_%i", model, i);
|
||||||
|
|
||||||
|
#ifdef SLIM
|
||||||
|
|
||||||
pheader->gl_texturenum[i][0] =
|
pheader->gl_texturenum[i][0] =
|
||||||
pheader->gl_texturenum[i][1] =
|
pheader->gl_texturenum[i][1] =
|
||||||
pheader->gl_texturenum[i][2] =
|
pheader->gl_texturenum[i][2] =
|
||||||
pheader->gl_texturenum[i][3] = loadtextureimage (model2, 0, 0, qtrue, GU_LINEAR);
|
pheader->gl_texturenum[i][3] = loadtextureimage (model2, 0, 0, qtrue, GU_LINEAR);
|
||||||
|
|
||||||
if (pheader->gl_texturenum[i][0] == 0)// did not find a matching TGA...
|
if (pheader->gl_texturenum[i][0] == 0)// did not find a matching TGA...
|
||||||
|
|
||||||
|
#endif // SLIM
|
||||||
|
|
||||||
{
|
{
|
||||||
sprintf (name, "%s_%i", loadmodel->name, i);
|
sprintf (name, "%s_%i", loadmodel->name, i);
|
||||||
if(mod_h2)
|
if(mod_h2)
|
||||||
|
|
|
@ -876,6 +876,9 @@ R_LoadSkys
|
||||||
extern int nonetexture;
|
extern int nonetexture;
|
||||||
void Sky_LoadSkyBox (char *name)
|
void Sky_LoadSkyBox (char *name)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef SLIM
|
||||||
|
|
||||||
if (strcmp(skybox_name, name) == 0)
|
if (strcmp(skybox_name, name) == 0)
|
||||||
return; //no change
|
return; //no change
|
||||||
|
|
||||||
|
@ -899,6 +902,7 @@ void Sky_LoadSkyBox (char *name)
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
int mark = Hunk_LowMark ();
|
int mark = Hunk_LowMark ();
|
||||||
|
|
||||||
if(!(skyimage[i] = loadtextureimage (va("gfx/env/%s%s", name, suf[i]), 0, 0, qfalse, GU_LINEAR)) &&
|
if(!(skyimage[i] = loadtextureimage (va("gfx/env/%s%s", name, suf[i]), 0, 0, qfalse, GU_LINEAR)) &&
|
||||||
!(skyimage[i] = loadtextureimage (va("gfx/env/%s_%s", name, suf[i]), 0, 0, qfalse, GU_LINEAR)))
|
!(skyimage[i] = loadtextureimage (va("gfx/env/%s_%s", name, suf[i]), 0, 0, qfalse, GU_LINEAR)))
|
||||||
{
|
{
|
||||||
|
@ -912,6 +916,9 @@ void Sky_LoadSkyBox (char *name)
|
||||||
Hunk_FreeToLowMark (mark);
|
Hunk_FreeToLowMark (mark);
|
||||||
}
|
}
|
||||||
strcpy(skybox_name, name);
|
strcpy(skybox_name, name);
|
||||||
|
|
||||||
|
#endif // SLIM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -40,7 +40,7 @@ qboolean SNDDMA_Init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
desired.channels = 2;
|
desired.channels = 2;
|
||||||
desired.samples = 512;
|
desired.samples = 48;
|
||||||
desired.callback = paint_audio;
|
desired.callback = paint_audio;
|
||||||
|
|
||||||
/* Open the audio device */
|
/* Open the audio device */
|
||||||
|
|
|
@ -749,7 +749,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
|
||||||
if (bits & SU_WEAPONSKIN)
|
if (bits & SU_WEAPONSKIN)
|
||||||
MSG_WriteByte (msg, ent->v.weaponskin);
|
MSG_WriteByte (msg, ent->v.weaponskin);
|
||||||
if (bits & SU_WEAPON)
|
if (bits & SU_WEAPON)
|
||||||
MSG_WriteByte (msg, SV_ModelIndex(pr_strings+ent->v.weaponmodel));
|
MSG_WriteShort (msg, SV_ModelIndex(pr_strings+ent->v.weaponmodel));
|
||||||
|
|
||||||
if (bits & SU_GRENADES)
|
if (bits & SU_GRENADES)
|
||||||
MSG_WriteLong (msg, ent->v.grenades);
|
MSG_WriteLong (msg, ent->v.grenades);
|
||||||
|
@ -767,7 +767,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
|
||||||
MSG_WriteByte (msg, ent->v.x2_icon);
|
MSG_WriteByte (msg, ent->v.x2_icon);
|
||||||
MSG_WriteByte (msg, ent->v.insta_icon);
|
MSG_WriteByte (msg, ent->v.insta_icon);
|
||||||
MSG_WriteByte (msg, ent->v.progress_bar);
|
MSG_WriteByte (msg, ent->v.progress_bar);
|
||||||
MSG_WriteByte (msg, SV_ModelIndex(pr_strings+ent->v.weapon2model));
|
MSG_WriteShort (msg, SV_ModelIndex(pr_strings+ent->v.weapon2model));
|
||||||
MSG_WriteByte (msg, ent->v.weapon2skin);
|
MSG_WriteByte (msg, ent->v.weapon2skin);
|
||||||
MSG_WriteByte (msg, ent->v.weapon2frame);
|
MSG_WriteByte (msg, ent->v.weapon2frame);
|
||||||
MSG_WriteByte (msg, ent->v.currentmag2);
|
MSG_WriteByte (msg, ent->v.currentmag2);
|
||||||
|
|
412
source/zone.c
412
source/zone.c
|
@ -1,5 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (C) 1996-1997 Id Software, Inc.
|
Copyright (C) 1996-2001 Id Software, Inc.
|
||||||
|
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||||
|
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
|
@ -17,7 +19,7 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
// Z_zone.c
|
// zone.c
|
||||||
|
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
|
||||||
|
@ -29,17 +31,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
typedef struct memblock_s
|
typedef struct memblock_s
|
||||||
{
|
{
|
||||||
int size; // including the header and possibly tiny fragments
|
int size; // including the header and possibly tiny fragments
|
||||||
int tag; // a tag of 0 is a free block
|
int tag; // a tag of 0 is a free block
|
||||||
int id; // should be ZONEID
|
int id; // should be ZONEID
|
||||||
struct memblock_s *next, *prev;
|
int pad; // pad to 64 bit boundary
|
||||||
int pad; // pad to 64 bit boundary
|
struct memblock_s *next, *prev;
|
||||||
} memblock_t;
|
} memblock_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int size; // total bytes malloced, including header
|
int size; // total bytes malloced, including header
|
||||||
memblock_t blocklist; // start / end cap for linked list
|
memblock_t blocklist; // start / end cap for linked list
|
||||||
memblock_t *rover;
|
memblock_t *rover;
|
||||||
} memzone_t;
|
} memzone_t;
|
||||||
|
|
||||||
|
@ -443,6 +445,7 @@ void *Q_strdup (const char *str)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
|
@ -458,34 +461,7 @@ all big things are allocated on the hunk.
|
||||||
==============================================================================
|
==============================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
memzone_t *mainzone;
|
static memzone_t *mainzone;
|
||||||
|
|
||||||
void Z_ClearZone (memzone_t *zone, int size);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
========================
|
|
||||||
Z_ClearZone
|
|
||||||
========================
|
|
||||||
*/
|
|
||||||
void Z_ClearZone (memzone_t *zone, int size)
|
|
||||||
{
|
|
||||||
memblock_t *block;
|
|
||||||
|
|
||||||
// set the entire zone to one free block
|
|
||||||
|
|
||||||
zone->blocklist.next = zone->blocklist.prev = block =
|
|
||||||
(memblock_t *)( (byte *)zone + sizeof(memzone_t) );
|
|
||||||
zone->blocklist.tag = 1; // in use block
|
|
||||||
zone->blocklist.id = 0;
|
|
||||||
zone->blocklist.size = 0;
|
|
||||||
zone->rover = block;
|
|
||||||
|
|
||||||
block->prev = block->next = &zone->blocklist;
|
|
||||||
block->tag = 0; // free block
|
|
||||||
block->id = ZONEID;
|
|
||||||
block->size = size - sizeof(memzone_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -501,12 +477,8 @@ void Z_Free (void *ptr)
|
||||||
Sys_Error ("Z_Free: NULL pointer");
|
Sys_Error ("Z_Free: NULL pointer");
|
||||||
|
|
||||||
block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
|
block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
|
||||||
|
|
||||||
if (block->id != ZONEID)
|
if (block->id != ZONEID)
|
||||||
{
|
Sys_Error ("Z_Free: freed a pointer without ZONEID");
|
||||||
Con_DPrintf("Z_Free: freed a pointer without ZONEID\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (block->tag == 0)
|
if (block->tag == 0)
|
||||||
Sys_Error ("Z_Free: freed a freed pointer");
|
Sys_Error ("Z_Free: freed a freed pointer");
|
||||||
|
|
||||||
|
@ -535,28 +507,10 @@ void Z_Free (void *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
========================
|
|
||||||
Z_Malloc
|
|
||||||
========================
|
|
||||||
*/
|
|
||||||
void *Z_Malloc (int size)
|
|
||||||
{
|
|
||||||
void *buf;
|
|
||||||
|
|
||||||
Z_CheckHeap (); // DEBUG
|
|
||||||
buf = Z_TagMalloc (size, 1);
|
|
||||||
if (!buf)
|
|
||||||
Sys_Error ("Z_Malloc: failed on allocation of %i bytes",size);
|
|
||||||
Q_memset (buf, 0, size);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *Z_TagMalloc (int size, int tag)
|
void *Z_TagMalloc (int size, int tag)
|
||||||
{
|
{
|
||||||
int extra;
|
int extra;
|
||||||
memblock_t *start, *rover, *new, *base;
|
memblock_t *start, *rover, *newblock, *base;
|
||||||
|
|
||||||
if (!tag)
|
if (!tag)
|
||||||
Sys_Error ("Z_TagMalloc: tried to use a 0 tag");
|
Sys_Error ("Z_TagMalloc: tried to use a 0 tag");
|
||||||
|
@ -588,14 +542,14 @@ void *Z_TagMalloc (int size, int tag)
|
||||||
extra = base->size - size;
|
extra = base->size - size;
|
||||||
if (extra > MINFRAGMENT)
|
if (extra > MINFRAGMENT)
|
||||||
{ // there will be a free fragment after the allocated block
|
{ // there will be a free fragment after the allocated block
|
||||||
new = (memblock_t *) ((byte *)base + size );
|
newblock = (memblock_t *) ((byte *)base + size );
|
||||||
new->size = extra;
|
newblock->size = extra;
|
||||||
new->tag = 0; // free block
|
newblock->tag = 0; // free block
|
||||||
new->prev = base;
|
newblock->prev = base;
|
||||||
new->id = ZONEID;
|
newblock->id = ZONEID;
|
||||||
new->next = base->next;
|
newblock->next = base->next;
|
||||||
new->next->prev = new;
|
newblock->next->prev = newblock;
|
||||||
base->next = new;
|
base->next = newblock;
|
||||||
base->size = size;
|
base->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,6 +565,92 @@ void *Z_TagMalloc (int size, int tag)
|
||||||
return (void *) ((byte *)base + sizeof(memblock_t));
|
return (void *) ((byte *)base + sizeof(memblock_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Z_CheckHeap
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
void Z_CheckHeap (void)
|
||||||
|
{
|
||||||
|
memblock_t *block;
|
||||||
|
|
||||||
|
for (block = mainzone->blocklist.next ; ; block = block->next)
|
||||||
|
{
|
||||||
|
if (block->next == &mainzone->blocklist)
|
||||||
|
break; // all blocks have been hit
|
||||||
|
if ( (byte *)block + block->size != (byte *)block->next)
|
||||||
|
Sys_Error ("Z_CheckHeap: block size does not touch the next block");
|
||||||
|
if ( block->next->prev != block)
|
||||||
|
Sys_Error ("Z_CheckHeap: next block doesn't have proper back link");
|
||||||
|
if (!block->tag && !block->next->tag)
|
||||||
|
Sys_Error ("Z_CheckHeap: two consecutive free blocks");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Z_Malloc
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
void *Z_Malloc (int size)
|
||||||
|
{
|
||||||
|
void *buf;
|
||||||
|
|
||||||
|
Z_CheckHeap (); // DEBUG
|
||||||
|
buf = Z_TagMalloc (size, 1);
|
||||||
|
if (!buf)
|
||||||
|
Sys_Error ("Z_Malloc: failed on allocation of %i bytes",size);
|
||||||
|
Q_memset (buf, 0, size);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Z_Realloc
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
void *Z_Realloc(void *ptr, int size)
|
||||||
|
{
|
||||||
|
int old_size;
|
||||||
|
void *old_ptr;
|
||||||
|
memblock_t *block;
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
return Z_Malloc (size);
|
||||||
|
|
||||||
|
block = (memblock_t *) ((byte *) ptr - sizeof (memblock_t));
|
||||||
|
if (block->id != ZONEID)
|
||||||
|
Sys_Error ("Z_Realloc: realloced a pointer without ZONEID");
|
||||||
|
if (block->tag == 0)
|
||||||
|
Sys_Error ("Z_Realloc: realloced a freed pointer");
|
||||||
|
|
||||||
|
old_size = block->size;
|
||||||
|
old_size -= (4 + (int)sizeof(memblock_t)); /* see Z_TagMalloc() */
|
||||||
|
old_ptr = ptr;
|
||||||
|
|
||||||
|
Z_Free (ptr);
|
||||||
|
ptr = Z_TagMalloc (size, 1);
|
||||||
|
if (!ptr)
|
||||||
|
Sys_Error ("Z_Realloc: failed on allocation of %i bytes", size);
|
||||||
|
|
||||||
|
if (ptr != old_ptr)
|
||||||
|
memmove (ptr, old_ptr, MIN(old_size, size));
|
||||||
|
if (old_size < size)
|
||||||
|
memset ((byte *)ptr + old_size, 0, size - old_size);
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *Z_Strdup (char *s)
|
||||||
|
{
|
||||||
|
size_t sz = strlen(s) + 1;
|
||||||
|
char *ptr = (char *) Z_Malloc (sz);
|
||||||
|
memcpy (ptr, s, sz);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
========================
|
========================
|
||||||
|
@ -640,37 +680,16 @@ void Z_Print (memzone_t *zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
========================
|
|
||||||
Z_CheckHeap
|
|
||||||
========================
|
|
||||||
*/
|
|
||||||
void Z_CheckHeap (void)
|
|
||||||
{
|
|
||||||
memblock_t *block;
|
|
||||||
|
|
||||||
for (block = mainzone->blocklist.next ; ; block = block->next)
|
|
||||||
{
|
|
||||||
if (block->next == &mainzone->blocklist)
|
|
||||||
break; // all blocks have been hit
|
|
||||||
if ( (byte *)block + block->size != (byte *)block->next)
|
|
||||||
Sys_Error ("Z_CheckHeap: block size does not touch the next block\n");
|
|
||||||
if ( block->next->prev != block)
|
|
||||||
Sys_Error ("Z_CheckHeap: next block doesn't have proper back link\n");
|
|
||||||
if (!block->tag && !block->next->tag)
|
|
||||||
Sys_Error ("Z_CheckHeap: two consecutive free blocks\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#define HUNK_SENTINAL 0x1df001ed
|
#define HUNK_SENTINEL 0x1df001ed
|
||||||
|
|
||||||
|
#define HUNKNAME_LEN 24
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int sentinal;
|
int sentinel;
|
||||||
int size; // including sizeof(hunk_t), -1 = not allocated
|
int size; // including sizeof(hunk_t), -1 = not allocated
|
||||||
char name[8];
|
char name[HUNKNAME_LEN];
|
||||||
} hunk_t;
|
} hunk_t;
|
||||||
|
|
||||||
byte *hunk_base;
|
byte *hunk_base;
|
||||||
|
@ -682,13 +701,11 @@ int hunk_high_used;
|
||||||
qboolean hunk_tempactive;
|
qboolean hunk_tempactive;
|
||||||
int hunk_tempmark;
|
int hunk_tempmark;
|
||||||
|
|
||||||
void R_FreeTextures (void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==============
|
==============
|
||||||
Hunk_Check
|
Hunk_Check
|
||||||
|
|
||||||
Run consistancy and sentinal trahing checks
|
Run consistancy and sentinel trahing checks
|
||||||
==============
|
==============
|
||||||
*/
|
*/
|
||||||
void Hunk_Check (void)
|
void Hunk_Check (void)
|
||||||
|
@ -697,9 +714,9 @@ void Hunk_Check (void)
|
||||||
|
|
||||||
for (h = (hunk_t *)hunk_base ; (byte *)h != hunk_base + hunk_low_used ; )
|
for (h = (hunk_t *)hunk_base ; (byte *)h != hunk_base + hunk_low_used ; )
|
||||||
{
|
{
|
||||||
if (h->sentinal != HUNK_SENTINAL)
|
if (h->sentinel != HUNK_SENTINEL)
|
||||||
Sys_Error ("Hunk_Check: trahsed sentinal");
|
Sys_Error ("Hunk_Check: trashed sentinel");
|
||||||
if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size)
|
if (h->size < (int) sizeof(hunk_t) || h->size + (byte *)h - hunk_base > hunk_size)
|
||||||
Sys_Error ("Hunk_Check: bad size");
|
Sys_Error ("Hunk_Check: bad size");
|
||||||
h = (hunk_t *)((byte *)h+h->size);
|
h = (hunk_t *)((byte *)h+h->size);
|
||||||
}
|
}
|
||||||
|
@ -715,13 +732,11 @@ Otherwise, allocations with the same name will be totaled up before printing.
|
||||||
*/
|
*/
|
||||||
void Hunk_Print (qboolean all)
|
void Hunk_Print (qboolean all)
|
||||||
{
|
{
|
||||||
|
|
||||||
hunk_t *h, *next, *endlow, *starthigh, *endhigh;
|
hunk_t *h, *next, *endlow, *starthigh, *endhigh;
|
||||||
int count, sum;
|
int count, sum;
|
||||||
int totalblocks;
|
int totalblocks;
|
||||||
char name[9];
|
char name[HUNKNAME_LEN];
|
||||||
|
|
||||||
name[8] = 0;
|
|
||||||
count = 0;
|
count = 0;
|
||||||
sum = 0;
|
sum = 0;
|
||||||
totalblocks = 0;
|
totalblocks = 0;
|
||||||
|
@ -756,9 +771,9 @@ void Hunk_Print (qboolean all)
|
||||||
//
|
//
|
||||||
// run consistancy checks
|
// run consistancy checks
|
||||||
//
|
//
|
||||||
if (h->sentinal != HUNK_SENTINAL)
|
if (h->sentinel != HUNK_SENTINEL)
|
||||||
Sys_Error ("Hunk_Check: trahsed sentinal");
|
Sys_Error ("Hunk_Check: trashed sentinel");
|
||||||
if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size)
|
if (h->size < (int) sizeof(hunk_t) || h->size + (byte *)h - hunk_base > hunk_size)
|
||||||
Sys_Error ("Hunk_Check: bad size");
|
Sys_Error ("Hunk_Check: bad size");
|
||||||
|
|
||||||
next = (hunk_t *)((byte *)h+h->size);
|
next = (hunk_t *)((byte *)h+h->size);
|
||||||
|
@ -769,7 +784,7 @@ void Hunk_Print (qboolean all)
|
||||||
//
|
//
|
||||||
// print the single block
|
// print the single block
|
||||||
//
|
//
|
||||||
memcpy_vfpu(name, h->name, 8);
|
memcpy (name, h->name, HUNKNAME_LEN);
|
||||||
if (all)
|
if (all)
|
||||||
Con_Printf ("%8p :%8i %8s\n",h, h->size, name);
|
Con_Printf ("%8p :%8i %8s\n",h, h->size, name);
|
||||||
|
|
||||||
|
@ -777,7 +792,7 @@ void Hunk_Print (qboolean all)
|
||||||
// print the total
|
// print the total
|
||||||
//
|
//
|
||||||
if (next == endlow || next == endhigh ||
|
if (next == endlow || next == endhigh ||
|
||||||
strncmp (h->name, next->name, 8) )
|
strncmp (h->name, next->name, HUNKNAME_LEN - 1))
|
||||||
{
|
{
|
||||||
if (!all)
|
if (!all)
|
||||||
Con_Printf (" :%8i %8s (TOTAL)\n",sum, name);
|
Con_Printf (" :%8i %8s (TOTAL)\n",sum, name);
|
||||||
|
@ -790,6 +805,17 @@ void Hunk_Print (qboolean all)
|
||||||
|
|
||||||
Con_Printf ("-------------------------\n");
|
Con_Printf ("-------------------------\n");
|
||||||
Con_Printf ("%8i total blocks\n", totalblocks);
|
Con_Printf ("%8i total blocks\n", totalblocks);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
===================
|
||||||
|
Hunk_Print_f -- johnfitz -- console command to call hunk_print
|
||||||
|
===================
|
||||||
|
*/
|
||||||
|
void Hunk_Print_f (void)
|
||||||
|
{
|
||||||
|
Hunk_Print (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -801,21 +827,17 @@ void *Hunk_AllocName (int size, char *name)
|
||||||
{
|
{
|
||||||
hunk_t *h;
|
hunk_t *h;
|
||||||
|
|
||||||
|
#ifdef PARANOID
|
||||||
|
Hunk_Check ();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
{
|
|
||||||
Sys_Error ("Hunk_Alloc: bad size: %i", size);
|
Sys_Error ("Hunk_Alloc: bad size: %i", size);
|
||||||
//Con_Printf ("Hunk_Alloc: bad size: %i", size);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size = sizeof(hunk_t) + ((size+15)&~15);
|
size = sizeof(hunk_t) + ((size+15)&~15);
|
||||||
|
|
||||||
if (hunk_size - hunk_low_used - hunk_high_used < size)
|
if (hunk_size - hunk_low_used - hunk_high_used < size)
|
||||||
{
|
Sys_Error ("Hunk_Alloc: failed on %i bytes",size);
|
||||||
Sys_Error ("Hunk_Alloc: failed on %i bytes, %s", size, name);
|
|
||||||
//Con_Printf ("Hunk_Alloc: failed on %i bytes",size);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
h = (hunk_t *)(hunk_base + hunk_low_used);
|
h = (hunk_t *)(hunk_base + hunk_low_used);
|
||||||
hunk_low_used += size;
|
hunk_low_used += size;
|
||||||
|
@ -825,8 +847,8 @@ void *Hunk_AllocName (int size, char *name)
|
||||||
memset (h, 0, size);
|
memset (h, 0, size);
|
||||||
|
|
||||||
h->size = size;
|
h->size = size;
|
||||||
h->sentinal = HUNK_SENTINAL;
|
h->sentinel = HUNK_SENTINEL;
|
||||||
Q_strncpy (h->name, name, 8);
|
strlcpy(h->name, name, HUNKNAME_LEN);
|
||||||
|
|
||||||
return (void *)(h+1);
|
return (void *)(h+1);
|
||||||
}
|
}
|
||||||
|
@ -897,11 +919,15 @@ void *Hunk_HighAllocName (int size, char *name)
|
||||||
hunk_tempactive = false;
|
hunk_tempactive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PARANOID
|
||||||
|
Hunk_Check ();
|
||||||
|
#endif
|
||||||
|
|
||||||
size = sizeof(hunk_t) + ((size+15)&~15);
|
size = sizeof(hunk_t) + ((size+15)&~15);
|
||||||
|
|
||||||
if (hunk_size - hunk_low_used - hunk_high_used < size)
|
if (hunk_size - hunk_low_used - hunk_high_used < size)
|
||||||
{
|
{
|
||||||
Con_Printf ("Hunk_HighAlloc: failed on %i bytes, %s\n", size, name);
|
Con_Printf ("Hunk_HighAlloc: failed on %i bytes\n",size);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -912,8 +938,8 @@ void *Hunk_HighAllocName (int size, char *name)
|
||||||
|
|
||||||
memset (h, 0, size);
|
memset (h, 0, size);
|
||||||
h->size = size;
|
h->size = size;
|
||||||
h->sentinal = HUNK_SENTINAL;
|
h->sentinel = HUNK_SENTINEL;
|
||||||
Q_strncpy (h->name, name, 8);
|
strlcpy (h->name, name, HUNKNAME_LEN);
|
||||||
|
|
||||||
return (void *)(h+1);
|
return (void *)(h+1);
|
||||||
}
|
}
|
||||||
|
@ -947,6 +973,14 @@ void *Hunk_TempAlloc (int size)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *Hunk_Strdup (char *s, char *name)
|
||||||
|
{
|
||||||
|
size_t sz = strlen(s) + 1;
|
||||||
|
char *ptr = (char *) Hunk_AllocName (sz, name);
|
||||||
|
memcpy (ptr, s, sz);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
|
||||||
|
@ -955,11 +989,12 @@ CACHE MEMORY
|
||||||
===============================================================================
|
===============================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define CACHENAME_LEN 32
|
||||||
typedef struct cache_system_s
|
typedef struct cache_system_s
|
||||||
{
|
{
|
||||||
int size; // including this header
|
int size; // including this header
|
||||||
cache_user_t *user;
|
cache_user_t *user;
|
||||||
char name[16];
|
char name[CACHENAME_LEN];
|
||||||
struct cache_system_s *prev, *next;
|
struct cache_system_s *prev, *next;
|
||||||
struct cache_system_s *lru_prev, *lru_next; // for LRU flushing
|
struct cache_system_s *lru_prev, *lru_next; // for LRU flushing
|
||||||
} cache_system_t;
|
} cache_system_t;
|
||||||
|
@ -975,25 +1010,25 @@ Cache_Move
|
||||||
*/
|
*/
|
||||||
void Cache_Move ( cache_system_t *c)
|
void Cache_Move ( cache_system_t *c)
|
||||||
{
|
{
|
||||||
cache_system_t *new;
|
cache_system_t *new_cs;
|
||||||
|
|
||||||
// we are clearing up space at the bottom, so only allocate it late
|
// we are clearing up space at the bottom, so only allocate it late
|
||||||
new = Cache_TryAlloc (c->size, true);
|
new_cs = Cache_TryAlloc (c->size, true);
|
||||||
if (new)
|
if (new_cs)
|
||||||
{
|
{
|
||||||
// Con_Printf ("cache_move ok\n");
|
// Con_Printf ("cache_move ok\n");
|
||||||
|
|
||||||
Q_memcpy ( new+1, c+1, c->size - sizeof(cache_system_t) );
|
Q_memcpy ( new_cs+1, c+1, c->size - sizeof(cache_system_t) );
|
||||||
new->user = c->user;
|
new_cs->user = c->user;
|
||||||
Q_memcpy (new->name, c->name, sizeof(new->name));
|
Q_memcpy (new_cs->name, c->name, sizeof(new_cs->name));
|
||||||
Cache_Free (c->user);
|
Cache_Free (c->user);
|
||||||
new->user->data = (void *)(new+1);
|
new_cs->user->data = (void *)(new_cs+1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Con_Printf ("cache_move failed\n");
|
// Con_Printf ("cache_move failed\n");
|
||||||
|
|
||||||
Cache_Free (c->user); // tough luck...
|
Cache_Free (c->user); // tough luck...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1080,7 +1115,7 @@ Size should already include the header and padding
|
||||||
*/
|
*/
|
||||||
cache_system_t *Cache_TryAlloc (int size, qboolean nobottom)
|
cache_system_t *Cache_TryAlloc (int size, qboolean nobottom)
|
||||||
{
|
{
|
||||||
cache_system_t *cs, *new;
|
cache_system_t *cs, *new_cs;
|
||||||
|
|
||||||
// is the cache completely empty?
|
// is the cache completely empty?
|
||||||
|
|
||||||
|
@ -1089,62 +1124,62 @@ cache_system_t *Cache_TryAlloc (int size, qboolean nobottom)
|
||||||
if (hunk_size - hunk_high_used - hunk_low_used < size)
|
if (hunk_size - hunk_high_used - hunk_low_used < size)
|
||||||
Sys_Error ("Cache_TryAlloc: %i is greater then free hunk", size);
|
Sys_Error ("Cache_TryAlloc: %i is greater then free hunk", size);
|
||||||
|
|
||||||
new = (cache_system_t *) (hunk_base + hunk_low_used);
|
new_cs = (cache_system_t *) (hunk_base + hunk_low_used);
|
||||||
memset (new, 0, sizeof(*new));
|
memset (new_cs, 0, sizeof(*new_cs));
|
||||||
new->size = size;
|
new_cs->size = size;
|
||||||
|
|
||||||
cache_head.prev = cache_head.next = new;
|
cache_head.prev = cache_head.next = new_cs;
|
||||||
new->prev = new->next = &cache_head;
|
new_cs->prev = new_cs->next = &cache_head;
|
||||||
|
|
||||||
Cache_MakeLRU (new);
|
Cache_MakeLRU (new_cs);
|
||||||
return new;
|
return new_cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// search from the bottom up for space
|
// search from the bottom up for space
|
||||||
|
|
||||||
new = (cache_system_t *) (hunk_base + hunk_low_used);
|
new_cs = (cache_system_t *) (hunk_base + hunk_low_used);
|
||||||
cs = cache_head.next;
|
cs = cache_head.next;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!nobottom || cs != cache_head.next)
|
if (!nobottom || cs != cache_head.next)
|
||||||
{
|
{
|
||||||
if ( (byte *)cs - (byte *)new >= size)
|
if ( (byte *)cs - (byte *)new_cs >= size)
|
||||||
{ // found space
|
{ // found space
|
||||||
memset (new, 0, sizeof(*new));
|
memset (new_cs, 0, sizeof(*new_cs));
|
||||||
new->size = size;
|
new_cs->size = size;
|
||||||
|
|
||||||
new->next = cs;
|
new_cs->next = cs;
|
||||||
new->prev = cs->prev;
|
new_cs->prev = cs->prev;
|
||||||
cs->prev->next = new;
|
cs->prev->next = new_cs;
|
||||||
cs->prev = new;
|
cs->prev = new_cs;
|
||||||
|
|
||||||
Cache_MakeLRU (new);
|
Cache_MakeLRU (new_cs);
|
||||||
|
|
||||||
return new;
|
return new_cs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// continue looking
|
// continue looking
|
||||||
new = (cache_system_t *)((byte *)cs + cs->size);
|
new_cs = (cache_system_t *)((byte *)cs + cs->size);
|
||||||
cs = cs->next;
|
cs = cs->next;
|
||||||
|
|
||||||
} while (cs != &cache_head);
|
} while (cs != &cache_head);
|
||||||
|
|
||||||
// try to allocate one at the very end
|
// try to allocate one at the very end
|
||||||
if ( hunk_base + hunk_size - hunk_high_used - (byte *)new >= size)
|
if ( hunk_base + hunk_size - hunk_high_used - (byte *)new_cs >= size)
|
||||||
{
|
{
|
||||||
memset (new, 0, sizeof(*new));
|
memset (new_cs, 0, sizeof(*new_cs));
|
||||||
new->size = size;
|
new_cs->size = size;
|
||||||
|
|
||||||
new->next = &cache_head;
|
new_cs->next = &cache_head;
|
||||||
new->prev = cache_head.prev;
|
new_cs->prev = cache_head.prev;
|
||||||
cache_head.prev->next = new;
|
cache_head.prev->next = new_cs;
|
||||||
cache_head.prev = new;
|
cache_head.prev = new_cs;
|
||||||
|
|
||||||
Cache_MakeLRU (new);
|
Cache_MakeLRU (new_cs);
|
||||||
|
|
||||||
return new;
|
return new_cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL; // couldn't allocate
|
return NULL; // couldn't allocate
|
||||||
|
@ -1160,10 +1195,9 @@ Throw everything out, so new data will be demand cached
|
||||||
void Cache_Flush (void)
|
void Cache_Flush (void)
|
||||||
{
|
{
|
||||||
while (cache_head.next != &cache_head)
|
while (cache_head.next != &cache_head)
|
||||||
Cache_Free ( cache_head.next->user ); // reclaim the space
|
Cache_Free ( cache_head.next->user); // reclaim the space
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
============
|
============
|
||||||
Cache_Print
|
Cache_Print
|
||||||
|
@ -1174,10 +1208,9 @@ void Cache_Print (void)
|
||||||
{
|
{
|
||||||
cache_system_t *cd;
|
cache_system_t *cd;
|
||||||
|
|
||||||
Con_Printf("\n===\nCache System Dump\n===\n");
|
|
||||||
for (cd = cache_head.next ; cd != &cache_head ; cd = cd->next)
|
for (cd = cache_head.next ; cd != &cache_head ; cd = cd->next)
|
||||||
{
|
{
|
||||||
Con_Printf("* NAME: %s | SIZE: %.2fkB", cd->name, (float)(cd->size/1024));
|
Con_Printf ("%8i : %s\n", cd->size, cd->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1192,16 +1225,6 @@ void Cache_Report (void)
|
||||||
Con_DPrintf ("%4.1f megabyte data cache\n", (hunk_size - hunk_high_used - hunk_low_used) / (float)(1024*1024) );
|
Con_DPrintf ("%4.1f megabyte data cache\n", (hunk_size - hunk_high_used - hunk_low_used) / (float)(1024*1024) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
============
|
|
||||||
Cache_Compact
|
|
||||||
|
|
||||||
============
|
|
||||||
*/
|
|
||||||
void Cache_Compact (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
============
|
============
|
||||||
Cache_Init
|
Cache_Init
|
||||||
|
@ -1275,7 +1298,7 @@ void *Cache_Alloc (cache_user_t *c, int size, char *name)
|
||||||
cache_system_t *cs;
|
cache_system_t *cs;
|
||||||
|
|
||||||
if (c->data)
|
if (c->data)
|
||||||
Sys_Error ("Cache_Alloc: allready allocated");
|
Sys_Error ("Cache_Alloc: already allocated");
|
||||||
|
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
Sys_Error ("Cache_Alloc: size %i", size);
|
Sys_Error ("Cache_Alloc: size %i", size);
|
||||||
|
@ -1288,19 +1311,17 @@ void *Cache_Alloc (cache_user_t *c, int size, char *name)
|
||||||
cs = Cache_TryAlloc (size, false);
|
cs = Cache_TryAlloc (size, false);
|
||||||
if (cs)
|
if (cs)
|
||||||
{
|
{
|
||||||
strncpy (cs->name, name, sizeof(cs->name)-1);
|
strlcpy (cs->name, name, CACHENAME_LEN);
|
||||||
c->data = (void *)(cs+1);
|
c->data = (void *)(cs+1);
|
||||||
cs->user = c;
|
cs->user = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// free the least recently used cahedat
|
// free the least recently used cahedat
|
||||||
if (cache_head.lru_prev == &cache_head) {
|
if (cache_head.lru_prev == &cache_head)
|
||||||
Cache_Print();
|
Sys_Error ("Cache_Alloc: out of memory"); // not enough memory at all
|
||||||
Sys_Error ("Cache_Alloc: out of memory");
|
|
||||||
}
|
Cache_Free (cache_head.lru_prev->user);
|
||||||
// not enough memory at all
|
|
||||||
Cache_Free ( cache_head.lru_prev->user );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Cache_Check (c);
|
return Cache_Check (c);
|
||||||
|
@ -1309,6 +1330,25 @@ void *Cache_Alloc (cache_user_t *c, int size, char *name)
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
void Memory_InitZone (memzone_t *zone, int size)
|
||||||
|
{
|
||||||
|
memblock_t *block;
|
||||||
|
|
||||||
|
// set the entire zone to one free block
|
||||||
|
|
||||||
|
zone->blocklist.next = zone->blocklist.prev = block =
|
||||||
|
(memblock_t *)( (byte *)zone + sizeof(memzone_t) );
|
||||||
|
zone->blocklist.tag = 1; // in use block
|
||||||
|
zone->blocklist.id = 0;
|
||||||
|
zone->blocklist.size = 0;
|
||||||
|
zone->rover = block;
|
||||||
|
|
||||||
|
block->prev = block->next = &zone->blocklist;
|
||||||
|
block->tag = 0; // free block
|
||||||
|
block->id = ZONEID;
|
||||||
|
block->size = size - sizeof(memzone_t);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
========================
|
========================
|
||||||
Memory_Init
|
Memory_Init
|
||||||
|
@ -1319,7 +1359,7 @@ void Memory_Init (void *buf, int size)
|
||||||
int p;
|
int p;
|
||||||
int zonesize = DYNAMIC_SIZE;
|
int zonesize = DYNAMIC_SIZE;
|
||||||
|
|
||||||
hunk_base = buf;
|
hunk_base = (byte *) buf;
|
||||||
hunk_size = size;
|
hunk_size = size;
|
||||||
hunk_low_used = 0;
|
hunk_low_used = 0;
|
||||||
hunk_high_used = 0;
|
hunk_high_used = 0;
|
||||||
|
@ -1333,7 +1373,9 @@ void Memory_Init (void *buf, int size)
|
||||||
else
|
else
|
||||||
Sys_Error ("Memory_Init: you must specify a size in KB after -zone");
|
Sys_Error ("Memory_Init: you must specify a size in KB after -zone");
|
||||||
}
|
}
|
||||||
mainzone = Hunk_AllocName (zonesize, "zone" );
|
mainzone = (memzone_t *) Hunk_AllocName (zonesize, "zone" );
|
||||||
Z_ClearZone (mainzone, zonesize);
|
Memory_InitZone (mainzone, zonesize);
|
||||||
|
|
||||||
|
Cmd_AddCommand ("hunk_print", Hunk_Print_f); //johnfitz
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (C) 1996-1997 Id Software, Inc.
|
Copyright (C) 1996-2001 Id Software, Inc.
|
||||||
|
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||||
|
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
|
@ -8,7 +10,7 @@ of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
See the GNU General Public License for more details.
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
@ -17,6 +19,10 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZZONE_H
|
||||||
|
#define __ZZONE_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
memory allocation
|
memory allocation
|
||||||
|
|
||||||
|
@ -92,16 +98,13 @@ void *Q_strdup (const char *str); //
|
||||||
|
|
||||||
void Z_Free (void *ptr);
|
void Z_Free (void *ptr);
|
||||||
void *Z_Malloc (int size); // returns 0 filled memory
|
void *Z_Malloc (int size); // returns 0 filled memory
|
||||||
void *Z_TagMalloc (int size, int tag);
|
void *Z_Realloc (void *ptr, int size);
|
||||||
|
char *Z_Strdup (char *s);
|
||||||
void Z_DumpHeap (void);
|
|
||||||
void Z_CheckHeap (void);
|
|
||||||
int Z_FreeMemory (void);
|
|
||||||
|
|
||||||
void *Hunk_Alloc (int size); // returns 0 filled memory
|
void *Hunk_Alloc (int size); // returns 0 filled memory
|
||||||
void *Hunk_AllocName (int size, char *name);
|
void *Hunk_AllocName (int size, char *name);
|
||||||
|
|
||||||
void *Hunk_HighAllocName (int size, char *name);
|
void *Hunk_HighAllocName (int size, char *name);
|
||||||
|
char *Hunk_Strdup (char *s, char *name);
|
||||||
|
|
||||||
int Hunk_LowMark (void);
|
int Hunk_LowMark (void);
|
||||||
void Hunk_FreeToLowMark (int mark);
|
void Hunk_FreeToLowMark (int mark);
|
||||||
|
@ -134,3 +137,4 @@ void Cache_Report (void);
|
||||||
|
|
||||||
void* memcpy_vfpu(void* dst, void* src, unsigned int size);
|
void* memcpy_vfpu(void* dst, void* src, unsigned int size);
|
||||||
|
|
||||||
|
#endif /* __ZZONE_H */
|
Loading…
Reference in a new issue