Jesse Freeman asked for advice:
I’m not a stupid person but prop injection is retarded. I need both vars set before calling apply -> http://twitpic.com/1dz5d9 #Advice
This comes up quite a bit in Mockingbird since hot-swapping dependencies while a game is running is our major differentiator. In practice, it’s often not necessary, but it definitely always make your code more complicated, more fragile and (inevitably) buggier.
If your class has (or ever could have) more than two hot-swappable dependencies, you need a proper invalidation model in order to scale to the dependencies. You can also potentially have a faster object by deferring, and thus aggregating, validations.
Here’s a quick example class I just wrote-up because code speaks louder than words. To keep things conversational, I typed it up in a text editor and haven’t actually tried to compile and run it, which probably means there are typos and stupid mistakes. But the point (and pattern) should hold.
If USE_DEFERRED_VALIDATION is true, validation will not occur immediately when a property changes. Instead, a flag will be set and on the next frame validation will happen. This allows you to set multiple dependencies during one frame and they’ll all be applied at once the next frame.
The classic game engine loop basically embodies this invalidation model with update() (which invalidates) and draw() (which validates).
Tags: as3