• Advertisement

Archived

This topic is now archived and is closed to further replies.

Package files

This topic is 5559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve made a package file format for my game that basically lists the files in order they were added. Each file has three fields with it, the name of the file, the size of the file, and the file itself. When the game needs to load a file from the package, it starts at the beginning and goes "Is this the right file?" *checks the filename* "Nope." *checks the size of the file and moves that far ahead in the package* "Is this the file? Nope." until it finds the file. The only problem with this is I plan on putting LOTS of files in this package file, so every time a file is loaded the game has to go looking through the whole package! Then I thought about putting a table in the file listing the filenames and their position in the package, but I realized the game would still basically be doing the same thing ("Is this the file? Nope. Is this the file? Nope..."). The only advantage to that approach that I can think of is that the hard drive doesn''t have to go looking through a big file; its all right there in one spot. Is that table idea a good one? Is it worth it? Is there a better way than any of this?

Share this post


Link to post
Share on other sites
Advertisement
An easy solution, while still keeping most of your work, is when opening the file, you make an "index" in a memory structure. This index contains the filename, size and the position in the package file where the file is. This way, you at least avoid the hd lag while searching. If your planning on having MANY MANY files (10000+) you might want to give your index a hash function, as well, but otherwise I think you have all speed you need.


Share this post


Link to post
Share on other sites
You do use the skip (or whatever its called) command to jump to next file in package - right? Otherwise - if you just move ahead one byte at a time, i can see why its so slow

-------------
E-)mil
I am me - no doubt about that.

Share this post


Link to post
Share on other sites
Oh yeah, I''m seeking right to where I need to be within the archive. And its not really that slow. In fact its much faster than loading each individual file off the hard drive. I just think there''s still lots of room for optimization. It seems like the code is doing much more than is needed. I''m just trying to optimize the file format right now.

Share this post


Link to post
Share on other sites
quote:
Original post by BradDaBug
I''ve made a package file format for my game that basically lists the files in order they were added. Each file has three fields with it, the name of the file, the size of the file, and the file itself. When the game needs to load a file from the package, it starts at the beginning and goes "Is this the right file?" *checks the filename* "Nope." *checks the size of the file and moves that far ahead in the package* "Is this the file? Nope." until it finds the file.

The only problem with this is I plan on putting LOTS of files in this package file, so every time a file is loaded the game has to go looking through the whole package! Then I thought about putting a table in the file listing the filenames and their position in the package, but I realized the game would still basically be doing the same thing ("Is this the file? Nope. Is this the file? Nope..."). The only advantage to that approach that I can think of is that the hard drive doesn''t have to go looking through a big file; its all right there in one spot.

Is that table idea a good one? Is it worth it? Is there a better way than any of this?


You can try to have a table at the begining of the package-file, with the name of every file, their size and the position where it begins. If this table is sorted (using the name), then you can do a binary search. I supose that this will improve a lot the speed.

P.S.: Sorry for my bad english...

Share this post


Link to post
Share on other sites

  • Advertisement