Packaging game contents
by WesTT · in Torque Game Builder · 09/25/2008 (1:27 am) · 5 replies
I would really like a way of packaging my game resources (art and sound files) into a VFS type structure, where the engine simply accesses those assets in a transparent manner when it loads. In this case, I develop the game with all my assets unzipped/unchunked as pngs/jpgs/oggs etc but when the game is built for distribution all calls to loads those assets are transparently handled if I place all assets into a zip file or the like.
My understanding is that TGB has no way to do this by default, but looking at the engine code there is support for zip files. In fact, I managed to put some code into the ResManager to output the contents of a zip file. I'd really REALLY like to package up my contents even if it is a simple ZIP file. I tried replacing some of my assets with a zip file, but alas TGB was not able to find them when I did.
Is there a simple way to do this? I've searched the forums and found some posts from people saying they have done it, but no solid indication of how to, so either I'm missing something or just can't find the docco.
Cheers
My understanding is that TGB has no way to do this by default, but looking at the engine code there is support for zip files. In fact, I managed to put some code into the ResManager to output the contents of a zip file. I'd really REALLY like to package up my contents even if it is a simple ZIP file. I tried replacing some of my assets with a zip file, but alas TGB was not able to find them when I did.
Is there a simple way to do this? I've searched the forums and found some posts from people saying they have done it, but no solid indication of how to, so either I'm missing something or just can't find the docco.
Cheers
#2
09/25/2008 (5:46 am)
Nevermind. I figured out that it was me zipping the files up with relative paths and the resmanager didn't like that by the looks of it. Without relative paths, the images load fine, as do the oggs, nice. :)
#3
I haven't looked at this at all but it's something I'd like to do.
09/25/2008 (2:37 pm)
So Wes, can you tell us what the process is? At what point do you zip up your files, do you have to give it a particular name and save it in a particular location, do you have to change your script at all to recognize the "new location" of the assets? Can you use compression when you zip everything up?I haven't looked at this at all but it's something I'd like to do.
#4
Anyway, it's pretty easy for the most part, just a bit finicky. Art assets appear to work fine, as do my oggs with some caveats. Oggs appear to only work without locking the game up when I specify no compression (store only) from WinRAR. *shrug* I don't have time to fix it and don't care much for compression once the game is on the users machine but YMMV.
Particle effects, level files and scripts files still have to be naked in the directory, they won't work from zip files with stock TGB. These are the steps I took to get this working:
1. Zip up files with or without compression.
2. Turn off echoing of paths in the zip file. Storage of relative paths appears to break zip functionality for me, but I haven't looked into it much.
3. Place files into the top level of the "mod" directory in TGB. In this case it's the "game" directory. This appears to work for me.
And that's pretty much it. It should find the zip files, extract them (check the log file) and loads as per normal. As I said, placing my oggs into the zip file would make my game hard lock from time to time, but I am using the latest OpenAL DLLs too. Don't know if this has an effect or not.
If you want to use a file with a different extension, you'll need the source. Find a function in the resManager.cc file called "searchPath". You should see a line of code like this:
(Don't know if I am allowed to reproduce this code on the private forums, so GG let me know if not)
Add in whatever extension you want there for a bit of obfuscation if you please. For password "protection" (which is really no protection at all when it comes to zips) find a file called "zipArchive.h". At the top there's a line that reads:
Set your password to whatever you want it to be. When zipping up your files set this password on them.
That's all there is to it really. I'd like to see more official and stable support for this functionality in TGB in the future, or rather just a proprietary chunk file (with or without encryption support) for sticking assets together through the BUILD command in TGB.
Hope this helps!
09/26/2008 (12:03 am)
Hi Shaz. I actually thought this morning as I was getting out of the shower that I should put a bit more info in here about how I did it. Anyway, it's pretty easy for the most part, just a bit finicky. Art assets appear to work fine, as do my oggs with some caveats. Oggs appear to only work without locking the game up when I specify no compression (store only) from WinRAR. *shrug* I don't have time to fix it and don't care much for compression once the game is on the users machine but YMMV.
Particle effects, level files and scripts files still have to be naked in the directory, they won't work from zip files with stock TGB. These are the steps I took to get this working:
1. Zip up files with or without compression.
2. Turn off echoing of paths in the zip file. Storage of relative paths appears to break zip functionality for me, but I haven't looked into it much.
3. Place files into the top level of the "mod" directory in TGB. In this case it's the "game" directory. This appears to work for me.
And that's pretty much it. It should find the zip files, extract them (check the log file) and loads as per normal. As I said, placing my oggs into the zip file would make my game hard lock from time to time, but I am using the latest OpenAL DLLs too. Don't know if this has an effect or not.
If you want to use a file with a different extension, you'll need the source. Find a function in the resManager.cc file called "searchPath". You should see a line of code like this:
if (extension && !ignoreZips && !dStricmp (extension, ".zip"))
(Don't know if I am allowed to reproduce this code on the private forums, so GG let me know if not)
Add in whatever extension you want there for a bit of obfuscation if you please. For password "protection" (which is really no protection at all when it comes to zips) find a file called "zipArchive.h". At the top there's a line that reads:
#define DEFAULT_ZIP_PASSWORD "changeme"
Set your password to whatever you want it to be. When zipping up your files set this password on them.
That's all there is to it really. I'd like to see more official and stable support for this functionality in TGB in the future, or rather just a proprietary chunk file (with or without encryption support) for sticking assets together through the BUILD command in TGB.
Hope this helps!
#5
When you save the zip file into the "top level of the mod directory", does it matter what you name it? Looks like it's got to be something.zip unless I want to change the source? (I believe it's ok to post snippets of code in the private forums, as only those who have purchased the full version with source have access to this area).
I'll play with this a bit on the weekend :)
09/26/2008 (3:38 am)
Thanks Wes. Sounds easy enough.When you save the zip file into the "top level of the mod directory", does it matter what you name it? Looks like it's got to be something.zip unless I want to change the source? (I believe it's ok to post snippets of code in the private forums, as only those who have purchased the full version with source have access to this area).
I'll play with this a bit on the weekend :)
Torque Owner WesTT