Sign in to follow this  

Reading game data from archive

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

Right now I only have a few files in my game that get loaded at runtime. But that number will probably increase as I progress with it, so I though of implementing a system that reads game data (like models, textures, sounds, etc.) from archive files (like zip) since that would be faster than loading many small files residing individually on disk.

 

Thing is, while it is very easy to create  such an archive, I have no clue on how to get my engine to load specific files from it or (more importantly) how to know where a file is.

 

Currently I pass in file locations as a path relative to the game folder, using the FileSystemContentResolver class to get my content manager to actually find and load the file. File paths are both hardcoded in the source and specified in .ini files

 

For example:

 

[Ship]

...

model = Content\Ships\someship.3df

 

Now, the content manager has an IContentResolver interface which FileSystemContentResolver implements, and it is set up so it will use all registered content resolvers to find a given file.

 

So, how would I go ahead to:

1. Tell the content manager/resolver which file to look for in which archive (or just try all there are)

2. Have the content resolver assert that the file actually exists in this/any archive

3. Load the file from archive, while preferable keeping the archive open for future file loading.

 

Preferable using C# framework built-in functionality

Share this post


Link to post
Share on other sites
Generally this is done by having the internal archive folder structure be identical to the loose file structure. The game is then told about each archive in some manner (ini setting, asking your OS for every "*.zip" file in a certain folder, having the archive name match the level name, etc). Once the game knows what archives exist, it can open them and read a table of contents telling it what files are in said archive.

Once you've done that, it's just a matter of asking your resource loader for the file like you've always done - the resource loader then checks its TOC for the archive and the position in the archive, and reads in the file.

If you want to get fancy, when your loader gets a request for a file it might first check to see if a loose file exists on disk before falling back to the archive - this lets you iterate quickly on a small selection of assets "overriding" your packaged files. Edited by SmkViper

Share this post


Link to post
Share on other sites

You mean like, e.g. the fallout or elder scrolls games, where you can put mod files either in an esp packages or as loose files on disk?


Pretty much exactly like that, though the BGS games go one step farther and let you pick the order in which archives load, "later" archives overriding the contents of earlier ones. (Basically, registering the first archive, then registering the second - letting the entries in the second one overwrite any matching ones in the table of contents)

Share this post


Link to post
Share on other sites

Take a look at the c# bindings for physfs, which allow for everything you're trying to do here, reading from archives and overriding specific paths and filenames with non-archived versions.

 

http://freecode.com/projects/physicsfs

 

It supports many file formats including 7z, zip, etc and the license is very permissive.

 

I used this in a previous project however I didn't use C# bindings, instead using it natively inside a C++ project. It worked very well.

 

Edit: ninja'd by Aldacron :P

Edited by braindigitalis

Share this post


Link to post
Share on other sites

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