Sign in to follow this  
ravengangrel

Multiplatform resource management

Recommended Posts

ravengangrel    406
At work, I use VC++2005 under MS-Windows. I know there is a .rc format to store resources; it's just a compilable text file with some definitions which can reference some files (for example, images); so, when it's compiled, an obj-like file would be generated, containing the mentioned file which, at link stage would be bundled in the executable. I'm not sure of the exact process because I mostly do non-graphics programming, and I DON'T REALLY CARE ABOUT THE DETAILS for now, so, I'd be grateful if (unless someone finds some *BIG* conceptual error or something) windows resource related discussion is avoided. I'm pretty sure there isn't any multiplatform solution for this but, do you know of any similar approach under MacOS or Linux? I guess this is compiler-dependant so, any idea for GCC to bundle some file to it? Then, how all this related to SDL? AFAIK, I need to reference the file image I want to load. Any way to do this from memory? Thanks a lot in advance.

Share this post


Link to post
Share on other sites
lightbringer    1070
Do they have to be part of the executable? An easy multi-platform solution is to store resources separately from the executable, either as separate files or in an archive (google zlib or roll your own).

Share this post


Link to post
Share on other sites
ravengangrel    406
Quote:
Original post by lightbringer
Do they have to be part of the executable? An easy multi-platform solution is to store resources separately from the executable, either as separate files or in an archive (google zlib or roll your own).


No, of course they haven't. Indeed, I was planning of mentioning it but I forget it. If the compiler has an automated way to do it, I'd like to use it. Else, a zip/gz/whatever seems nice enough, but again, is possible to load a SDL_Surface from memory?

Share this post


Link to post
Share on other sites
lightbringer    1070
I'm not aware of any system for storing resources like images inside ELF binaries, although that doesn't mean much since I barely ever use gcc. I digged up a discussion about this, which you might want to mine for any info I missed. Apple apparently has something called file system forks, which could be useful for this but is almost certainly not portable. I have a vague idea about you being able to compile the resource as part of the program if you store it in base64-encoded form inside the program source, but that sounds a bit far-fetched. No clue about SDL.

Share this post


Link to post
Share on other sites
Rattenhirn    3114
Many compilers come with tools that can turn arbitrary binary data into an object file, which can then be linked to the executable.

I have used something like that in the olden days for gcc, but its name eludes me at the moment...

Share this post


Link to post
Share on other sites
ravengangrel    406
Thank you, guys.
I'm beginning to realize this isn't worth the portability issues it would create, and it's always far more flexible having the data outside. I'll take the traditional approach.
You have been very helpful, though.

Share this post


Link to post
Share on other sites
Kambiz    758
Qt Creator comes with some built in tools to create such resource files (cross platform), it does this by writing the binary data in a static const array in an auto generated source file. It works well for small data like icons but for larger data it takes forever to generate and compile the source file. I'm not even sure it would work for arbitrary file sizes.

Another method is to append a zip file to the actual executable (It works at least under windows), like some self-extracting archives, an example can be found under the PhysicsFS samples.

Storing the data in separate files or in an separate archive is probably the better idea, it makes both compiling and patching easier.

You may also find SDL_RWops useful.

[Edited by - Kambiz on May 3, 2009 1:52:29 PM]

Share this post


Link to post
Share on other sites
Yes it is possible to load SDL_Surfaces from memory. SDL itself does it; SDL_LoadBMP and IMG_Load are just a macros hiding that fact.

Custom Resource Files

Displaying a Bitmap from a Custom Resource File using SDL

Displaying a Bitmap from a zip file using SDL and zlib

I haven't personally done it so I cannot tell you how, but those tutorials should give you enough information. Might be a bit difficult though, so you should consider whether you really want to bother with it or not.

Share this post


Link to post
Share on other sites
lightbringer    1070
Quote:
Original post by Servant of the Lord
Custom Resource Files


I'm probably going slightly off-topic but I find it amusing how those guys are writing:

Quote:

Disgusting imagery aside, custom resource files are an essential part of any professional game. When was the last time you purchased a game and found all of the sprites, textures, sound, or music files plainly visible within the game's directory tree? Never! Or at least, hardly ever!


It's not generally such a bright idea, but I see this in professional games all the time. I'd say around 20-40% of all commercially published games do this. It also helps with modding for games that are mod-friendly, such as many of the Civilization, Total War, and Europa Universalis titles.

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