Saturday, October 9, 2010

Faster Map Loading

I can now get ID1 map loading times down to virtually instantaneous. OK, they're already fast, so what's the point in beating on something that doesn't need optimization? The answer is big maps - big maps load slowly. Really big maps load really slowly. Removal of bottlenecks from map loading code means that big maps can load faster, meaning that the player is no longer sitting there twiddling their thumbs and looking at the "Loading" screen for what seems like forever. This is a good thing.

There are a few places in the original code which are candidates for attacking here.

First one is texture loading. Instead of allocating each texture structure individually, I allocate a single big array and just pull structs off that as required. GLQuake doesn't need to keep the original texture pixels either so there's a memory saving here too.

Second one is polygon creation. This also suffers from "lots of small allocations" syndrome - especially so in big maps. It's quite easy to use the same technique, allocate a big array of polygons, and pull from that instead.

Texture resampling is another one. GLQuake resamples non-power-of-two textures to powers of two, and this is now done at the same time as the upsampling of 8-bit textures to 32-bit. Another memory saving is just a bonus.

Lightmaps - clearly they're all the same size and format, so if a texture object already exists from the previous map, just reuse that (via glTexSubImage2D) instead of fully respecifying the new texture. There's also scope for applying this principle to other textures, but I haven't done so yet.

There are other bottlenecks in the RMQ engine that don't exist in ID Quake and that I haven't yet identified; it's still a little slower at loading regular ID1 maps (the transition should be almost totally seamless) so I need to do some profiling and find out what's happening.

2 comments:

gb said...

I always thought of an engine coder like the drummer in a band.

And you're a damn good drummer.

Baker said...

Hrm!

I like this. ;)

Those giant maps do load slow as hell.