Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Multiple Files

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 BarryJ   Members   


Posted 13 August 1999 - 10:46 PM

I am looking for a way to put multiple files(Graphics, etc.) into one file similiar to that of Allegro's .dat files. I am using VC++, no MFC. Thanks.

#2 mordell   Members   


Posted 31 July 1999 - 01:36 PM

check out some source code here:

The idea is that you have one file (data file), in this data file there is a directory or index of all the other files (resources) this file contains.

Part of the information contained in the index is the offset within the data file your resource file resides, and its length.

So, when you need a particular sound, image, or whatever, you open your data file, lookup in your index for the offset of your file, seek to that offset, and begin reading as usual.

The sample code I pointed you to has a couple of limitations that may make it inappropriate for your use:

1) Fixed index size, indicating the file can only hold so many other files. You can set this number to any arbitrary number i guess, but once your out of "slots", your out..

2) There is no compression

For another example, check out Chris Hargroves colum "Code on the Cob" at www.loonygames.com. Or, I believe there is a similar example as part of the DirectX SDK examples.


#3 Anonymous Poster_Anonymous Poster_*   Guests   


Posted 08 August 1999 - 02:07 PM

Can you give an example on how ures works? i dont quite get it, say i have a structure like this:


how do i make the ures file and how do i load these bmps normally i would load these bmps as follows:

lpDDSTitle = DDLoadBitmap(lpDD, "BMP\Title.bmp", 0, 0);

#4 mordell   Members   


Posted 08 August 1999 - 03:25 PM


First I would recommend building the ures.cpp executable. It is the tool that you would use to build your .res file.

Once you have the URES.EXE compiled, you can create the URES.RES resource file.

Simply run the URES.EXE with the command line option -c. This will create the file URES.RES in the current directory. (NOTE: you can also just run URES without command line options to get a list of available commands).

Now, you can add your resources to the URES.RES file by using the command line option:

URES -a -ntitle.bmp -ktitle

This will add the file title.bmp to the resource and give it the key of "title". Keys MUST be unique as URES will fail to add if the key already exists for an item in the resource file.

Go ahead and add all the files you need:

URES -a -nsprite.bmp -ksprite1
URES -a -nexplosion.wav -kboom1

Once you have added all your resources you will be ready to use the URES.RES file.

Add the files resclient.h and resclient.cpp to your project.

Probably during the initialization of your program you will want to read out the files you will need. To do so, create an instance of the ResourceClient_t class, call its extractResource with the the appropriate key for the resource your looking for, and the filename you want to refer to that resource.

Like so:

//: assumes URES.RES in current directory
//: otherwise, if you renamed your res file
//: to something else, or its in a different
//: dir, you would use alternate ctor and
//: pass in path+filename of .res file.

ResourceClient_t rc;
returnValue rv;

rv = rc.extractResource("title" /* key */, "BMP\\title.bmp" /* output file */);

check rv for errors.

//: continue for all resources...
rv = rc.extractResource("sprite1" /* key */, "BMP\\sprite.bmp" /* output file */);

rv = rc.extractResource("boom1" /* key */, "BMP\\explosion.wav" /* output file */);

[...other files...]

The resource(s) will be created in the BMP directory off the current directory, if this directory doesn't already exist, the extract will fail (sorry, beyond the scope of the current implementation).

You would then make the call(s) to DDLoadBitmap (or whatever else) and the files would be there.

Now, one thing (of many) I didn't do, but you will want to do, is to keep a list of the files you use (extracted) and delete them all when you are finished. That was left out of the ResourceClient_t implementation (oversight).

As you can see, there are lots and lots of features that would make this so much better, but there you have it.

Let me know if its still not clear, or if you have other questions and especially if you make improvements I would like to hear about it!


#5 Zenroth   Members   


Posted 08 August 1999 - 05:26 PM

This sounds like a bad method(extracting the files to a temporary dir and then del on finish). Because if one of your goals is to preent ppl from stealing your art/sounds all they'll have to do is alt-tab and go to the bmp directory while the program is still running. I think the prefered method is to actuly load the data from the datafile(e.g. useing custom structs ect.)Other wise why mess with a datafile at all and not just put all the files in the exe?

#6 mordell   Members   


Posted 09 August 1999 - 02:00 AM

Yep, your absolutely right!

The URES source needed to be able to extract files out to a temporary directory, where another process was expecting to find them.

Reading directly from the resource file would be the preferred method. I believe there is an example of this in the DirectX sdk (under fastfile or something like that), as well as part of Chris Hargroves "Code on the Cob" code on www.loonygames.com.


#7 foofightr   Members   


Posted 11 August 1999 - 01:54 PM

I had this kind of problem before, because it was getting that I had 50+ files to send along with the program I was working on. So I wrote a utility that collected the files (specified on command line) and put them in one .dat file.

This was transparent to the program that wanted to read the file. The only thing that changed was the function that it would call to open/read/write/seek/close, etc.

It didn't have compression, but it read files in your "preferred" method by reading the dat file directly.

If you want to have a look at it, let me know..

#8 BarryJ   Members   


Posted 11 August 1999 - 01:57 PM

I would VERY much like to see it, thank you!

#9 Anonymous Poster_Anonymous Poster_*   Guests   


Posted 13 August 1999 - 10:46 PM

In the DirectX 5 SDK, there is fastfile this one has no compression but does the job...

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.