Esempio n. 1
0
/*
==============
Cache_Alloc
==============
*/
void *Cache_Alloc (cache_user_t *c, int size, const char *name)
{
	cache_system_t	*cs;

	if (c->data)
		Sys_Error ("%s: %s is already allocated", __thisfunc__, name);

	if (size <= 0)
		Sys_Error ("%s: bad size %i for %s", __thisfunc__, size, name);

	size = (size + sizeof(cache_system_t) + 15) & ~15;

// find memory for it
	while (1)
	{
		cs = Cache_TryAlloc (size, false);
		if (cs)
		{
			q_strlcpy (cs->name, name, CACHENAME_LEN);
			c->data = (void *)(cs + 1);
			cs->user = c;
			break;
		}

	// free the least recently used cahedat
		if (cache_head.lru_prev == &cache_head)	// not enough memory at all
			Sys_Error ("%s: out of memory", __thisfunc__);
		Cache_Free ( cache_head.lru_prev->user );
	}

	return Cache_Check (c);
}
void CAudioSourceMP3Cache::CacheUnload( void )
{
	if ( !m_cache.data )
		return;

	Cache_Free( &m_cache );
}
Esempio n. 3
0
/*
==============
Cache_Alloc
==============
*/
void *Cache_Alloc (cache_user_t *c, int size, const char *name)
{
	cache_system_t	*cs;

	if (c->data)
		Sys_Error ("Cache_Alloc: already allocated");
	
	if (size <= 0)
		Sys_Error ("Cache_Alloc: size %i", size);

	size = (size + sizeof(cache_system_t) + 15) & ~15;

// find memory for it	
	while (1)
	{
		cs = Cache_TryAlloc (size, false);
		if (cs)
		{
			Q_strncpy(cs->name, name, sizeof(cs->name));
			c->data = (void *)(cs+1);
			cs->user = c;
			break;
		}

	// free the least recently used entry
		// assume if it's a locked entry that we've run out.
		if (cache_head.lru_prev == &cache_head || cache_head.lru_prev->locked)
			Sys_Error ("Cache_Alloc: out of memory");
		
		Cache_Free ( cache_head.lru_prev->user );
	}
	
	return Cache_Check (c);
}
Esempio n. 4
0
/*
 * ==============
 * Cache_AllocPadded
 * ==============
 */
void *
Cache_AllocPadded(cache_user_t *c, int pad, int size, const char *name)
{
    cache_system_t *cs;

    if (c->data)
	Sys_Error("%s: allready allocated", __func__);

    if (size <= 0)
	Sys_Error("%s: size %i", __func__, size);

    size = (size + pad + sizeof(cache_system_t) + 15) & ~15;

    /* find memory for it */
    while (1) {
	cs = Cache_TryAlloc(size, false);
	if (cs) {
	    strncpy(cs->name, name, sizeof(cs->name) - 1);
	    cs->user = c;
	    c->pad = pad;
	    c->data = Cache_Data(cs);
	    break;
	}
	/* free the least recently used cache data */
	if (cache_head.lru_prev == &cache_head)
	    Sys_Error("%s: out of memory", __func__);
	/* not enough memory at all */
	Cache_Free(cache_head.lru_prev->user);
    }

    return Cache_Check(c);
}
Esempio n. 5
0
File: zone.cpp Progetto: m4c0/Quake
/*
==============
Cache_Alloc
==============
*/
void *Cache_Alloc (cache_user_t *c, int size, const char *name)
{
	cache_system_t	*cs;

	if (c->data)
		Sys_Error ("Cache_Alloc: allready allocated");
	
	if (size <= 0)
		Sys_Error ("Cache_Alloc: size %i", size);

	size = (size + sizeof(cache_system_t) + 15) & ~15;

// find memory for it	
	while (1)
	{
		cs = Cache_TryAlloc (size, false);
		if (cs)
		{
			strncpy (cs->name, name, sizeof(cs->name)-1);
			c->data = (void *)(cs+1);
			cs->user = c;
			break;
		}
	
	// free the least recently used cahedat
		if (cache_head.lru_prev == &cache_head)
			Sys_Error ("Cache_Alloc: out of memory");
													// not enough memory at all
		Cache_Free ( cache_head.lru_prev->user );
	} 
	
	return Cache_Check (c);
}
Esempio n. 6
0
File: zone.c Progetto: deurk/mvdsv
/*
===========
Cache_Move
===========
*/
void Cache_Move(cache_system_t *c)
{
	cache_system_t *new_block;

	// we are clearing up space at the bottom, so only allocate it late
	new_block = Cache_TryAlloc(c->size, true);
	if (new_block) {
		memcpy(new_block + 1, c + 1, c->size - sizeof(cache_system_t));
		new_block->user = c->user;
		memcpy(new_block->name, c->name, sizeof(new_block->name));
		Cache_Free(c->user);
		new_block->user->data = (void *)(new_block + 1);
	}
	else {
		Cache_Free(c->user); // tough luck...
	}
}
Esempio n. 7
0
File: zone.c Progetto: deurk/mvdsv
/*
============
Cache_Flush

Throw everything out, so new data will be demand cached
============
*/
void Cache_Flush(void)
{
	while (cache_head.next != &cache_head) {
		Cache_Free(cache_head.next->user); // reclaim the space
	}
#ifndef SERVERONLY
	Mod_ClearSimpleTextures();
#endif
}
Esempio n. 8
0
/*
==========
Skin_Flush
==========
*/
void Skin_Flush (void)
{
	int		i;

	for (i=0 ; i<numskins ; i++)
	{
		if (skins[i].cache.data)
			Cache_Free (&skins[i].cache);
	}

	numskins = 0;
}
Esempio n. 9
0
/*
 * ===========
 * Cache_Move
 * ===========
 */
static void
Cache_Move(cache_system_t *c)
{
    cache_system_t *newobj;
    int pad;

    /* we are clearing up space at the bottom, so only allocate it late */
    newobj = Cache_TryAlloc(c->size, true);
    if (newobj) {
	memcpy(newobj + 1, c + 1, c->size - sizeof(cache_system_t));
	newobj->user = c->user;
	memcpy(newobj->name, c->name, sizeof(newobj->name));
	pad = c->user->pad;
	Cache_Free(c->user);
	newobj->user->pad = pad;
	newobj->user->data = Cache_Data(newobj);
    } else {
	/* tough luck... */
	Cache_Free(c->user);
    }
}
Esempio n. 10
0
/* <99d0> ../engine/com_custom.c:19 */
void COM_ClearCustomizationList(customization_t *pHead, qboolean bCleanDecals)
{
	customization_s *pCurrent, *pNext;
	cachewad_t *pWad;
	cachepic_t *pic;

	pCurrent = pHead->pNext;
	if (!pCurrent)
		return;

	while (pCurrent)
	{
		pNext = pCurrent->pNext;

		if (pCurrent->bInUse)
		{
			if (pCurrent->pBuffer)
				Mem_Free(pCurrent->pBuffer);

			if (pCurrent->pInfo)
			{
				if (pCurrent->resource.type == t_decal)
				{
					if (bCleanDecals && g_pcls.state == ca_active)
					{
						R_DecalRemoveAll(-1 - pCurrent->resource.playernum);
					}

					pWad = (cachewad_t *)pCurrent->pInfo;

					Mem_Free(pWad->lumps);

					for (int i = 0; i < pWad->cacheCount; i++)
					{
						pic = &pWad->cache[i];
						if (Cache_Check(&pic->cache))
							Cache_Free(&pic->cache);
					}

					Mem_Free(pWad->name);
					Mem_Free(pWad->cache);
				}

				Mem_Free(pCurrent->pInfo);
			}
		}

		Mem_Free(pCurrent);
		pCurrent = pNext;
	}

	pHead->pNext = NULL;
}
Esempio n. 11
0
/*
===========
Cache_Move
===========
*/
static void Cache_Move ( cache_system_t *c)
{
	cache_system_t		*new_cs;

// we are clearing up space at the bottom, so only allocate it late
	new_cs = Cache_TryAlloc (c->size, true);
	if (new_cs)
	{
	//	Con_Printf ("cache_move ok\n");
		memcpy (new_cs+1, c+1, c->size - sizeof(cache_system_t));
		new_cs->user = c->user;
		memcpy (new_cs->name, c->name, sizeof(new_cs->name));
		Cache_Free (c->user);
		new_cs->user->data = (void *)(new_cs + 1);
	}
	else
	{
	//	Con_Printf ("cache_move failed\n");
		Cache_Free (c->user);	// tough luck...
	}
}
Esempio n. 12
0
/*
================
S_Restart
================
*/
void S_Restart (void)
{
	int		i;

	S_Shutdown ();

	// flush all sounds
	for (i = 0; i < num_sfx; i++) {
		if (known_sfx[i].cache.data)
			Cache_Free (&known_sfx[i].cache);
	}

	S_Init ();
}
Esempio n. 13
0
/*
==========
Skin_Skins_f

Refind all skins, downloading if needed.
==========
*/
void	Skin_Skins_f (void)
{
	int		i;

	for (i=0 ; i<numskins ; i++)
	{
		if (skins[i].cache.data)
			Cache_Free (&skins[i].cache);
	}
	numskins = 0;

	cls.downloadnumber = 0;
	cls.downloadtype = dl_skin;
	Skin_NextDownload ();
}
Esempio n. 14
0
/*
==================
Mod_FindName

==================
*/
model_t *Mod_FindName (char *name)
{
	int		i;
	model_t	*mod;
	model_t	*avail = NULL;

	if (!name[0])
		Sys_Error ("Mod_ForName: NULL name");
		
//
// search the currently loaded models
//
	for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
	{
		if (!strcmp (mod->name, name) )
			break;
		if (mod->needload == NL_UNREFERENCED)
			if (!avail || mod->type != mod_alias)
				avail = mod;
	}
			
	if (i == mod_numknown)
	{
		if (mod_numknown == MAX_MOD_KNOWN)
		{
			if (avail)
			{
				mod = avail;
				if (mod->type == mod_alias)
					if (Cache_Check (&mod->cache))
						Cache_Free (&mod->cache);
			}
			else
				Sys_Error ("mod_numknown == MAX_MOD_KNOWN");
		}
		else
			mod_numknown++;
		strcpy (mod->name, name);
		mod->needload = NL_NEEDS_LOADED;
	}

	return mod;
}
Esempio n. 15
0
/*
 * ============
 * Cache_FreeHigh
 *
 * Throw things out until the hunk can be expanded to the given point
 * ============
 */
static void
Cache_FreeHigh(int new_high_hunk)
{
    cache_system_t *c, *prev;

    prev = NULL;
    while (1) {
	c = cache_head.prev;
	if (c == &cache_head)
	    return;		/* nothing in cache at all */
	if ((byte *)c + c->size <= hunk_base + hunk_size - new_high_hunk)
	    return;		/* there is space to grow the hunk */
	if (c == prev)
	    Cache_Free(c->user);	/* didn't move out of the way */
	else {
	    Cache_Move(c);	/* try to move it */
	    prev = c;
	}
    }
}
Esempio n. 16
0
//Refind all skins, downloading if needed.
void Skin_Skins_f (void) {
	int i;

	for (i = 0; i < numskins; i++) {
		if (skins[i].cache.data)
			Cache_Free (&skins[i].cache);
	}
	numskins = 0;

	skins_need_preache = true; // we need precache it ASAP

	cls.downloadnumber = 0;
	cls.downloadtype = dl_skin;
	Skin_NextDownload ();

	if (cls.mvdplayback == QTV_PLAYBACK && cbuf_current != &cbuf_main)
	{
		cls.qtv_donotbuffer = false;
	}
}
Esempio n. 17
0
/*
============
Cache_FreeHigh

Throw things out until the hunk can be expanded to the given point
============
*/
void Cache_FreeHigh (int new_high_hunk)
{
	cache_system_t	*c, *prev;

	prev = NULL;
	while (1)
	{
		c = cache_head.prev;
		if (c == &cache_head)
			return;		// nothing in cache at all
		if ( (byte *)c + c->size <= hunk_base + hunk_size - new_high_hunk)
			return;		// there is space to grow the hunk
		if (c == prev)
			Cache_Free (c->user, true);	// didn't move out of the way //johnfitz -- added second argument
		else
		{
			Cache_Move (c);	// try to move it
			prev = c;
		}
	}
}
Esempio n. 18
0
/*
==========
Skin_Skins_f

Refind all skins, downloading if needed.
==========
*/
void	Skin_Skins_f (void)
{
	int		i;

	for (i = 0; i < numskins; i++)
	{
		if (skins[i].cache.data)
			Cache_Free (&skins[i].cache);
	}
	numskins = 0;

	if (cls.state == ca_disconnected)
	{
		Con_Printf("%s: no connection to a server.\n", __thisfunc__);
		return;
	}

	cls.downloadnumber = 0;
	cls.downloadtype = dl_skin;
	Skin_NextDownload ();
}
Esempio n. 19
0
File: zone.c Progetto: deurk/mvdsv
/*
============
Cache_FreeHigh

Throw things out until the hunk can be expanded to the given point
============
*/
void Cache_FreeHigh(int new_high_hunk)
{
	cache_system_t *c, *prev;

	prev = NULL;
	while (1) {
		c = cache_head.prev;
		if (c == &cache_head) {
			return; // nothing in cache at all
		}
		if ((byte *)c + c->size <= hunk_base + hunk_size - new_high_hunk) {
			return; // there is space to grow the hunk
		}
		if (c == prev) {
			Cache_Free(c->user); // didn't move out of the way
		}
		else {
			Cache_Move(c); // try to move it
			prev = c;
		}
	}
}
Esempio n. 20
0
File: zone.cpp Progetto: m4c0/Quake
/*
============
Cache_Flush

Throw everything out, so new data will be demand cached
============
*/
void Cache_Flush (const quake::common::argv & argv)
{
	while (cache_head.next != &cache_head)
		Cache_Free ( cache_head.next->user );	// reclaim the space
}
Esempio n. 21
0
/*
============
Cache_Flush

Throw everything out, so newmem data will be demand cached
============
*/
void Cache_Flush (void)
{
	while (cache_head.next != &cache_head)
		Cache_Free ( cache_head.next->user );	// reclaim the space
}
Esempio n. 22
0
/*
============
Cache_Flush

Throw everything out, so new data will be demand cached
============
*/
void Cache_Flush (void)
{
	while (cache_head.next != &cache_head)
		Cache_Free ( cache_head.next->user, true); // reclaim the space //johnfitz -- added second argument
}
Esempio n. 23
0
/*
==========
Skin_Cache

Returns a pointer to the skin bitmap, or NULL to use the default
==========
*/
byte	*Skin_Cache (skin_t *skin)
{
	char	name[1024];
	byte	*raw;
	byte	*out, *pix;
	pcx_t	*pcx;
	int		x, y;
	int		dataByte;
	int		runLength;

	if (cls.downloadtype == dl_skin)
		return NULL;		// use base until downloaded

	if (noskins.value==1) // JACK: So NOSKINS > 1 will show skins, but
		return NULL;	  // not download new ones.

	if (skin->failedload)
		return NULL;

	out = Cache_Check (&skin->cache);
	if (out)
		return out;

//
// load the pic from disk
//
	sprintf (name, "skins/%s.pcx", skin->name);
	raw = COM_LoadTempFile (name);
	if (!raw)
	{
		Con_Printf ("Couldn't load skin %s\n", name);
		sprintf (name, "skins/%s.pcx", baseskin.string);
		raw = COM_LoadTempFile (name);
		if (!raw)
		{
			skin->failedload = true;
			return NULL;
		}
	}

//
// parse the PCX file
//
	pcx = (pcx_t *)raw;
	raw = &pcx->data;

	if (pcx->manufacturer != 0x0a
		|| pcx->version != 5
		|| pcx->encoding != 1
		|| pcx->bits_per_pixel != 8
		|| pcx->xmax >= 320
		|| pcx->ymax >= 200)
	{
		skin->failedload = true;
		Con_Printf ("Bad skin %s\n", name);
		return NULL;
	}
	
	out = Cache_Alloc (&skin->cache, 320*200, skin->name);
	if (!out)
		Sys_Error ("Skin_Cache: couldn't allocate");

	pix = out;
	memset (out, 0, 320*200);

	for (y=0 ; y<pcx->ymax ; y++, pix += 320)
	{
		for (x=0 ; x<=pcx->xmax ; )
		{
			if (raw - (byte*)pcx > com_filesize) 
			{
				Cache_Free (&skin->cache);
				skin->failedload = true;
				Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
				return NULL;
			}
			dataByte = *raw++;

			if((dataByte & 0xC0) == 0xC0)
			{
				runLength = dataByte & 0x3F;
				if (raw - (byte*)pcx > com_filesize) 
				{
					Cache_Free (&skin->cache);
					skin->failedload = true;
					Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
					return NULL;
				}
				dataByte = *raw++;
			}
			else
				runLength = 1;

			// skin sanity check
			if (runLength + x > pcx->xmax + 2) {
				Cache_Free (&skin->cache);
				skin->failedload = true;
				Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
				return NULL;
			}
			while(runLength-- > 0)
				pix[x++] = dataByte;
		}

	}

	if ( raw - (byte *)pcx > com_filesize)
	{
		Cache_Free (&skin->cache);
		skin->failedload = true;
		Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
		return NULL;
	}

	skin->failedload = false;

	return out;
}