One feature that C++ does not provide out of the box is the ability to get information about a class at runtime. We might want to know how many members it has, their names and types, and where they are stored in memory. Known as reflection, this would be very useful, for example, when initialising objects from a file.

I absolutely need to have the game data stored outside the program. Possibly external tools will be used to edit it. I also need to be able to change it while the game is running. As a minimum I need serialisation if not a full reflection system.

While there are a lot of reflection and serialisation systems for C++, none of them have exactly the feature set that I need, which is:

  • Serialisation/Deserialisation to text or binary files.
  • Non-intrusive code (i.e. I don’t have to change the classes to support serialisation).
  • Human readable/editable file format.
  • Tolerance to missing/extra data.

And most are a lot more complicated than I would have a use for.

So I wrote something that looks a bit like Boost serialisation but without all the complicated bits, and uses JSON as a file format. Rather than having version numbers (not human-friendly) I match data when loading based on the name.

It’s not reflection, yet, but it’s enough to get started.