Sign in to follow this  
orphankill

Game Archives

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this