openfl/lime — pull request #38 by bendmorris (2014-02-05 02:44:28+00:00)
Title: DrawTiles optimization

This is a memory/performance optimization for engines that call drawTiles to render each frame.

In both HaxePunk and HaxeFlixel, an array is kept and updated each frame with data that will be passed to drawTiles. The arrays aren't reallocated each frame but are reused. On the next rendering pass, if the size of data to be rendered is greater than the previous frame, the array will expand; if it's smaller, the array will shrink (HaxePunk uses splice() to remove the extra elements in the array, while HaxeFlixel uses "untyped array.length = n").

I've added a parameter to drawTiles, dataSize, which specifies the amount of the XYIDs array that actually contains information that should be rendered - so instead of shrinking the array, the entire array could be passed to drawTiles along with the last position which was written to this frame. This avoids the overhead of having to shrink the array - it can simply grow to the largest size that's needed, and continually overwrite that same block of allocated memory.

Note that on the openfl-native end, the dataSize parameter will default to -1, which will imply that the entire array should be used, ensuring that this change won't break any existing code.

This is my first contribution to lime, so I'm not sure what the correct procedure is, but I have additional pull requests ready to update the API on openfl-native and openfl also if this one is merged.