Frustration abound…

April 12th, 2007 by jamyskis

Progress on Open Invaders has ground to a halt simply because the Allegro library is causing me so many headaches I am seriously considering moving over to SDL. While I have solved the problem of the 100% CPU usage, it hasn’t solved the problem of the choppy performance and the game is still using up to around 90-95% of the CPU with 50% just through the double buffering.

I’ve brought this problem to the attention of the crew at allegro.cc, and I’ve followed their suggestions, including profiling my program, but the profile results don’t make any sense whatsoever. OK, I struggled to make head or tail of the profiling results, but what I did understand did not appear logical at all.

Apparently, according to gprof (the profiler) the collision detection library that I’ve been using, PMASK, is eating up 81.5% of the processing time. Yet, when I completely comment out the collision detection routines out of the code, it makes absolutely no difference to performance. However, when I comment out a single line of code - blit(display,screen,0,0,0,0,800,600); - CPU usage drops to around 40-45%. This line of code is responsible for copying everything that is written to the graphics backbuffer to the display. Obviously, leaving this out isn’t an option, but the game runs rather well performance-wise without it.

Now, I know that Allegro doesn’t have hardware accelerated graphics under Linux, but an Athlon 2400 should be able to manage a simple game of Space Invaders without coming to a halt like this. I can optimise the code and probably find ways of dropping the CPU usage about 5% in the rest of the graphics code, but there’s no easy way around that one line there. This has been a bugbear for me for the past four months and I am just about ready to ditch the project altogether and start doing something else in SDL.

If anyone does have a suggestion why this is happening, or is willing to take a look at the code, please drop me a line and we can sort something out.

Posted in Linux, Personal, Development, Open Invaders |

2 Responses

  1. Astrochicken Says:

    Your game might be running at the maximum frame rate. You might try limiting it to 30 or 60 frames per second by using a delay function in your main loop.

    If the main loop runs unrestricted, it may blit the same stuff to the screen a hundred times before anything actually changes on the screen.

  2. Astrochicken Says:

    Also, you might want to blit on those rectangles of the screen that have changed.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.