From 69a35ba645a27f682facdbe7b99b781e5bd19e9c Mon Sep 17 00:00:00 2001 From: sezero Date: Sat, 11 Feb 2012 14:30:19 +0000 Subject: [PATCH] gl_texmgr.c (TexMgr_ReloadImage): reduced the hunk memory usage during reloading of images from the bsp by not loading the whole file but by opening the file, fseek()ing and allocating only the necessary amount. This way, I can load and reload a save of ne_ruins with just the default 64 Mb of memory on x86 and with only 68.5 Mb of memory (-heapsize 70000) on x86_64. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@633 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/gl_texmgr.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Quake/gl_texmgr.c b/Quake/gl_texmgr.c index e2518cc7..e213bccb 100644 --- a/Quake/gl_texmgr.c +++ b/Quake/gl_texmgr.c @@ -1235,10 +1235,21 @@ void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants) if (glt->source_file[0] && glt->source_offset) { //lump inside file - data = COM_LoadHunkFile (glt->source_file, NULL); - if (!data) + long size; + FILE *f; + COM_FOpenFile(glt->source_file, &f, NULL); + if (!f) goto invalid; - data += glt->source_offset; + fseek (f, glt->source_offset, SEEK_CUR); + size = (long) (glt->source_width * glt->source_height); + /* should be SRC_INDEXED, but no harm being paranoid: */ + if (glt->source_format == SRC_RGBA) + size *= 4; + else if (glt->source_format == SRC_LIGHTMAP) + size *= lightmap_bytes; + data = Hunk_Alloc (size); + fread (data, 1, size, f); + fclose (f); } else if (glt->source_file[0] && !glt->source_offset) data = Image_LoadImage (glt->source_file, (int *)&glt->source_width, (int *)&glt->source_height); //simple file