Forum

GLQuake Memory Saving

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

GLQuake Memory Saving

Postby mh » Tue Jun 15, 2010 10:03 pm

GLQuake is very wasteful on memory. Here we're going to start saving some. This not only reduces overhead on Quake's Hunk memory (meaning that you can fit more stuff, bigger maps, etc in there), but will also speed up map loading times!

The first set of changes are in the texture loader. Break open gl_model.c and change the following.

In Mod_LoadTextures, replace:
Code: Select all
tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );

with
Code: Select all
tx = Hunk_AllocName (sizeof(texture_t), loadname );

remove
Code: Select all
// the pixels immediately follow the structures
memcpy ( tx+1, mt+1, pixels);

change
Code: Select all
tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(tx+1), true, false);

to
Code: Select all
tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(mt+1), true, false);

change
Code: Select all
R_InitSky (tx);

to
Code: Select all
R_InitSky (mt);

Now on to the render.h changes.

change
Code: Select all
void R_InitSky (struct texture_s *mt);   // called at level load

to
Code: Select all
void R_InitSky (struct miptex_s *mt);   // called at level load

And lastly the gl_warp.c changes

replace
Code: Select all
void R_InitSky (texture_t *mt)

with
Code: Select all
void R_InitSky (miptex_t *mt)


All we're doing here is avoiding allocating the texels from the BSP on the hunk. They're only ever used in the texture loader, so why waste perfectly good memory that could be put to better use holding something else? Also good for the PSP people trying to squeeze Quake into 32 MB. :D

The saving for this one? I loaded e1m3, before was 421104 bytes for textures, after was 4992 bytes. That's almost half a MB wasted in stock GLQuake.
Last edited by mh on Tue Jun 15, 2010 10:13 pm, edited 1 time in total.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: GLQuake Memory Saving

Postby Downsider » Tue Jun 15, 2010 10:06 pm

mh wrote:In Mod_LoadTextures, replace:
Code: Select all
tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );

with
Code: Select all
tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );


It's the same? :O

Cool tutorial, though.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby mh » Tue Jun 15, 2010 10:13 pm

You're right. Changed. :lol:
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby leileilol » Tue Jun 15, 2010 11:09 pm

Another waste is the MDL files. They're all UVmapped too efficiently, there is no way to fix that by engine so for them to be happy with GLQuake one would have to make new UVs and power of 16 texture sizes for more memory efficiency and cpu efficiency too so there's less resampling to do on load.

I'd do it if I ever got a binary patcher to work. I'd only submit it as a binary patch form that depends on registered pak1.pak that then patches a whole new pak2.pak (unaffecting pak1 of course)
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby ArchAngel » Wed Jun 08, 2011 11:34 pm

Just tried this in a stock QuakeWorld client and it crashes it... the function looks pretty damn similar to the NQ one... any thoughts?
ArchAngel
 
Posts: 37
Joined: Fri Jun 03, 2011 7:33 pm

Postby mh » Wed Jun 08, 2011 11:48 pm

Probably R_InitSky or the GL_LoadTexture call. If memory serves there might be a little extra work needed in R_InitSky too, and I haven't tried this in glqwcl so there might be other places where (byte *) (tx + 1) is referred.

I'll try it tomorrow and post an update if I remember. ;)
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest