Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've just finished a basic RPG game written in C++ SFML, I've put a lot of effort into the game and I'd want to distribute it, however I've ran into a small issue.

Problem is, I have well over 200 images and map files (they're .txt files which hold map codes) all in the same folder as the executable, when I look in the folder, it makes me want to cry a little bit seeing so many resources, I've never seen a game which shows you all the resources directly, instead I believe they pack the resources in a certain file.

Well, that's what I'm trying to achieve: I'm hoping to pack all the images in 1 file (Maybe the .txt files as well) then being able to read from that file or easily add to it.

share|improve this question
6  
    
I've seen code where all the images were packed into a string in the code. But that was done due to requirements. (It was a 64KB Java competition) –  Omar Kooheji Sep 26 '12 at 14:44
    
Sorry it was a 4Kb java competition. Not a 64Kb one. –  Omar Kooheji Sep 28 '12 at 8:57
add comment

9 Answers 9

up vote 55 down vote accepted

Game programmers have relied on one of two main methods of data storage:

  • store each data file as a separate file
  • store each data file in a custom archive format

The drawback to the first solution is the wasted disk space problem, as well as the problem of slower installations.

The second solution provides it's own pitfalls, first is that you must write all your own image/sound/etc. loading routines which use a custom API for accessing the archived data. A further drawback is that you have to write your own archive utility to build the archives in the first place.

Unless you will always load all files from the archive, TAR/GZ might not be a very good idea, because you cannot extract specific files as you need them. This is the reason many games use ZIP archives, which do allow you to extract individual files as required (a good example is Quake 3,​​​​ whose PK3 files are nothing but ZIP files with a different extension).

EDIT : "Hide" the game folder structure and "Keep" only the executables

Another solution is often used to "hide" the game files in folder structure. Keep only your executables and maybe a readme file in the main directory and move the game files into a sub folder named "data" or other related.

EDIT : Gamedev Tuts Plus have a nice resource

EDIT : libarchive

One potential solution libarchive, which is an archiving library that will handle extracting files from an archive such as a ZIP file. It even allows you to assign the extracted file to a standard FILE pointer, which would make interfacing with any other libraries potentially more straightforward.

EDIT : ZIP Format files with alternative extension

Here, I like @Joachim Sauer's Comment

Using ZIP-format files with alternative extensions has a great tradition outside of games as well: Java does it, the OpenDocument Format (a.k.a. the OpenOffice/LibreOffice format) does it, even Office Open XML (a.k.a. the "new" Microsoft Office format) does it.

share|improve this answer
3  
+1 for the quake example, I had no idea that's amazing. –  Bugster Sep 25 '12 at 9:17
2  
Yeah, Thief/SystemShock2 used .zip files renamed something else too. In Java you can use something like TrueZip to access files in zips as if they were files in folders, I imagine there are similar libraries for C++. –  Nick Sep 25 '12 at 10:46
16  
Using ZIP-format files with alternative extensions has a great tradition outside of games as well: Java does it, the OpenDocument Format (a.k.a. the OpenOffice/LibreOffice format) does it, even Office Open XML (a.k.a. the "new" Microsoft Office format) does it, ... –  Joachim Sauer Sep 25 '12 at 12:46
5  
@Svish. Depending on the platform, the amount of disk space taken up by a lot of small files can be considerably greater than the amount taken up by one large file, even if that large file is not compressed at all (.tar, for example). It's to do with the way data is physically stored on the disk. –  TRiG Sep 25 '12 at 16:33
1  
Ah, that's true. Shouldn't be much though, unless there are a lot, but in that case it can indeed build up. I can imagine installation and uninstallation also takes a hit with lots of small files. –  Svish Sep 25 '12 at 17:01
show 21 more comments

Another solution often used to "hide" the game files is folder structure. Keep only your executables and maybe a readme in the main directory and move the game files into a sub folder "data". I don't think that it is very uncommon to do so. Many games I know store their content in such a way.

share|improve this answer
8  
+1 If disk space or protection isn't an issue, that's the easiest fix. –  Laurent Couvidou Sep 25 '12 at 8:14
8  
+1 for the easiest fix, and maximum modding potential. –  Polynomial Sep 25 '12 at 9:06
1  
+1 because the other guy said +1. Can't be wrong, eh? (Joking aside, great answer.) –  jco Sep 25 '12 at 14:20
3  
@Omnifarious That's not always true, e.g. when reading from an optical disk, even with a perfect filesystem, it's common to pack files in loading order to prevent excessive seeking (the speed up can actually be quite surprising). But this is a totally different story for hard disks, and I tend to think the OP is in this case. –  Laurent Couvidou Sep 25 '12 at 19:17
3  
@Mr.Beast You missed my point. I'm talking about optical disks. I've worked for a studio where it was a single programmer's full time job to make sure files would be packed as efficiently as possible on a DVD, to get the best loading time possible. I'm sure he'd be glad to learn he could just have relied on the DVD file system ;) –  Laurent Couvidou Sep 26 '12 at 10:14
show 2 more comments

I really like PhysFS for this. It allows you to access either folder or zip archives with the same code. It works well for all stages of a Games lifetime.

  1. During development: access the resources directly from a folder hierachy. This way compressed archives are not in the way and you can rapidly iterate.
  2. Initial deployment: zip up you resources for easy deployment / quick installs. No code needs to change. Just point PhysFS at the zip instead of the folder.
  3. Updates / Modding: PhysFS can load multiple zip archives where the resources of one override the other. Updates can be as simple as a new zip with only the changed files. Similarly for modding.

update:

I used the tutorial included with the source and the doxygen documentation to learn PhysFS. The API really is fairly simple, you'll spend more time learning how to load images into SFML via memory buffers instead of by file path.

share|improve this answer
4  
I'm using PhysFS for my current project and I love it. I don't always need to regenerate my content archive file; I can just drop an updated version in the search path and BAM! It works. –  Zack The Human Sep 25 '12 at 17:37
    
After some answers I decided I'll go with physFS. Would you care to recommend a nice tutorial? :) –  Bugster Sep 25 '12 at 17:51
3  
In that case you should accept this answer. :-) –  Eric Sep 25 '12 at 18:13
add comment

I'd suggest using a ZIP file. It's an ubiquitous format and you'll find ready-made libraries that allow you to load files from within a ZIP file. A quick Google search even revealed a zip loader for sfml.

share|improve this answer
add comment

Well, you could cheat like they mentioned:) You can make a sprite-sheet from the imagery, there is no need to zip it nowadays unless it saves a ton of space. After you create a sprite-sheet or several sprite-sheets from the images, you could simply rename their extensions. Most Gamers will not bother to check and why not leave that option to Artists who may want to mod your game in the future? That way they can too create a sprite-sheet, rename it's extension and start rolling.

With the text files, I would humbly suggest you convert that data into binary form. I am pretty sure you will find a simple way to do it.. For instance, if you only use A-Z, a-z and the 0-9, you can use 6 bits to represent each character, that will somewhat protect your copyrighted material, it will also prevent others from editing maps.. You can always add a map converter if you like. Zipping is completely reasonable for text though.

share|improve this answer
    
Converting to binary is good advice but not for protection - it's just going to be easier to parse and faster to load. Would suggest it as a pre-processing step, but that's going to off-topic for the question. –  Jimmy Shelter Sep 25 '12 at 14:04
    
Well, I am guessing, if he wants to protect it more effectively, he could try to encrypt it in RSA or a similar algorithm(there is no need). I doubt anyone will make unauthorized use of the map files from an indie game if it's inside a binary file. It just doesn't seem worth investing the time in figuring our the parsing. Text files are just completely vulnerable and as you suggested something ineffective for storing data. –  Zehelvion Sep 25 '12 at 14:13
2  
On HDDs, loading a single zip-file is faster than a lot of small files because there are less expensive random seeks to the physical disk. A binary for a small game can be mapped into memory and work "magically", almost no parsing required. –  Liosan Sep 25 '12 at 14:16
    
@Liosan You could have misinterpreted what I meant or I misunderstood you.. I said binary is better for storing data and that other game designers are unlikely to want to learn how to parse your binary map code, unless it is documented and encouraged for modding purposes. Therefore it offers some rudimentary protection over text files. –  Zehelvion Sep 25 '12 at 14:23
add comment

It's not only about the number of resources or disk space.
With a lot of different texture files, as you are using SFML, which renders with OpenGL, each time you are going to render a texture, OpenGL needs to bind the next texture to the video card (check glBindTexture() ), and it is a really expensive task.
With that in mind you can realize why games usually put a number of sprites in the same texture, the so called spritesheets, according to your menus/levels/maps of the game.
The result is a huge gain in performance, since you are rendering a lot of sprites with the same bind texture call.

share|improve this answer
    
After getting several references to making a spritesheet I've considered some refactoring to lower the image count. Thanks –  Bugster Sep 25 '12 at 19:42
add comment

I would personally head down the custom binary file route for this. This is something I do myself all of the time now, it isn't as difficult as it might sound, and it also provides a level of obfuscation for you game resource files. I wrote a small introductory Gamedev article about this not so long ago if you are interested:

http://gamedev.tutsplus.com/tutorials/implementation/create-custom-binary-file-formats-for-your-games-data/

Sprite-sheets are a different subject entirely but they are the norm for most games :)

share|improve this answer
add comment

Another method you can use:

The free version of XnView provides a feature called "Strip of Images" (SHIFT+A), which allows you to create sprite-collections.

This minimizes file access and is particularly important for web applications/games to minimize the number of HTTP-roundtrips.

Access to individual images is then granted through coordinate maps (for instance css-definitions).

share|improve this answer
add comment

First you must write all your own image/sound/etc. loading routines which use a custom API for accessing the archived data. A further drawback is that you have to write your own archive utility to build the archives in the first place. Unless you will always load all files from the archive, TAR/GZ might not be a very good idea, because you cannot extract specific files as you need them. This is the reason many games use ZIP archives, which do allow you to extract individual files as required (a good example is Quake 3,​​​​ whose PK3 files are nothing but ZIP files with a different extension). http://zpp-library.sourceforge.net/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.