Reduce rendering calls
Note that last time we reduced the number of objects returned in collision detection using a bin-ing strategy from 10020 to just around 31 objects. But then after profiling the application we noticed that the most time was now being spent in the rendering loop. Upon examination both loops were largely inefficient they were in fact both performing loops on 10020+ objects each call which was happening at both 33fps and the updates were as often as possible.
Since the strategy existed already it was easy enough to figure out how a bounding box of objects to grab each time we render the screen and only render those objects since they are the only ones that are visible.
One problem that arose from this was the fact that the way the views work the actual objects on screen were significantly scaled.
Handle scaling
Screen size was 640x480 but each tile is 8x8 and is scaled. Blown up by a factor of 5. So grabbing a 640x480 section of from the SpacePartitionStrategy resulted in returning over 5000 objects.
If we take the inverse scale factor for the x and y directions which where 1/5 since each x and y was multiplied by 5. Then we get a grid size of 128x96 so instead of about 80*60 (4800) objects we now are only rendering 16*12 or 192 objects approximately. Of course it comes out to more like 200 or so objects based on bin boundaries and that will fluctuate when we add in smooth scrolling on maps.
The savings are incredible and give many many more benefits for future development.
Check out the commits
You can check out the diffs of the four commits created for these two posts.
Abstract partitioning scheme 32994afbc7d8bf2c34f4e3246473acb9eace8d7f
Space partitioning that does not work 4e09bed3aff2f03856ff282ec4c6e1d91ca6ed58
Fix integer bin partition strategy e62a1760dd9c59d6d8619b88f03a24f573c23e37
Reduce Rendering using Partitioning fb896ef2098972b6007bb1cb0b03d74e14f93ce6
No comments:
Post a Comment