Sign in to follow this  

File formats...

This topic is 4685 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

In most games out there, data is stored in one or more massive composite container files. How would I go about making my game(s) use something like this? What would be the most efficient way to read these types of files (for example, reading an audio chunk of data from one of these big files into my audio decompressor without making my audio decompressor need to know the inner workings of the container)? How would I write them?

Share this post


Link to post
Share on other sites
Obviously, since there will be many more types of data in the files than just audio, the code that reads (and writes) the file should be in a single separate class.

The basic concept is to have a container class, which can read and write data from the file, and objects (such as samples, images, icons, textures, text, ...), that can be constructed from the data read from the file. Neither knows about the other. Then you have a mediator that knows how to load from the container and create an object from the loaded data.

There are so many ways to do it. Which one you use depends a lot on your overall design.

A very flexible way is to first load it from the container into generic types in memory, and then pass the loaded data to the object's constructor. Something like this, for example:

Container file( "filename" );
Resource * resource = file.load( "resourcename" );
Object * object = new Object( resource->size, resource->data );
...
Object::Object( int size, void const * data )
{
...
}


Other techniques might include using callbacks to load each specific type, or use a "factory" to create a specific type of object from a variety of different sources (including a container).

Share this post


Link to post
Share on other sites
How do you go about opening a several hundred MB data file (which is likely the size that a decent game would require), having a song playing in the background and loading various 3D meshes, textures, etc. without chewing massive RAM?

Share this post


Link to post
Share on other sites
Quote:
Original post by trevaaar
How do you go about opening a several hundred MB data file (which is likely the size that a decent game would require), having a song playing in the background and loading various 3D meshes, textures, etc. without chewing massive RAM?


Hence the long load times for many games. You would probably be better off putting your stuff in more files, such as one file per level, etc.

Share this post


Link to post
Share on other sites
Lots of games nowadays simply use zip files with a different extension - .pk3 for example in Quake3 based games.

The benefit of using zip files is the ease of use in creating them and also there's several libraries which will read from them. Of course since zip files are so popular then practically anyone will be able to view your game's data files which you may not want.

Share this post


Link to post
Share on other sites
Quote:
Original post by trevaaar
How do you go about opening a several hundred MB data file (which is likely the size that a decent game would require), having a song playing in the background and loading various 3D meshes, textures, etc. without chewing massive RAM?

Apart from Emmanuel's suggestion you can also stream from these files. You can open a file handle for the container and just keep track of the file pointer during streaming. Additionally the streaming function can call a number of (buffered) filters to decompress or decrypt the content on the fly.

Share this post


Link to post
Share on other sites

This topic is 4685 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.

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