Loading From Zip Files

December 16, 2011 by Terry

It has been a long, slow journey, but Retrobooster finally has a decent system for loading data from zip files. This was particularly challenging because it uses OpenSceneGraph for graphics, which didn’t have the ability to access zip files for resources the same way it could access file system paths. I wanted them to be treated the same way. I first had to add this functionality, which meant getting plenty of advice on OpenSceneGraph’s mailing list and hours upon hours of stepping through OpenSceneGraph’s file loading code in a debugger to figure out how it worked and how to extend it. Once I had added the ability to specify a zip file as a path, it would load everything properly except shaders. There was still plenty of work to do just to get the shader loading working. All this new code has been submitted to OpenSceneGraph, and I really hope it gets accepted permanently so that I don’t have to publish Retrobooster with a modified version of OpenSceneGraph.

Last, there was some more code to write to pull music and sound effects from a zip file into SDL_mixer, but that was much easier.

“What is all this for?” you might ask. Having all the game data stuffed into one zip file makes the game installation much cleaner because you don’t have hundreds of data files sitting in a directory somewhere. It also makes the game more modifiable. With just a little more effort in the way the game is set up, this will allow people to easily override almost any game asset using a zip file full of new assets.

Along the way, I discovered Zip Utils, which is a wonderful, free piece of code for zipping and unzipping. OpenSceneGraph uses a version of this code for its zip archive reader/writer, and it is what I am currently using to load anything that is not loaded by OpenSceneGraph, such as sound effects and level files.

Leave a Reply