#Making a save system for a sandbox game

17 messages · Page 1 of 1 (latest)

vivid otter
#

So, I am making a sandbox game and need to make a save system that can basically store the entire save state. I understand the basic idea that I can in theory serialize a bunch of data into a file and then take it out again in the same order but theres a few caveats im curious about:

  1. Platform independence. While not extremely important, it would be nice to know that saves can be transferred just fine. I understand that different systems store data differently, so just using read or write or <</>> on a struct it will depend on how the compiler/system organizes the bits. (big endian vs small, and maybe other things?). Im thinking the way to solve this is probably some library

  2. Corruption. Idk how big of an issue this is or if I should even worry about it, but if the data is somehow corrupted I probably don't want to load it since it might cause big errors

  3. Version independence. This is the most problematic to me. I don't need to seriously worry about it until(unless) I actually release and have players but I'd like to start with this in mind. When I update the game, I'd want old saves to always work on new versions (tho not vice versa). The only way I can think to do this is to futureproof the system for any changes I might make to the game (impossible) or maintain a seperate save loader for every major version of the system I make. Maybe theres a better way? I wonder how most games deal with it.

Any help or insight is appreciated, thanks!

peak birchBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

tidal fable
#

The byte order only matters when you directly reinterpret a sequence of bytes as a data object. When you implement your own serialization – deserialization it will work regardless of the platform byte order.

vivid otter
#

i would want to serialize into binary to avoid huge file sizes

tidal fable
#

Yes, you can still implement your own serialization into – deserialization from binary data.

vivid otter
#

it probably would be worth it to use some library to serialize the basic types right

tidal fable
#

Not really.

vivid otter
#

why not? I mean why would I need to implement converting int to bytes i dont even really know how id do that easily

tidal fable
#

I guess it might be if you use types like float.

#

For integers serialization is very easy.

vivid otter
#

im definitely using floats

#

ideally I could just slap a struct straight into the file at a specific location

#

rather than making a custom serialization and deserialization scheme for each struct I need to use

mossy cairn
#

If possible, I would go with something like Boost's serialization library: https://www.boost.org/doc/libs/latest/libs/serialization/doc/tutorial.html

  1. It will deal with all the platform bits, allowing to choose between saving as text, xml (useful for debugging your save files during development), or portable binary archives (see the examples, you'd have to add IEEE float support manually).
  2. I would use a checksum using a fast hashing algorithm (like xxHash). If the checksum doesn't match, you have corruption, and warn the user.
  3. Boost allows class versioning during se/deserialization. At least, the save loaders for every major version will be centralized to a single function.
vivid otter
#

thanks!

peak birchBOT
#

@vivid otter Has your question been resolved? If so, type !solved :)

vivid otter
#

!solved