The autosave feature was a bit of a pain to implement. As best as I can tell, the only place where you can add autosave functionality is in the applicationWillTerminate method of the AppDelegate. But the problem there is that my main View class, where I keep all my data, is invisible to the AppDelegate class. (Huh? MVC? Screw that.) And it's kind of hard to save data that's invisible to you.
My solution was to create a singleton class and import it in both the AppDelegate and the View. That's still just a one-way communication though -- the AppDelegate and View can talk to the singleton class, but not the other way around. That was good enough, though. The View class periodically compiles autosave data within the singleton and then when the application terminates, the AppDelegate checks in with the singleton to see if it needs to autosave -- and if so, it does. Then when you start the game back up, if autosave data exists, the InitWithCoder fires it up and you can continue on your merry way. It was a bit trickier than that, though, because the game needs to track a ton of state data and sometimes my timing on compiling the autosave data was a bit off, resulting in the data getting out of sync -- for example, it saves a bunch of Event data but then tries to load it in Map mode, which causes it to get really confused and then die horribly, thus making it impossible to ever start the game again since it immediately crashes. That obviously isn't very acceptable behavior, so I spent a few hours tracking all those bugs down and making sure the autosave data stays synced no matter what combination of loads, saves, and mode changes the user goes through. It seems to be working now.
Just a couple finishing touches to go. Gonna be glad when the programming phase is behind me and I can start actually making a game with this engine that I've spent forever designing and implementing.
- Satellite Observatory (James)


No comments:
Post a Comment
Note: Only a member of this blog may post a comment.