I'm attempting to serialize the following:
Expand|Select|Wrap|Line Numbers
- typedef struct
- {
- const char* name;
- const char* layer1[12];
- const char* layer2[12];
- const char* layer3[12];
- const char* layer4[12];
- bool passability[12*800][800];
- }DataMap;
- typedef struct
- {
- DataMap map;
- }MapManager;
Expand|Select|Wrap|Line Numbers
- // Save
- private: System::Void SaveMap(MapManager* map)
- {
- ofstream ofs(StringToChar(CharToString(map->map.name) + ".map"), ios::binary);
- ofs.write((char *)&map->map, sizeof(map->map));
- }
- // Load
- private: System::Void LoadMap(System::String^ fname, MapManager* map)
- {
- ifstream ifs(StringToChar(fname), ios::binary);
- ifs.read((char *)&map->map, sizeof(map->map));
- }
However, I recently learned that I can't serialize pointers which puts me in a bind because I don't know any other way to go about this.
What I'm trying to do is make a simple map editor that saves map data and loads it. I also want to be able to load this data from the game I'm programming. So I decided to use a simple struct the hold the data.
note: I don't necessarily need to use "const char*" if there is a way to convert an object to "const char*" but like i said, I don't know any other way to go about this. The reason I'm using "const char*" is because the engine i'm using only accepts "const char*" for loading textures and so on.
What should I do to save/load my data? Is there a workaround I can do?
I don't necessarily want to know a way to serialize pointers themselves because it might become troublesome in the future, so a workaround would be better. Such as getting the data that the pointer is pointing to a temporary variable and saving that variable instead and loading it in reverse.
(If you need more info than just ask :))