dirty rectangles
Niunio

I'm using dirty rectangles from the Allegro Demo Game in my next project which is a Pong game. I've changed it a bit because I'll use a background bitmap. Here you have the function I'm using to clean the background:

1void mjCleanDirtyRectangle (BITMAP *bmp)
2{
3 int c;
4 DIRTY_LIST swap;
5 BITMAP *Active = mjActiveVideoPage ();
6 
7 if (is_video_bitmap (Active)) acquire_bitmap (Active);
8/* clear everything drawn during the previous update */
9 for (c = 0; c < dirty.count; c++) {
10 if ((dirty.rect[c].w == 1) && (dirty.rect[c].h == 1)) {
11 putpixel (Active, dirty.rect[c].x, dirty.rect[c].y,
12 getpixel (bmp, dirty.rect[c].x, dirty.rect[c].y));
13 }
14 else {
15 blit (bmp, Active,
16 dirty.rect[c].x, dirty.rect[c].y,
17 dirty.rect[c].x, dirty.rect[c].y,
18 dirty.rect[c].x + dirty.rect[c].w - 1,
19 dirty.rect[c].y + dirty.rect[c].h - 1);
20 }
21 }
22 if (is_video_bitmap (Active)) release_bitmap (Active);
23/* swap lists, so the just cleared rects automatically are in this update */
24 swap = old_dirty;
25 old_dirty = dirty;
26 dirty = swap;
27 dirty.count = 0;
28}

And next is the screen update function:

1void mjUpdateDirtyRectangle (void)
2{
3 int c;
4 BITMAP *Visual = mjVisualVideoPage (), *Active = mjActiveVideoPage ();
5 
6/* for dirty rectangle animation, only copy the areas that changed */
7 for (c = 0; c < dirty.count; c++)
8 add_to_list (&old_dirty, dirty.rect[c].x, dirty.rect[c].y,
9 dirty.rect[c].w, dirty.rect[c].h);
10/* sorting the objects really cuts down on bank switching */
11 if (!gfx_driver->linear)
12 qsort (old_dirty.rect, old_dirty.count, sizeof(DIRTY_RECT),
13 rect_cmp);
14 acquire_bitmap (Visual);
15 for (c = 0; c < old_dirty.count; c++) {
16 if ((old_dirty.rect[c].w == 1) && (old_dirty.rect[c].h == 1)) {
17 putpixel (Visual, old_dirty.rect[c].x, old_dirty.rect[c].y,
18 getpixel (Active, old_dirty.rect[c].x, old_dirty.rect[c].y));
19 }
20 else {
21 blit (Active, Visual, old_dirty.rect[c].x, old_dirty.rect[c].y,
22 old_dirty.rect[c].x, old_dirty.rect[c].y,
23 old_dirty.rect[c].w, old_dirty.rect[c].h);
24 }
25 }
26 release_bitmap (Visual);
27}

The problem I have is that the ball does dirty the screen when it bounces. If I change the blit by a rectfill in "mjCleanDirtyRectangle" then the ball doesn't dirty the screen when it bounces. Is something wrong in my code?

I'm using GNU/Linux (Debian) and I'm not tested it in Windows.

[edit] I've discovered that the ball only does dirty the screen when it bounces at "0" coordinate (that is, the border of screen). If it bounces inside the screen it doesn't dirty it. So, there's no problem at all. May be Matt or other moderator would delete this thread if it isn't a bug of Allegro or the Demo Game...

Thread #585764. Printed from Allegro.cc