Skip to content

Conversation

@hweimer
Copy link
Contributor

@hweimer hweimer commented Oct 1, 2020

This PR introduces serialization for both game data and save game files by handling them as JSON files when written to/read from disk, using the Cereal library. Char arrays are serialized into JSON strings with loading ensuring that they fit into the respective buffer. Simple numeric arrays are serialized as JSON vectors. Save game files are additionally compressed using zlib before writing.

This is a rather minimal approach in that only the game data structure plus replay and event data get serialized so far. However, it should be rather straightforward to extend this to other areas such as mission data files by adding a serialize function to the struct of interest. To this end, serialize.h includes some helper macros for string and vector serialization for C-arrays.

Fixes #21.

This commit introduces serialization for both game data and save game
files by handling them as JSON files when written to/read from disk,
using the Cereal library. Char arrays are serialized into JSON strings
with loading ensuring that they fit into the respective buffer. Simple
numeric arrays are serialized as JSON vectors. Save game files are
additionally compressed using zlib before writing. Fixes raceintospace#21.
Fixes two issues with data serialization. First, the buffer for
temporary storage of news events was not initialized properly, which
could lead to segfaults or missing news entries. Second, the AstroLevel
was not getting serialized, leading to recruiting starting again with
group I after loading a save game.
Fixes a number of issues with improper serialization of the game data.
1) Data->Season was not serialized.
2) AstroLevel was missing in urast.json
3) An off-by-one resulted in the serialized string not being
   null-terminated
4) Vectors of a multi-byte type were not de-serialized correctly
5) Data->Prestige.Goal[] was serialized as uint8_t instead of
   uint16_t.
@rnyoakum
Copy link
Contributor

rnyoakum commented Oct 8, 2020

The cereal header and move to C++11 should be added to this pull request as well, so they get committed together.

Adds the Cereal library to the build process and sets the C++ version to
C++11.
@hweimer
Copy link
Contributor Author

hweimer commented Oct 16, 2020

The cereal header and move to C++11 should be added to this pull request as well, so they get committed together.

I've added both things, and at least on my machine the build runs successfully even if Cereal has not been installed before.

@pemensik
Copy link
Contributor

pemensik commented Nov 1, 2020

Is another serialization library required? I think we already have jsoncpp library for handling json. And we also require protobuf. Do we have specific reason to choose yet another library? More different libraries makes it harder to build from source.

@rnyoakum
Copy link
Contributor

rnyoakum commented Nov 1, 2020

There's a discussion of using Cereal in #21. The idea was to move to C++11, use Cereal as a serialization library and drop Protocol Buffers support. If you have any opinions or disagree, I'd love to hear it.

Because of the need to hash out any such issues, I wasn't merging this pull request until after the next release.

@hweimer
Copy link
Contributor Author

hweimer commented Nov 2, 2020

The problem with both protobuf and jsoncpp is that you can't directly serialize from the current Data struct. So, using them would mean to change almost every line of code of the entire game. Frankly speaking, I don't see this as a realistic option. With Cereal, you just need to add a serialize method to the struct and that's it. Additionally, Cereal is a header-only library, so I don't see how this makes building from source any harder (other than requiring a C++11 compiler).

@hweimer hweimer mentioned this pull request May 5, 2021
Fixes a compilation error due to a duplicated entry in data.h.
hweimer referenced this pull request May 15, 2021
I also went through all our closed Issues to make sure all the improvements we've made are included.  A few had fallen through the cracks.
@hweimer
Copy link
Contributor Author

hweimer commented Jun 3, 2021

Given that there is now an growing list of issues that can be fixed much easier when this PR gets merged, wouldn't it make sense to merge it into a new branch to keep things going? Alternatively, one could also create a separate release branch in which #416 gets taken care of.

@peyre
Copy link
Member

peyre commented Jun 3, 2021

It sounds good to me. I'm inclined, though, to defer to the programmers in the group, as I don't necessarily understand the potential implications of this one.

@hweimer hweimer mentioned this pull request May 30, 2022
@hweimer
Copy link
Contributor Author

hweimer commented Jun 6, 2022

Closed by #655.

@hweimer hweimer closed this Jun 6, 2022
@sflynn850 sflynn850 added this to the Release 2.0 milestone Jun 12, 2024
@sflynn850 sflynn850 added the Technical Enhancement Improves the codebase for stability, ease of development, or other non-gameplay reasons. label Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decouple save games from internal data structures

5 participants