More time has been spent on dirty rectangles to try and eek out some performance during rendering to canvas. There are basically two methods which I am currently fighting with:
- Brute force method
- Joined rectangles method
With the first method, we just go ahead and grab dirty rectangles for each object regardless of whether another object is grabbing that rectangle (or part of it) as well. Thus, if there are 30 dirty objects, we grab 30 rectangles each frame, draw 30 objects, then for the next frame we restore 30 rectangles and do it again.
If we combine rectangles, it might add up to a savings if the objects overlap. However, time will be spent determining the overlap and joining rectangles before actually grabbing the images to later restore. I'm not sure if the trade-off is worth it without actually testing it. The actual method is pretty intensive and requires visiting objects, which have already been visited, repeatedly. This might end up causing more overhead than just a simple brute force method.
The other issue, with dirty rectangles, is the particle engine. Capturing hundreds of tiny little rectangles for the particle engine is messy, and time consuming. The actual time saved is lost because we're doing twice the work for all of those particles. For larger objects it makes sense. If we can eliminate the need to redraw 30 objects, if only 3 are moving, then we save time. There are some tricks for particles, such as using bitmaps for the explosions which simulate particles but that might look bad.
Maybe using the Asteroids Evolution demo to test all of this isn't the best idea, after all.
No comments:
Post a Comment