Wednesday, February 18, 2009

Chunk and BitmapCamera

New system and test: BitmapCamera.
The only fast reliable form of panning is via bitmapData and draw()/copyPixels(), as far as I know. And I've tried a LOT - including writing pixelbender shaders, crazy memory flop tricks and every form of bitmap caching available.

The fastest method I call the BitmapCamera. Run a copyPixels on everything that the window 'sees' doing appropriate transforms. Don't render a single pixel that doesn't need to be there (especially not transparent). So, in taking from MMO client methodologies, here is a culling BitmapCamera. Basically, if we can't even see the object, it's not even going to be considered (and may not be in memory). You can expand that to include dynamic loading/unloading of tile pieces, and if you know enough about the prefetch paths (for example, with a Graph or BSPTree), you might know WELL in advance.

This code was written stealing the architecture from that of common 3D clients, abstracted down into simple classes, and then extended as "Bitmap" versions of them. However the scene type class that I have doesn't care what it is, so it could work to do a portalcast/scenegraph for a 3D flash renderer.

In this example, use the arrow keys to move the 'camera'. Sprites that are out-of-frame (represented in red) will go transparent to denote this. The blue doesn't mean anything here but the possibility of a loading/unloading hysteresis.

BitmapCamera test 01

(EDIT: I added mousewheel support... mousewheel while keyboarding around to change the camera size - on flash 10 it should still be quite fast even at 800+ pixels)

No comments: