100% CPU use

Blitz3D Forums/Blitz3D Beginners Area/100% CPU use

sequoia(Posted 2004) [#1]
I just recently noticed that the main game loop that displays the graphics and makes updates, cranks the CPU
use up to 100% which is logical, but I don't want it to run
at 100%. I lowered the speed of the loop by using something like:
a=createtimer(27)
while not keyhit(1)
waittimer (a)
wend

This works, but I still somehow get about 60%-80% CPU usage
but don't want to slow it down further because I don't want the FPS to drop below 27.

Any idea if it is possible to reduce CPU usage any further
without slowing the FPS or loop speed down with it?


thanks


WolRon(Posted 2004) [#2]
You must be using Blitz3D. It likes to do that.


Zethrax(Posted 2004) [#3]
Just stick a Delay(1) in your main loop to give Windows some breathing room.

For most games you will want to let the game hog most of the CPU cycles.

For aplication programs use Delay(20) when you don't need to update the CPU intensive parts (rendering, collisions, picking, etc, and Delay(1) when you do. Use a global variable as a flag to control which gets used and whether the CPU intensive routines are run. This should bring your idle time CPU usage down to below 0.5%.


sequoia(Posted 2004) [#4]
I tried a delay(1) before that too, which worked fine on a loop that didn't draw any graphics. It reduced it to about 5% (from 100%). When I do the same thing in the main loop however, it went down to 97% which I thought is still way too high. I tried several different things and the waittimer
function seems to be working the best so far.
I guess 70% is the best I can get out of it then.

thanks


Zethrax(Posted 2004) [#5]
If your program draws graphics then it's naturally going to use more of the CPU than if it didn't draw any.