From: molivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Tue, 23 Mar 2004 07:59:09 +0000 (+0000)
Subject: Added a mempool parameter to FS_LoadFile
X-Git-Tag: xonotic-v0.1.0preview~5966
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1e1dbc1c5b89ae4ab8cdd9b32dc6413c67f5dd84;p=xonotic%2Fdarkplaces.git

Added a mempool parameter to FS_LoadFile


git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4051 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/cl_particles.c b/cl_particles.c
index 1a6ae07d..790abe05 100644
--- a/cl_particles.c
+++ b/cl_particles.c
@@ -542,7 +542,7 @@ void CL_ReadPointFile_f (void)
 #if WORKINGLQUAKE
 	pointfile = COM_LoadTempFile (name);
 #else
-	pointfile = FS_LoadFile(name, true);
+	pointfile = FS_LoadFile(name, tempmempool, true);
 #endif
 	if (!pointfile)
 	{
diff --git a/cmd.c b/cmd.c
index ec5e3cb5..acba1396 100644
--- a/cmd.c
+++ b/cmd.c
@@ -294,7 +294,7 @@ static void Cmd_Exec_f (void)
 		return;
 	}
 
-	f = (char *)FS_LoadFile (Cmd_Argv(1), false);
+	f = (char *)FS_LoadFile (Cmd_Argv(1), tempmempool, false);
 	if (!f)
 	{
 		Con_Printf("couldn't exec %s\n",Cmd_Argv(1));
diff --git a/fs.c b/fs.c
index cebf3e4c..093d0ac9 100644
--- a/fs.c
+++ b/fs.c
@@ -1719,7 +1719,7 @@ Filename are relative to the quake directory.
 Always appends a 0 byte.
 ============
 */
-qbyte *FS_LoadFile (const char *path, qboolean quiet)
+qbyte *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet)
 {
 	qfile_t *h;
 	qbyte *buf;
@@ -1729,7 +1729,7 @@ qbyte *FS_LoadFile (const char *path, qboolean quiet)
 	if (!h)
 		return NULL;
 
-	buf = Mem_Alloc(tempmempool, fs_filesize+1);
+	buf = Mem_Alloc(pool, fs_filesize+1);
 	if (!buf)
 		Sys_Error ("FS_LoadFile: not enough available memory for %s (size %i)", path, fs_filesize);
 
diff --git a/fs.h b/fs.h
index da3b6a00..228b75b6 100644
--- a/fs.h
+++ b/fs.h
@@ -70,7 +70,7 @@ fssearch_t;
 fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet);
 void FS_FreeSearch(fssearch_t *search);
 
-qbyte *FS_LoadFile (const char *path, qboolean quiet);
+qbyte *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet);
 qboolean FS_WriteFile (const char *filename, void *data, int len);
 
 
diff --git a/gl_rmain.c b/gl_rmain.c
index bcaf390d..76123a6f 100644
--- a/gl_rmain.c
+++ b/gl_rmain.c
@@ -239,7 +239,7 @@ void gl_main_newmap(void)
 		if (l >= 0 && !strcmp(entname + l, ".bsp"))
 		{
 			strcpy(entname + l, ".ent");
-			if ((entities = FS_LoadFile(entname, true)))
+			if ((entities = FS_LoadFile(entname, tempmempool, true)))
 			{
 				CL_ParseEntityLump(entities);
 				Mem_Free(entities);
diff --git a/image.c b/image.c
index 4dae89a9..2d3882c9 100644
--- a/image.c
+++ b/image.c
@@ -655,7 +655,7 @@ qbyte *loadimagepixels (const char *filename, qboolean complain, int matchwidth,
 	for (i = 0;imageformats[i].formatstring;i++)
 	{
 		sprintf (name, imageformats[i].formatstring, basename);
-		f = FS_LoadFile(name, true);
+		f = FS_LoadFile(name, tempmempool, true);
 		if (f)
 		{
 			data = imageformats[i].loadfunc(f, matchwidth, matchheight);
diff --git a/menu.c b/menu.c
index 180fb135..c486bcb6 100644
--- a/menu.c
+++ b/menu.c
@@ -991,7 +991,7 @@ void M_Setup_Draw (void)
 		menuplyr_load = false;
 		menuplyr_top = -1;
 		menuplyr_bottom = -1;
-		if ((f = FS_LoadFile("gfx/menuplyr.lmp", true)))
+		if ((f = FS_LoadFile("gfx/menuplyr.lmp", tempmempool, true)))
 		{
 			data = LoadLMPAs8Bit (f, 0, 0);
 			menuplyr_width = image_width;
diff --git a/model_brush.c b/model_brush.c
index 28714ec9..40c3dc94 100644
--- a/model_brush.c
+++ b/model_brush.c
@@ -1209,7 +1209,7 @@ static void Mod_Q1BSP_LoadLighting(lump_t *l)
 		strlcpy (litfilename, loadmodel->name, sizeof (litfilename));
 		FS_StripExtension (litfilename, litfilename, sizeof (litfilename));
 		strlcat (litfilename, ".lit", sizeof (litfilename));
-		data = (qbyte*) FS_LoadFile(litfilename, false);
+		data = (qbyte*) FS_LoadFile(litfilename, tempmempool, false);
 		if (data)
 		{
 			if (fs_filesize > 8 && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
@@ -1264,7 +1264,7 @@ static void Mod_Q1BSP_LoadLightList(void)
 	strlcpy (lightsfilename, loadmodel->name, sizeof (lightsfilename));
 	FS_StripExtension (lightsfilename, lightsfilename, sizeof(lightsfilename));
 	strlcat (lightsfilename, ".lights", sizeof (lightsfilename));
-	s = lightsstring = (char *) FS_LoadFile(lightsfilename, false);
+	s = lightsstring = (char *) FS_LoadFile(lightsfilename, tempmempool, false);
 	if (s)
 	{
 		numlights = 0;
@@ -3592,7 +3592,7 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l)
 	{
 		for (i = 0;i < search->numfilenames;i++)
 		{
-			if ((f = FS_LoadFile(search->filenames[i], false)))
+			if ((f = FS_LoadFile(search->filenames[i], tempmempool, false)))
 			{
 				text = f;
 				while (COM_ParseToken(&text, false))
diff --git a/model_shared.c b/model_shared.c
index 634c799f..39274584 100644
--- a/model_shared.c
+++ b/model_shared.c
@@ -264,7 +264,7 @@ static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk,
 	{
 		if (checkdisk)
 		{
-			buf = FS_LoadFile (mod->name, false);
+			buf = FS_LoadFile (mod->name, tempmempool, false);
 			if (!buf)
 			{
 				if (crash)
@@ -289,7 +289,7 @@ static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk,
 
 	if (!buf)
 	{
-		buf = FS_LoadFile (mod->name, false);
+		buf = FS_LoadFile (mod->name, tempmempool, false);
 		if (!buf)
 		{
 			if (crash)
@@ -1107,7 +1107,7 @@ tag_torso,
 */
 	memset(tagsets, 0, sizeof(tagsets));
 	memset(word, 0, sizeof(word));
-	for (i = 0;i < MAX_SKINS && (data = text = FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), true));i++)
+	for (i = 0;i < MAX_SKINS && (data = text = FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true));i++)
 	{
 		numtags = 0;
 		skinfile = Mem_Alloc(tempmempool, sizeof(skinfile_t));
diff --git a/palette.c b/palette.c
index 0f76f372..3e1bd563 100644
--- a/palette.c
+++ b/palette.c
@@ -46,7 +46,7 @@ void Palette_Setup8to24(void)
 	palette_complete[255] = 0; // completely transparent black
 
 	// FIXME: fullbright_start should be read from colormap.lmp
-	colormap = FS_LoadFile("gfx/colormap.lmp", true);
+	colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true);
 	if (colormap && fs_filesize >= 16385)
 		fullbright_start = 256 - colormap[16384];
 	else
@@ -181,7 +181,7 @@ void Palette_Init(void)
 	float gamma, scale, base;
 	qbyte *pal;
 	qbyte temp[256];
-	pal = (qbyte *)FS_LoadFile ("gfx/palette.lmp", false);
+	pal = (qbyte *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false);
 	if (pal && fs_filesize >= 768)
 	{
 		memcpy(host_basepal, pal, 765);
diff --git a/pr_edict.c b/pr_edict.c
index 151e62f0..2f512093 100644
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -1251,7 +1251,6 @@ void PR_LoadProgs (void)
 	int i;
 	dstatement_t *st;
 	ddef_t *infielddefs;
-	void *temp;
 	dfunction_t *dfunctions;
 
 // flush the non-C variable lookup cache
@@ -1261,15 +1260,10 @@ void PR_LoadProgs (void)
 	Mem_EmptyPool(progs_mempool);
 	Mem_EmptyPool(edictstring_mempool);
 
-	temp = FS_LoadFile ("progs.dat", false);
-	if (!temp)
+	progs = (dprograms_t *)FS_LoadFile ("progs.dat", progs_mempool, false);
+	if (!progs)
 		Host_Error ("PR_LoadProgs: couldn't load progs.dat");
 
-	progs = (dprograms_t *)Mem_Alloc(progs_mempool, fs_filesize);
-
-	memcpy(progs, temp, fs_filesize);
-	Mem_Free(temp);
-
 	Con_DPrintf("Programs occupy %iK.\n", fs_filesize/1024);
 
 	pr_crc = CRC_Block((qbyte *)progs, fs_filesize);
diff --git a/prvm_cmds.c b/prvm_cmds.c
index bfc904d3..f19deb65 100644
--- a/prvm_cmds.c
+++ b/prvm_cmds.c
@@ -2266,7 +2266,7 @@ void VM_loadfromfile(void)
 	}
 
 	// not conform with VM_fopen
-	data = FS_LoadFile(filename, false);
+	data = FS_LoadFile(filename, tempmempool, false);
 	if (data == NULL)
 		PRVM_G_FLOAT(OFS_RETURN) = -1;
 	
diff --git a/prvm_edict.c b/prvm_edict.c
index 4baf85d5..4cc58724 100644
--- a/prvm_edict.c
+++ b/prvm_edict.c
@@ -1269,21 +1269,15 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required
 	int i;
 	dstatement_t *st;
 	ddef_t *infielddefs;
-	void *temp;
 	dfunction_t *dfunctions;
 
 	Mem_EmptyPool(prog->progs_mempool);
 	Mem_EmptyPool(prog->edictstring_mempool);
 
-	temp = FS_LoadFile (filename, false);
-	if (temp == 0)
+	prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false);
+	if (prog->progs == NULL)
 		PRVM_ERROR ("PRVM_LoadProgs: couldn't load %s for %s", filename, PRVM_NAME);
 
-	prog->progs = (dprograms_t *)Mem_Alloc(prog->progs_mempool, fs_filesize);
-
-	memcpy(prog->progs, temp, fs_filesize);
-	Mem_Free(temp);
-
 	Con_DPrintf("%s programs occupy %iK.\n", PRVM_NAME, fs_filesize/1024);
 
 	pr_crc = CRC_Block((qbyte *)prog->progs, fs_filesize);
diff --git a/r_shadow.c b/r_shadow.c
index 72d06b22..ac7d08c1 100644
--- a/r_shadow.c
+++ b/r_shadow.c
@@ -2468,7 +2468,7 @@ void R_Shadow_LoadWorldLights(void)
 	}
 	FS_StripExtension (cl.worldmodel->name, name, sizeof (name));
 	strlcat (name, ".rtlights", sizeof (name));
-	lightsstring = FS_LoadFile(name, false);
+	lightsstring = FS_LoadFile(name, tempmempool, false);
 	if (lightsstring)
 	{
 		s = lightsstring;
@@ -2586,7 +2586,7 @@ void R_Shadow_LoadLightsFile(void)
 	}
 	FS_StripExtension (cl.worldmodel->name, name, sizeof (name));
 	strlcat (name, ".lights", sizeof (name));
-	lightsstring = FS_LoadFile(name, false);
+	lightsstring = FS_LoadFile(name, tempmempool, false);
 	if (lightsstring)
 	{
 		s = lightsstring;
diff --git a/snd_mem.c b/snd_mem.c
index 94027d43..d0671eb8 100644
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -221,7 +221,7 @@ sfxcache_t *S_LoadWavFile (const char *filename, sfx_t *s)
 	sfxcache_t *sc;
 
 	// Load the file
-	data = FS_LoadFile(filename, false);
+	data = FS_LoadFile(filename, tempmempool, false);
 	if (!data)
 		return NULL;
 
diff --git a/snd_ogg.c b/snd_ogg.c
index 8acedc7c..bf7bd2a3 100644
--- a/snd_ogg.c
+++ b/snd_ogg.c
@@ -380,7 +380,7 @@ sfxcache_t *OGG_LoadVorbisFile (const char *filename, sfx_t *s)
 		return NULL;
 
 	// Load the file
-	data = FS_LoadFile (filename, false);
+	data = FS_LoadFile (filename, tempmempool, false);
 	if (data == NULL)
 		return NULL;
 
diff --git a/sv_main.c b/sv_main.c
index d5b05b5d..4bd02928 100644
--- a/sv_main.c
+++ b/sv_main.c
@@ -1927,7 +1927,7 @@ void SV_SpawnServer (const char *server)
 	// load replacement entity file if found
 	entities = NULL;
 	if (sv_entpatch.integer)
-		entities = FS_LoadFile(va("maps/%s.ent", sv.name), true);
+		entities = FS_LoadFile(va("maps/%s.ent", sv.name), tempmempool, true);
 	if (entities)
 	{
 		Con_Printf("Loaded maps/%s.ent\n", sv.name);
diff --git a/wad.c b/wad.c
index c1ceb126..44f39f31 100644
--- a/wad.c
+++ b/wad.c
@@ -73,7 +73,7 @@ void *W_GetLumpName(char *name)
 	if (!wad_loaded)
 	{
 		wad_loaded = true;
-		if ((temp = FS_LoadFile ("gfx.wad", false)))
+		if ((temp = FS_LoadFile ("gfx.wad", tempmempool, false)))
 		{
 			if (memcmp(temp, "WAD2", 4))
 				Con_Print("gfx.wad doesn't have WAD2 id\n");