I'm creating a 2D game in plain ANSI-C using SDL2. I'm planning to let users create their own graphics. So, to achieve this, I'll use an information file which will hold some data such as Width, Height, X and Y position of each frame. But I have two views of this. One is to use a single file which will hold the information of all graphics. The other is to use one file for each graphic. Which one is faster and cleaner? Or it's just the same?
Using one file is cleaner, but also, files have to take up a minimum space (On my disk, 16kb, this is called the cluster size). So if you're creating lots of small files, even if each one is only one byte long, if you have 1000 files, that's nearly 16 megabytes!
It depends on the size of the files stored with each graphic, to summarize:
- A corrupted file will not effect all graphics.
- You don't need to search for the part of the file you want.
- Clearer code
Single file advantages:
- You don't have issues with cluster size
- Potentially faster accessing as you don't need to open multiple files
It also depends if this information will be streamed, or read once at startup. If it's read once at startup, then speed of accessing doesn't matter so much. Personally, if you're going to end up with lots of really small files, I'd go with one larger file, but if you're going to end up with less files of more reasonable sizes, I'd go for a file per graphic
The key here is that you want end users to be able to add graphics. If thats the case, I'd recommend individual files for the graphics, this way customers don't have to edit existing files (and possibly corrupt them), and its easier to distribute art for the game by just copying files into their directory - no need to edit existing files.