Creating own file format...
Since i got my hands on a copy of AC3Di have been wondering "Howdo you makeyour own file format". Something like this would be really handy for me, as i would like to make my own map format.
This would have to hold:
a height field terrain
sea level
speed of waves
positions and models of arbitrary objects (eg. houses)
How would i go about doing this.
------------
"Here lies a toppled God,
His fall was not a small one,
We but built his pedastle,
A narrow, and a tall one"
Frank Herbert (Dune:Messiah)
Something like:
4B File signature, like 87 12 E4 D0 or something..
2B Sea level offset
2B Speed offset
2B Objects offset
offset 11-Sea level offset : Height field (1B height)
offset Sea level - Speed offset : Sea level (1B height)
offset Speed offset - Objects offset : Speed of waves (1B speed or 2 or 65536, it doesn't really matter)
offset Objects - end of file : Objects with something like:
2B number of triangles
current offset - number of tris :
6B X, Y and Z positions (could make it 12B if you need minus positions and you want all 65536 numbers or divide with 100 or 1000 to get decimals?)
Maybe 2B (RGB565) or 3B of color?
Just a proposal which you can play with.
It's not advanced at all but I believe it's up to you to figure out a decent final format. Also RLE is a very good option to improve the size with the height fields and sea levels (if bigger parts are plain of course).
[edited by - nife on May 31, 2004 4:13:32 PM]
4B File signature, like 87 12 E4 D0 or something..
2B Sea level offset
2B Speed offset
2B Objects offset
offset 11-Sea level offset : Height field (1B height)
offset Sea level - Speed offset : Sea level (1B height)
offset Speed offset - Objects offset : Speed of waves (1B speed or 2 or 65536, it doesn't really matter)
offset Objects - end of file : Objects with something like:
2B number of triangles
current offset - number of tris :
6B X, Y and Z positions (could make it 12B if you need minus positions and you want all 65536 numbers or divide with 100 or 1000 to get decimals?)
Maybe 2B (RGB565) or 3B of color?
Just a proposal which you can play with.
It's not advanced at all but I believe it's up to you to figure out a decent final format. Also RLE is a very good option to improve the size with the height fields and sea levels (if bigger parts are plain of course).
[edited by - nife on May 31, 2004 4:13:32 PM]
mmm, i get how it wouldwork, i just dont know how to save it. Would i have to do fwrite or something?
Are you using C++? fwrite is from a few different languages . I personally use good ol'' fstream To quote directly from the many statements that have been beaten into my head recently
#include <fstream.h>ofstream outfile; //global variable like cout that //handles output to a filevoid main(void){ outfile.open("filename.lol", ios::out); outfile << data;}//Comparatively this is a primitive way of operating but whatever :)
quote:Original post by uber_n00b
Are you using C++? fwrite is from a few different languages . I personally use good ol'' fstream To quote directly from the many statements that have been beaten into my head recently
#include <fstream.h>ofstream outfile; //global variable like cout that //handles output to a filevoid main(void){ outfile.open("filename.lol", ios::out); outfile << data;}//Comparatively this is a primitive way of operating but whatever :)
Tisk tisk, using deprecated header files, and the stream types are not in global namespace, there in std namespace.
Sorry but I refuse to give that way up because well why? THEY'RE in the std namespace only if you include <'fstream> buddy. I don't care if they are 'deprecated', but that's how the damned C++ courses still teach them unfortunately.
[edited by - uber_n00b on May 31, 2004 8:43:24 PM]
[edited by - uber_n00b on May 31, 2004 8:43:24 PM]
Those header files are not meant to exist, you'll see what will happen when you try compile your code on a newer compiler like VS.NET 2003 and see what will happen!, VS.NET 2003 has completely remove the old header style. At the moment your using code that may be buggy because those headers are likely not have been maintained for a long time. The reason for all this is standardization and thats not standard C++ code. Go ahead use if you like but don't pass on bad habits to other people learning.
[edited by - snk_kid on May 31, 2004 9:56:49 PM]
[edited by - snk_kid on May 31, 2004 9:56:49 PM]
Hey, I think I''ve read enough threads regarding standard headers this week, let''s give it a rest and get back on topic. I think the standard people have made their point.
fwrite is in the C runtime, but you could certainly use it if you''re writing C code. In C++, you would indeed use an ofstream (and conversely an ifstream for reading), but it''s not as easy as using the overloaded << and >> operators. You''ll have to use write and read. And you must, I deplore you, open your files in binary mode. Or else your data will be transformed without your knowledge and you''ll come back here wondering why
quote:Original post by Kris2456
mmm, i get how it wouldwork, i just dont know how to save it. Would i have to do fwrite or something?
fwrite is in the C runtime, but you could certainly use it if you''re writing C code. In C++, you would indeed use an ofstream (and conversely an ifstream for reading), but it''s not as easy as using the overloaded << and >> operators. You''ll have to use write and read. And you must, I deplore you, open your files in binary mode. Or else your data will be transformed without your knowledge and you''ll come back here wondering why
quote:Original post by uber_n00b
Sorry but I refuse to give that way up because well why? THEY''RE in the std namespace only if you include <''fstream> buddy. I don''t care if they are ''deprecated'', but that''s how the damned C++ courses still teach them unfortunately.
[edited by - uber_n00b on May 31, 2004 8:43:24 PM]
So your not allowed to teach yourself?
90% of programming is not what you learn in school, but what you teach yourself as you work in the industry or as a hobby. Don''t be afraid to change the way you do something just because you learned it a different way.
First make it work, then make it fast. --Brian Kernighan
The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)
Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement