-
Notifications
You must be signed in to change notification settings - Fork 51
Add JSON serialization for game data and save games #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
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.
I've added both things, and at least on my machine the build runs successfully even if Cereal has not been installed before. |
|
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. |
|
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. |
|
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). |
Fixes a compilation error due to a duplicated entry in data.h.
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.
|
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. |
|
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. |
|
Closed by #655. |
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.