slow graphics, but move fast when window is moved
peter walker

Hi everyone, I was hoping someone could help me.

I am finding that my graphics routine is running slow. I converted my code from VC++ Windows GDI to Allegro and I am finding that there is a significant decrease in the speed in which the graphics is being updated on the screen. A snippet of my code is below. All it does is create a window and place 3 circles in the window and updates the location of those objects via the Update() function.

The really strange thing is that if I move the window created by Allegro i.e. the window inwhich all the graphics is being displayed, the graphics move much faster.

Would anyone know what is going on?

Cheers,
voirin

----------------------------------

1Object * member = new Object[numberOfObjects];
2 
3void moveCircle(){
4
5 {... other routines}
6 
7 for ( int i = 0; i < numberOfObjects; i++ )
8 {
9 member<i>.Update( );
10 member<i>.Draw(screen); // draws circle (screen, x, y, r, color);
11 }
12}
13 
14 
15int main(){
16 
17 member[0] = Object(0,0);
18 member[1] = Object(10,10);
19 member[2] = Object(20,-15);
20 
21 allegro_init();
22 install_keyboard();
23 set_color_depth(8);
24 set_gfx_mode( GFX_AUTODETECT_WINDOWED, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
25 
26 while( !key[KEY_ESC]){
27 moveCircles();
28 }
29
30 return 0;
31}
32END_OF_MAIN();

mEmO

You should use the desktop color depth, use desktop_color_depth() to get it.

Archon

You should control the execution speed of your program with rests.

gnolam

... no. No you shouldn't. Use proper timing. Not rest(). :P

Neil Walker

That code suggests you're drawing everything directly to the screen. Use a backbuffer instead, e.g.

BITMAP* double=NULL;

... somewhere in initialisation...
double=create_bitmap(SCREEN_W,SCREEN_H);
void moveCircle(){
       

        {... other routines}
        clear(double);
  for ( int i = 0; i < numberOfObjects; i++ )
  {
    member<i>.Update( );
    member<i>.Draw(double); // draws circle (screen, x, y, r, color);
  } 
        blit(double, screen, etc, etc);

peter walker

Thanks for the replies everyone. I'll incorporate the suggestions into my code and see how well it executes. Im away from my code till monday.

I want the graphics to run as fast as possible. That is my primary aim - fast object movement - no rest or pauses in the program.

Thanks again
cheers, voirin

Kris Asick
Quote:

You should control the execution speed of your program with rests.

Quote:

... no. No you shouldn't. Use proper timing. Not rest().

Actually, you're both right. Proper timing should be implemented using Allegro's timer system or the Windows High Performance Timer, but you should also add a rest(0) or Sleep(0) to the end of a program loop so that CPU time can be properly given to Allegro's other threads and to other programs running in the background.

Also, if the application runs faster while you're moving the window than when not you might want to disable your background applications and see if one of them is eating up the resources your application wants.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Audric
peter walker said:

I want the graphics to run as fast as possible. That is my primary aim - fast object movement - no rest or pauses in the program.

OK for the idea of "timing your drawing code", but don't dismiss rest(0).

If you don't explicitely yield to Windows when it's the best moment to do so, Windows WILL suspend your program at random moments, and it will cause an extra waste of time every time it's in the middle of a sensitive operation - like a screen redraw, with locked DirecX surfaces.

Neil Black

[n00b question] I've asked here before, but I still don't know how to use proper timing instead of rest() I'll probalby just go look it up in the manual though, so don't worry.[/n00b question]

Goalie Ca

Aah.. time to spread the love of the wiki: http://wiki.allegro.cc/Timers
And instead of rest() i recommend my semaphore solution. Of course you can call other semaphore functions to implement all of the regular volatile int models if you so need for your un-lagger or whatever.

note: as a community we really should post all answers to common (and not so common) questions on the wiki and points users to that.

Thread #591181. Printed from Allegro.cc