Most of my spare time today went to fighting with the WP7 Ad control, but I did get some time to work on adding persistence to Monsters. It’s working except for persistence of AggroTarget (which points at another Actor, typically the Player). This is just one instance of an issue that will come up often in the game: persisting references between objects

The challenge during rehydration is: how do you re-establish that reference if the target actor hasn’t been created yet? I expect I’ll need to add some kind of unique id to each Actor (or, at a broader level, each GameObject), persist/restore that id, and then do a second “fix-up” pass on the list of Actors in a Level to re-establish those relationships. I’m hesitant to do it as it feels error prone; any time I add a new reference variable I need to remember to do the fixup on restore :P.

The alternative is to do away with references altogether and simply store those “InstanceIds” and use those to look up the object from an array of objects any time one object points at another. That would gross-up the code a good deal though, and I’d end up adding complexity everywhere just to avoid it in persist/restore. So, I’ll likely go with the aforementioned model.

I didn’t get that completed, so no new code update today. Hopefully tomorrow!

Cheers,
Jeff

Advertisements