Best way for saving Maps?
So are there are decent article on saving map files? Im currently using simple fstream library to output the data in a txt format, but as the maps get large they are starting to get pretty big save files ( i would like to keep the files under a meg)... would writing them out in binary save any space? do the variables type you fout have any impact of file size? ie i have one variable thats a float... it ends up being something like 3.4500000.... when the text file writes it, it only writes 3.45 so are the rest of the zeros not outputted to save space - or are they their just not visibly when looking at a text editor. Are binary files faster to read / write? any help would be much appreciated.
Lep
Yes, binary files is usually the best way to go if you want to save space. It is also faster to load from and save to a file. Take for instance the floating-point you mentioned (I am assuming a 32 bit floating point). Suppose the value equals 3.45001. In this case, it will take 7 bytes to store the value in a txt file as opposed to 4 bytes in a binary file. So you definetly save in space. Same goes for other types as well. Take a 16 bit unsigned integer (unsigned short) of value 65535. Saving the value in binary form will take up 2 bytes, as opposed to 5 bytes in txt form.
Also, if you are using data structures within you application and you want to minimize the amount of required storage, you may want to align the data on a byte boundery (also know as byte aligned). Byte alignment forces the compiler to pack the data without inserting padding between data elements. The drawback is reduce performance. 32 bit systems prefer packing the data on a 4 byte boundery for faster access to the data.
I hope this helps,
Also, if you are using data structures within you application and you want to minimize the amount of required storage, you may want to align the data on a byte boundery (also know as byte aligned). Byte alignment forces the compiler to pack the data without inserting padding between data elements. The drawback is reduce performance. 32 bit systems prefer packing the data on a 4 byte boundery for faster access to the data.
I hope this helps,
Guy
ALWAYS use binary files. The only benefit of using text files is that it''s human readable.
Here are some tips on keeping your file small:
-Instead of using an int to store a boolean value, use that int to store 16 boolean values, with a bit representing 1 value.
-Split your static and dynamic portions of the file. This way your static file never changes and you can optimize it. This also allows you to have multiple dynamic files, or saved files, for each static file, thus saving space in the end.
Good Luck
Dino M. Gambone
Good judgement is gained through experience. Experience, however, is gained through bad judgement.
Here are some tips on keeping your file small:
-Instead of using an int to store a boolean value, use that int to store 16 boolean values, with a bit representing 1 value.
-Split your static and dynamic portions of the file. This way your static file never changes and you can optimize it. This also allows you to have multiple dynamic files, or saved files, for each static file, thus saving space in the end.
Good Luck
Dino M. Gambone
Good judgement is gained through experience. Experience, however, is gained through bad judgement.
Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.
Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/
Is it really smaller and faster though? Ive wrote my maps out via both methods and they are within a few hundred bytes of each other - with the ascii version being smaller!perhaps this is because many of my textures and such are low value ints - and when writing in ascii it writes ''1'' but in binary it would have to write 00000000001 or whatever. why would they otherwise be so close in size?
The size of the value in binary written depends on the data type of the value itself. Worst case scenerio, a standard data type (longs, shorts, chars, etc...) will take up at most 8 bytes (for doubles).
The size of the value in text files, on the other hand, depends on the value itself. So 1000 would take up 4 bytes in a text file where as the equivilant binary file would only use 2 bytes (if it is stored in a short).
Binary file doesn''t mean that text you read will be displayed in binary format (0001 instead on 1). It means that the value written represents the actual value. It''s pretty much a copy as it appears in memory.
For example:
Say you want to write the value 10 to a file. In a text file, it will appear as 10. In the binary file, it appears as the ASCII character chr(10), not 0x0000000A (hex) or 1010 (binary).
The reason that it''s faster is because reading a binary file requires not translation, unlike a text file which has to convert the text it''s reading into the proper value.
The reason that you''re not seeing a big difference in size is maybe the size of the variables you are writing. IF you are using longs (or ints) all over the place, then there won''t be much of an improvement. Try shorts or chars instead if you know that a value won''t be that big.
Good Luck.
Dino M. Gambone
Good judgement is gained through experience. Experience, however, is gained through bad judgement.
The size of the value in text files, on the other hand, depends on the value itself. So 1000 would take up 4 bytes in a text file where as the equivilant binary file would only use 2 bytes (if it is stored in a short).
Binary file doesn''t mean that text you read will be displayed in binary format (0001 instead on 1). It means that the value written represents the actual value. It''s pretty much a copy as it appears in memory.
For example:
Say you want to write the value 10 to a file. In a text file, it will appear as 10. In the binary file, it appears as the ASCII character chr(10), not 0x0000000A (hex) or 1010 (binary).
The reason that it''s faster is because reading a binary file requires not translation, unlike a text file which has to convert the text it''s reading into the proper value.
The reason that you''re not seeing a big difference in size is maybe the size of the variables you are writing. IF you are using longs (or ints) all over the place, then there won''t be much of an improvement. Try shorts or chars instead if you know that a value won''t be that big.
Good Luck.
Dino M. Gambone
Good judgement is gained through experience. Experience, however, is gained through bad judgement.
Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.
Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/
There's an Ultima Online server emulator called sphere, that uses a text file for it's world map(of course, just for the dynamic objects, the statics are on the cd).
A sample from it:
The worldfile is now 6.37 Mb, and has 62171 objects....
Gaiomard Dragon
-===(UDIC)===-
Edited by - Outworlder on October 13, 2000 12:58:51 AM
A sample from it:
TITLE=Sphere World ScriptVERSION=0.51aTIME=49070674SAVECOUNT=3921[WORLDITEM 0c5]SERIAL=040009524COLOR=037ID=0caTYPE=0LINK=040001ae6ATTR=024MOREP=1419,6,10P=1419,6,10[WORLDITEM 03ed5]SERIAL=040000eb7ATTR=010MORE1=040009524MORE2=02710P=1417,6,10
The worldfile is now 6.37 Mb, and has 62171 objects....
Gaiomard Dragon
-===(UDIC)===-
Edited by - Outworlder on October 13, 2000 12:58:51 AM
Gaiomard Dragon-===(UDIC)===-
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement