The new MHQuake texture loader is a biggie. It's orders of magnitude faster as it no longer needs to test if it can open each type of texture file (in each potential directory) before loading it. Instead, what it does is scan through the game directory at startup and build a list of all textures found in (nearly) all subdirectories (it excludes /sound, /save, /scrnshot and one or two others). This is a reasonably quick one-time only operation, and uses the Windows API to query the filesystem, rather than attempting an fopen () on the file itself.
When loading, it then looks up the original texture name in the list and returns the path at which the external replacement can be found, as well as the file type so that it can call the correct image loading function. The list is unsorted, and a brute-force search is used every time, but for 40-50 textures per map the hit is negligible. I might move to a sorted list with indexes for the first character of the name at some time before release, as doing it properly seems the correct thing.
The real beauty of this approach is a subtle side-effect that was unintended when I first wrote the loader. MHQuake no longer cares where you put your textures - it can quite happily load them anyway. If you're paranoid about Tenebrae compatibility, go ahead and put them in /override, or put your skyboxes in /env, /gfx, /env/gfx, /gfx/env, /textures, /textures/env, or even /elephant, and MHQuake will detect them and load them without having to painfully crawl through all possible paths. (I can also do recursive '.link' loading, although why you'd want recursive '.link's is something I have a hard time imagining...)
Saturday, January 26, 2008
Coolness in the MHQuake Texture Loader
Posted by
mhquake
at
4:21 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment