Further Rendering Optimizations 445
An Isometric Rendering Class
At last, I’m going to bring all the frame buffer stuff together and create a class that will minimize blitting using a frame buffer for scrolling and update rectangles. First, a decision must be made about what infor-mation such a class will need, based on the discussion so far.
during initialization, but again, this is not a big deal. Since you’ll be using update RECTs, you need some way to store a list of RECTs in the class. Unfortunately, you don’t know how many RECTs are needed, so you should probably have some way to allocate a number of RECTs that should be sufficient. Because you will rely on an array of boolean values to check whether to update a given map location, you need such an array in the class itself. The update array isn’t needed anywhere but within the rendering class, so doing this is OK. Finally, you need a rendering function. This will not be within the class itself, but rather a function that you create outside of the class and give a pointer to it to the renderer. This will be just like what you do with your TilePlotter and TileWalker, only you must always supply the function rather than having it predefined.
Here’s a summary of what you need in the way of members of your rendering class:
• A boolean update array of arbitrary size
• A pointer to a rendering function
Without further delay, let’s get to it. Go ahead and load up IsoHex17_2.cpp. In this example, I have supplied CRenderer in the files IsoRenderer.h and IsoRenderer.cpp.
The code for CRenderer is the most complicated that I’ve written so far. This is because there are just so many things that have to be examined and calculated for it to work. The declaration of CRenderer looks like the following: