flixel
flixel copied to clipboard
Cache transformation calculation results
we need to find the way to cache transformation calculation results, which could improve perfomance due to less calculations done at each frame. as you can see here: https://github.com/Beeblerox/flixel-spine-hx/blob/transform-sprite/source/flixel/addons/display/FlxTransformableSprite.hx#L65-L123 there are a lot of repetative calculations. and they should be reduced as much as possible. But having multiple camera support making it harder to achieve (but not impossible i think)
Adding and maintaining a dirty flag for _matrix (and related variables) should be easy enough, although the potential savings in redundant computation against the overhead of caching likely only results in a win if the majority of sprites are static the majority of the time. Of course as with anything performance-related, profiling would be the only way to be certain.
One question, though, regarding the computation in isOnScreen: why is the transformMatrix being applied after the translation caused by the Camera? That does not seem to match what is happening within drawComplex. Is the transformMatrix supposed to be in "view space"? If so, what is the point of having a single transformMatrix to apply to all cameras?
Assuming that the transformMatrix is a "world space" transform, then the solution here is to make the cached _matrix completely view-independent by not involving a Camera at all. Instead, the bounds of each camera can be transformed into "world space" and the overlap check performed there. And then, if all cameras and sprites are able to cache their "world space" bounds, then the overlap checks can be made reasonably fast.
I hope that makes sense. (: