Game Archives

This topic is 3879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello again everyone, I have a question that I thought would have been answered by now, but maybe not many people are quite so far into their game as I am. Up until this point my game has been using hard-coded folder paths to access things like graphics and sound. The structure looks something like: Game folder -> Data folder -> Sound folder, Graphics folder, Saves folder, Maps foler, etc. Those folders are often broken down even further to specifics. Anyway, I'm trying to devise an system like what most games use, an archiving system. I want everything in one or multiple large archives that my game can decompress quickly at run time. My question is, how can create a good archive and access it quickly? Should I use a preconceived format and adopt that, or should I create my own format (like I've done for everything else so far)? How do games so quickly depress models, graphics, sound, etc. from one large archive and load them into memory? Any help is appreciates, as always. Thanks.

Share on other sites
I personally use just a one zip file where all game data is stored, and for unzipping I use zlib: http://www.zlib.net/

Using it is quite simple:
#include <unzip.h>// Open zip archiveHandle=unzOpen(ZipFileName);// Find file from zip and open itunzLocateFile(Handle,FileName,false);unzOpenCurrentFile(Handle);// Find file sizeunz_file_info FileInfo;unzGetCurrentFileInfo(Handle, &FileInfo, NULL,0, NULL,0, NULL,0);int FileSize=FileInfo.uncompressed_size;// Allocate memory and read fileunsigned char *Buffer=new unsigned char[FileSize];unzReadCurrentFile(ZipHandle,Buffer,FileSize);unzCloseCurrentFile(ZipHandle);

And basically that's it, just removed some error handling for clarity.

The only thing that has given me problems in this is that whenever you read something from the disk you'll get memory pointer - not file pointer. For example I tried to use few image loading libraries, but they accepted only file pointer or file name. They were not able to read that memory buffer where I have that file data stored. So this limits choice of libraries a bit.

Edit: Missing source tag
Edit2: Wrong url :)

Share on other sites
To Jænis' problem, it is a common practice to "inflate" archived files to a temporary folder so you don't need to re-inflate them if you remove them from memory after a first load.

Share on other sites
Thanks, zlib looks like the way to go. Simple, cross-platform, and patent free. I'm gonna go look into implementing now, thanks for the sample code too.

Share on other sites
You might want to give PhysFS a try. It has direct support for accessing archive files such as zips as well as neat things like override folders.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• Forum Statistics

• Total Topics
633768
• Total Posts
3013740
×