Mail Archives: djgpp/1997/08/03/21:48:15
Dave writes:
>Okay I have tried to look at the source for Demo that comes with allegro
>but i just cant work out the specifics of the dirty rectangle
>allgorithm.
>
>Could someone post an algorithm in code or in Pseudo-code :)
Ok, here goes!
Create a memory bitmap to use as a drawing buffer, the same size as the
physical screen. Also create two lists of rectangles (I'll call them
current and previous) with room to hold a number of entries at least
equal to the maximum number of objects you are ever going to display at
a time. Initialise both lists to contain a single rectangle covering the
entire screen.
Your redraw routine then looks something like:
For each rectangle in the previous list, reset that area of your
memory bitmap to the background image. That might mean just clearing
it to black, or copying graphics across from another image, or
drawing tiles from a map, or whatever.
Clear the current list to empty.
For each movable object in your game, draw it onto the memory
bitmap, and add the area it covers into the current list.
For each rectangle in both the previous and current lists, blit that
area of your memory bitmap across onto the screen.
Copy the current list across so that it becomes the new previous
list.
Repeat.
Obviously this can be implemented without an actual copy of the current
to the previous list, by using pointers and flipping which area of
memory is used by each list. Useful optimisations are sorting the lists
by Y coordinate before the blit to the screen (to cit down on bank
switching), and merging overlapping regions into a single rectangle
while adding new items into each list...
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.
- Raw text -