• Advertisement
Sign in to follow this  

Game Archives

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 archive
Handle=unzOpen(ZipFileName);

// Find file from zip and open it
unzLocateFile(Handle,FileName,false);
unzOpenCurrentFile(Handle);

// Find file size
unz_file_info FileInfo;
unzGetCurrentFileInfo(Handle, &FileInfo, NULL,0, NULL,0, NULL,0);
int FileSize=FileInfo.uncompressed_size;

// Allocate memory and read file
unsigned 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement