-
Saving Map Array To Disk
I was wondering if anyone could give me a little help on a simple question. I have been making an RPG with DirectX 7, and have the tile engine working perfectly. Now I have made a tile editor to create the land the easy way. All is good, with the exception that I am having trouble saving my array to disk. I used a 2D map array, and was wondering if I should use the C++ stream functions, or stick with C. Someone told me to stick with C, but that doesn't seem to sound right. Anyways, I was just wondering how it would be possible to save the full map array to disk, and have it read back in the same order? Thanks in advance.
-
You can use write() to output an array to a file in one go if you want. There are other ways, it's going to depend on your current code. Post a sample and someone will help you.
-
Sorry for the extra post, I pressed tab to set my code up and I some how exited my entry. I couldn't delete it, so I just edited it so that I didn't look quite as dumb. Sorry.
-
I know how to save a map array to disk, and then re-load it for use, but the problem I have is this: It is a 2D array that I have my tile map set up in. Here is what I have so far:
Code:
/*
int main()
{
ofstream out("test1", ios::out|ios::binary);
if(!out){
cout << "Cannot open file.\n";
return 1;
}
out.write((char *)&map,sizeof map);
out.close();
}
*/
How can I use something similar to save an array but in 2D array style, like map[100][100]?
-
Your best bet is to do the following:
1) Create a map class
2) Make the actual map data private, and a 1D array.
3) Overload operator() to allow things like myMap(0,100)
4) Overload operators >> and << to allow easy string activities (the operators themselves should use read() and write()
It really makes a ton of sense to encapsulate a map in a class, and 2D arrays are bad to work with; there aren't a whole lot of guarantees about how your compiler handles them.