views:

86

answers:

2

I am creating a game using Allegro/C++. The game is almost done and now, I want to create a map editor. The game contains numerous classes and their number will vary depending on the number of objects the map requires. I was thinking of creating a separate structure to hold level data and store it as a map. The problem is that the size varies according to the map and I've got to use pointers to accommodate objects depending on the number. What is the best way to store such data and retrieve it.

An example of the structure I was thinking of-

struct Level
{    
    int soldierCount;

    Soldier **soldier;

    int taskCount;

    int *taskPercentage;

    int *taskBitmapX;

    int *taskBitmapY;

};
A: 

Create class for each different datastructure and then implement Read/Write functions for them. Use some flags between records to indicate the type of the record. For dynamic arrays store first the number of items and then store items.

Riho
+1  A: 

So, what you want to do is serialization.

I suggest simply using an already existing library for that. Have a look at this thread: How to serialize in c++ ?

Loki