tags:

views:

68

answers:

2

I want to create a single data file that holds all the data that my game will need, and I want it to be compressed. I looked into tar and gzip, but I downloaded their sources and I don't know where to begin. Can somebody give me some pointers to how I can use these?

+1  A: 

If you mean that you want your game to read out of the archive at runtime, then I recommend decompressing each time the game is run into a temporary folder, and then using the files as required. This can be achieved through using a library for decompressing whatever archive format you use. Look into zlib.

njak32
That's not a great approach if the archives contain many files. You don't want to decompress 5000 textures if the current level only uses 100 of them!
Porculus
I suppose I made the assumption that the game wasn't very large, as if it was then kaykun would most likely have already had experience in this area. My method is far simpler for the programmer, despite introducing a tolerable amount of overhead.
njak32
+2  A: 

Unless you will always load all files from the archive, TAR/GZ might not be a very good idea, because you cannot extract specific files as you need them. This is the reason many games use ZIP archives, which do allow you to extract individual files as required (a good example is Quake, whose PK3 files are nothing but ZIP files with a different extension).

A bit of searching brought up Minizip, which is a ZIP library built on top of zlib. I couldn't find any separate documentation for it, but the header files seem to include a lot of comments, and I believe you can get off with it.

casablanca
+1. Zip is the way to go if you don't want to roll your own.
Porculus
Minizip is perfect.
kaykun