Skip to main content
gamedev.net
🔒 Locked

Resource Files

Started by Jackbunny 0 replies 300+ views
Original Post
Jackbunny
Jackbunny
I''m wanting to create resource files for a game I''m working on so I can group all my bitmaps, all my character files etc into one binary file. What I want to do is create a simple app that will allow me to pick which bmp files I want. I''m going to create a table of contents at the beginning of the file so that I know where to go. The example table would like something like bitmap1.bmp|(size of bitmap1)|bitmap2.bmp|(size of bitmap2)| Just for testing purposes I want to loop through and break the file back into seperate bitmap files. I''m having several problems. First of all I''m wondering if a table of contents is the way to go. I couldn''t figure out how to do a search in an fstream so I thought that a header telling me where to start would work best. Next, on the reopen, I''m having trouble putting together the actual code to break apart the file. As near as I can tell I need to use the seekg member function of fstream to get to the position based off of the file sizes of preceding bitmaps. Example: Bitmap1 has size of 3 Bitmap2 has size of 2 Bitmap3 has size of 4 I''m searching for bitmap3 so I would go to position 6. Something doesn''t seem right with this. It seems sloppy and inaccurate, but I''m not sure what else to do. Thanks in advance for your help.
"I am Galstaff sorceror of light!""Then how come you had to cast magic missile?"
Chuck Stumps
Chuck Stumps
There are a whole number of different ways to set something like this up. It all depends on what you want to support. Do you want to allow files to be in different directories, preserving directory structure inside your archive? If not then your on the right track with your table of contents, just add in a location field that gives a bitmaps offset within the archive. If you do want to preserve directory structure then you might want to look into how a directory tree might be stored on disk and try to come up with some data sturcture you can use to represent that and act as your ''table of contents''.

Your other problem: accessing the individual files withing your archive. You could just search to the specified bitmap in the archive and read the whole thing into memory, freeing it when your finished with it. Another possiblity would be to keep an open open pointer to the archive and create your own file handle interface, wrapping common file functions like open, close, seek, read, etc.

In other words create a structure/class which has fields such as start location, end location and size. Then when the program has to access a file in the archive, your little file handle system searches to the specified bitmap in the archive and fills in the start and end locations as file offsets in a copy of that structure/class. That structure is then returned from your ''open'' function to act as a handle in your other wrapped functions. With the information provided in that structure your other functions should have the info they need to manipulate data in the archive, keeping the fact that its a archive and not a individual file hidden from the rest of yoru program.

That seems to have come out a bit more convoluted then I had hoped. Look around though, there are many tutorials available on virtual file systems.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.