Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualKhatharr

Posted 06 January 2013 - 11:10 PM

Serialization sounds scary but it's actually really easy to do once you give it a try. For every class whose instances will need to be serialized just write a pair of load/dump functions for it that convert to and from 'raw' data. If it has members that aren't raw data then those member object classes also need load/dump functions written, then you just call those from the owner and chain it on to the serialization. By the time you reach the end you can just load/dump the top level object and the whole chain should respond correctly. It's really a lot easier still if you make use of istream and ostream for loading and dumping, since you can just pass the stream down the chain to whatever is getting serialized next. Just remember that for containers you'll want to dump a member count prior to dumping the actual members so that when you go to load the data you know how much data to use for populating the container before moving on to populating the other members.

Seriously, though, it sounds more complex than it is. When you start doing it yourself it should come out sort of naturally. Just start by writing the dump functions and setting everything up for that, then start writing the load functions and adjust the dump functions as needed until everything matches up. If you get stuck then just post showing where you're at and ask for help. smile.png

In terms of security, which was mentioned by OP, if I want to cheat in a game I typically just modify the values in memory while it's running, so I wouldn't worry too much about the savefile format until it becomes an issue in competitive environments or something. Basically the more powerful you make your security the more hackers get off on breaking it. Even giant companies like Sony or Nintendo can't engineer foolproof systems with millions of dollars of research, so....

Serialization is enough to stop people that don't care. Nothing is enough to stop people that do care.

#1Khatharr

Posted 06 January 2013 - 11:09 PM

Serialization sounds scary but it's actually really easy to do once you give it a try. For every class whose instances will need to be serialized just write a pair of load/dump functions for it that convert to and from 'raw' data. If it has members that aren't raw data then those member object classes also need load/dump functions written, then you just call those from the owner and chain it on to the serialization. By the time you reach the end you can just load/dump the top level object and the whole chain should respond correctly. It's really a lot easier still if you make use of istream and ostream for loading and dumping, since you can just pass the stream down the chain to whatever is getting serialized next. Just remember that for containers you'll want to dump a member count prior to dumping the actual members so that when you go to load the data you know how much data to use for populating the container before moving on to populating the other members.<br /><br />Seriously, though, it sounds more complex than it is. When you start doing it yourself it should come out sort of naturally. Just start by writing the dump functions and setting everything up for that, then start writing the load functions and adjust the dump functions as needed until everything matches up. If you get stuck then just post showing where you're at and ask for help. <img data-cke-saved-src="http://public.gamedev.net//public/style_emoticons/default/smile.png" src="http://public.gamedev.net//public/style_emoticons/default/smile.png" class="bbc_emoticon" title=":)" /><br /><br />In terms of security, which was mentioned by OP, if I want to cheat in a game I typically just modify the values in memory while it's running, so I wouldn't worry too much about the savefile format until it becomes an issue in competitive environments or something. Basically the more powerful you make your security the more hackers get off on breaking it. Even giant companies like Sony or Nintendo can't engineer foolproof systems with millions of dollars of research, so....<br /><br />Serialization is enough to stop people that don't care. Nothing is enough to stop people that do care.

PARTNERS