Oik, assuming your height map is something like:
int map[1024*1024];
fwrite(map, 1024*1024*sizeof(int), 1, f);
and
fread(map, 1024*1024*sizeof(int), 1, f);
You can easily use fstream too, I prefer the old C file I/O functions mostly out of habit.
I''d suggest you store the map in a linear array like that. You can always type case it to a pointer and use it like a 2-d array or just use the math and index into it directly (y*width + x).
Peace
Creating own file format...
quote:Original post by PeterTarkus
Oik, assuming your height map is something like:
int map[1024*1024];
fwrite(map, 1024*1024*sizeof(int), 1, f);
and
fread(map, 1024*1024*sizeof(int), 1, f);
Thats exactly what i did too. Except my Array is in BYTES as in:
BYTE HeightMap[MAX_SIZE*MAX_SIZE];
But it only reads in the first line of my file, so if my file looked like this:
abcde fghij klmno pqrst uvwxy
It would only readin first line, IE: abcde
Hope that cleans it up
what about ReadFile() and WriteFile()??
My oversimplification of the process:
1) come up with a struct you like that has all the data you need to load from the disk.
1.5) Make one. (E.G. " MYSTRUCT MyStruct; ")
2) put information in it ( MyStruct.Blah = Foo; )
3) Write it to a file using WriteFile
to read:
1) MYSTRUCT MyStruct;
2) then use ReadFile(). There ya go.
look at MSDN for how to use WriteFile() and ReadFile(). You''ll also need CreateFile().
My oversimplification of the process:
1) come up with a struct you like that has all the data you need to load from the disk.
1.5) Make one. (E.G. " MYSTRUCT MyStruct; ")
2) put information in it ( MyStruct.Blah = Foo; )
3) Write it to a file using WriteFile
to read:
1) MYSTRUCT MyStruct;
2) then use ReadFile(). There ya go.
look at MSDN for how to use WriteFile() and ReadFile(). You''ll also need CreateFile().
I don''t see any immediate problem in your code, maybe when you write the RAW file you didn''t write it all or something. I don''t know, sorry, maybe someone else can see the problem, from what I see your code should work.
YEs,i managed to gt it working. I now have an editor that saves a .BEL file. An i hav a function in mygame taht loas the map. And a function thatdraws it.
Also, i was wondering. Is it possible to pass a struct into a function as a parameter?
Also, i was wondering. Is it possible to pass a struct into a function as a parameter?
Its an easy process that involves appending a data file to a file extension to categorize what kind of data is in the file..
Make sure your using binary mode! Your data should not be stored in lines at all. your file should have some sort of master header that gives a good synopsis of what it contains. (eg. # heightmaps, enemies, etc). one way to handle differnt data types in the same file would be to have a small mini-header prior to each data chunk. this little header would have info in it about the size of the data that follows, the type of data (maybe a simple int) so that data can be interpretted properly. Another method would be to have everything in the file appear in a very strict layout, only this is more limited.
The system I am working on is rather complex.. It is going towards a full fleged data base system which uses a B-Tree for indexing, and actually stores a scene graph. My system will allow for unlimited expansion to my level data, which is broken up accross a regular grid. I use an advanced paging system and stream in level data as it is needed.
The system I am working on is rather complex.. It is going towards a full fleged data base system which uses a B-Tree for indexing, and actually stores a scene graph. My system will allow for unlimited expansion to my level data, which is broken up accross a regular grid. I use an advanced paging system and stream in level data as it is needed.
Yes,i open my file in binary mode. But dont worry about the lines. What i was saying i that when i open it in notepad.I can acctually see my image drawn with symbols. Myfilestruture is rather basic:
MapName
Description
Water Level
.RAW data
I am planning to ad other stuff such as coords of models.And the Map Textures. Anyway, can u pass a struct into a function as a parameter?
MapName
Description
Water Level
.RAW data
I am planning to ad other stuff such as coords of models.And the Map Textures. Anyway, can u pass a struct into a function as a parameter?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement