Skip to content

Decouple save games from internal data structures #21

@willglynn

Description

@willglynn

I'd really like to shuffle around the members of struct BuzzData, but I can't because the game assumes old save files conform to that structure layout. We could change the magic number every time we change the save game format, but that's a poor solution. So, let's talk about better solutions.

Protocol Buffers

Protocol Buffers were created to address this need to sanely version data structures.

  • Pro: it lets us be explicit about how data should now be laid out without forgetting about how it used to be structured
  • Pro: it cleanly separates the definition of an interchange data structure from the code that accesses it
  • Pro: it would be particularly appropriate for use over a network (play-by-mail/Internet multiplayer)
  • Con: it's another library

jsoncpp

Another option would be to use jsoncpp's coercion and default value support:

m_name = json_object["name"].asString();
m_female = json_object.get("female", false).asBool();
m_capsule = json_object.get("capsule", 0).asInt();
m_lunar = json_object.get("lunar", 0).asInt();
m_eva = json_object.get("eva", 0).asInt();
m_docking = json_object.get("docking", 0).asInt();
m_endurance = json_object.get("endurance", 0).asInt();
  • Pro: we already have jsoncpp
  • Con: we have to consciously worry about versioning in the code
  • Con: ...and we're going to get it wrong somewhere

Even if we pick Protocol Buffers for save games, it shouldn't replace jsoncpp for game data. Game data should be user-editable, and JSON wins there. Moreover, versioning is unimportant since we can to change both the game data and the code that reads it simultaneously. Save games live on-disk, and we're expecting saves to be written by one version and read by another.

Thoughts?

Metadata

Metadata

Assignees

Labels

Technical EnhancementImproves the codebase for stability, ease of development, or other non-gameplay reasons.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions