Search code examples
c++file-iodynamic-data

Storing and Retrieving Dynamically Changing Structures


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;

};

Solution

  • 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++ ?