scrolling
William Labbett

Thanks for the help on the other topic. At the moment my background scrolls smoothly and at a good pace when the program first runs but after it's been running for a few seconds the scrolling slows right down and jerks.

case ALLEGRO_EVENT_TIMER:
        
              if(Top_BD.Waiting() == 0)
        {   
            Top_BD.Update_Position();
              }
      
        redraw = true;
        break;

I wanted to make sure the position of the backdrop gets updated once per clock tick so Update_Position sets a variable 'waiting' and doesn't update the position again until

Top_BD.Draw draws the bitmap and set 'waiting' back to 0.

Like I say, suddenly the scrolling slows right down and don't what's causing it.

Perhaps someone could see why ? Thanks.

#SelectExpand
1void *make_bitmap(ALLEGRO_THREAD *t, void *data); 2 3 4void Backdrop::Draw(void) 5{ 6 ALLEGRO_BITMAP *bb, *tb; 7 if(current_bottom_backdrop == 0) 8 { 9 10 bb = b1; 11 tb = b2; 12 } 13 else 14 { 15 16 bb = b2; 17 tb = b1; 18 } 19 20 al_draw_bitmap_region( bb, 0, 0, BACKDROP_WIDTH_IN_PIXELS, BACKDROP_HEIGHT_IN_PIXELS - draw_from, 40, draw_from - BACKDROP_HEIGHT_IN_PIXELS + 480, 0); 21 22 23 if(draw_from > BACKDROP_HEIGHT_IN_PIXELS - SCREEN_HEIGHT) 24 { 25 al_draw_bitmap_region( tb, 0, BACKDROP_HEIGHT_IN_PIXELS - (draw_from - (BACKDROP_HEIGHT_IN_PIXELS - SCREEN_HEIGHT)), 26 BACKDROP_WIDTH_IN_PIXELS, 27 (draw_from - (BACKDROP_HEIGHT_IN_PIXELS - SCREEN_HEIGHT)), 40, 0, 0); 28 29 } 30 31 waiting_to_be_drawn = 0; 32} 33 34 35 36void Backdrop::Update_Position(void) 37{ 38 draw_from += 2; 39 40 waiting_to_be_drawn = 1; 41 42 if(remake_a_bitmap == 1) 43 { 44 if(t) { 45 printf("joining.\n"); 46 //al_join_thread(t, NULL); 47 al_destroy_thread(t); 48 } 49 50 printf("creating thread.\n"); 51 52 t = al_create_thread(make_bitmap, this); 53 al_start_thread(t); 54 55 /* Set this back to 0 so that another thread doesn't get started until necessary */ 56 57 remake_a_bitmap = 0; 58 } 59 60 61 62 if(draw_from > BACKDROP_HEIGHT_IN_PIXELS) 63 { 64 /* Can't draw anymore of the current bottom backdrop so reset draw_from to 0 and start drawing the other bitmap. */ 65 66 draw_from = 0; 67 68 69 70 71 printf("switching bitmaps.\n"); 72 73 ++current_bottom_backdrop; 74 if(current_bottom_backdrop > 1) 75 { 76 current_bottom_backdrop = 0; 77 } 78 79 80 81 /* Set this to 0 to indicate to that the bitmap that's has scolled off the screen needs to be remade. */ 82 83 remake_a_bitmap = 1; 84 } 85} 86 87 88 89void Backdrop::Make_New_Blot() 90{ 91 printf("making new blot.\n"); 92 switch(current_bottom_backdrop) 93 { 94 case 1: 95 al_destroy_bitmap(b1); 96 b1 = dinkle_get_connecting_blot(BACKDROP_WIDTH_IN_TILES, BACKDROP_HEIGHT_IN_TILES, &ratios, b2_tiles, b1_tiles, bg_colors[0], bg_colors[1]); 97 break; 98 case 0: 99 al_destroy_bitmap(b2); 100 b2 = dinkle_get_connecting_blot(BACKDROP_WIDTH_IN_TILES, BACKDROP_HEIGHT_IN_TILES, &ratios, b1_tiles, b2_tiles, bg_colors[0], bg_colors[1]); 101 break; 102 } 103} 104 105 106 107 108 109void *make_bitmap(ALLEGRO_THREAD *t, void *data) 110{ 111 Backdrop *obj = (Backdrop *) data; 112 113 obj->Make_New_Blot(); 114 115 return NULL; 116}

Dizzy Egg

You're creating new bitmaps every time you call the Draw function...?

William Labbett

No, they're just pointers to ALLEGRO_BITMAPS.

That would have explained it.

EDIT : at the point when it slows right down, the memory usage goes from 4% to 40+%

:o - from which I conclude that the CPU gets busy which is why it's slowing.

EDIT 2

% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
25.00 0.03 0.03 dinkle_pixels_from_tiles
25.00 0.06 0.03 next_to_two_array_code
16.67 0.08 0.02 dinkle_make_monochrome_pattern
8.33 0.09 0.01 arrays_are_the_same
8.33 0.10 0.01 make_another_line
8.33 0.11 0.01 next_to_array_code
8.33 0.12 0.01 reflect_tile

Thread #608123. Printed from Allegro.cc