Jump to content
  • Advertisement
Sign in to follow this  
graveyard filla

how to verify contents of a map file?

This topic is 5145 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

hi, im working on a 2d tile based RPG, and was wondering, is there anyway to verify that a map file is valid? surely there must be a way, because using other program's ive seen this sort of thing. im using binary file i/o using fstream::write/read. basically, lets say in my map editor i try to parse in a jpg file or an html file or something, how could i stop this from crashing the game? i know i could just make sure the extension is .map, but even then, what if the map file got currupted? anyway, thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
It depends on how you set out your map file, really you just need to code in lots of checks for invalid data. With a tile map when reading in the tile IDs for each tile in the map, say a certain tile says it uses ID 232058 but there's only 200 tile images then the file must be corrupt.

Another thing you can do is put a magic number in the file header. This is basically an arbitray number that you put somewhere in the header that is always the same, then when reading in the file if the magic number is not correct then the file is corrupt.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You could do a hash check (like MD5)

You got your .map file, then you take the hash code of it and put that as your "magic number". Then before loading the map you take again the hash of the (file - the magic number) if it's different then the file is corrupt.

MD5 creates a 32 character string no matter how long the input and as soon as 1 character of the original string is changed, the hash string changes aswell.

That could work I guess.

Share this post


Link to post
Share on other sites
Clicky

There is some superb information on file i/o there, he even shows a simple technique to make sure the structure of the file format is intact. Its definetly worth checking out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!