High cpu usage

I put together a test program that just bounces 2 sprites around in a
window. They bounce off each other and off the sides of the window, and
it has a simple gravity caclulation. It has a collsion response function
that is fairly sophisticated but only runs when there is indeed a
collision, and my collision detection algorithm is linear and very
efficient.

However, my CPU usage is always in the 80-90% range when the program is
running. I had some of my calculations as floating point operations, and
I converted them to use all integer ops where possible, and that seems to
have increased my framerate from 50fps to 75fps or so, but no reduction in
CPU load. Is this normal behavior? Could this be caused by the blitting?
I do a SDL_DisplayFormat() on the sprites after loading them so I assume
its not because SDL has to convert the images each blit. If anyone is
interested in seeing the code I put a tarball at
http://meatloop.andover.net/~count/bounce-051801.tar.gz. Thanks :slight_smile:
dave—

Vanity. Definitely my favorite sin.

I converted them to use all integer ops where possible, and that seems to
have increased my framerate from 50fps to 75fps or so, but no reduction in
CPU load. Is this normal behavior?

Well I’m no expert, but yes, I’d say it’s normal.

while(1) {
/* do nothing */
}

will also use your push your CPU to the max. By changing the code in the
middle (e.g. from floating point ops to integer ops), all you could ever
hope to achieve is higher framerates. If you’re concerned about hogging
the box, add an SDL_Delay(10).

Make sense :)?

DaveOn Fri, 18 May 2001, Dave wrote:

David MacCormack
@David_MacCormack