PDA

View Full Version : Game loop



Chunwah
11-03-2004, 09:03 AM
Hi im new in making games. I am wondering how I can make a fast game loop. I need to set the interval to 5 or 10. When i do this with a Timer it doesnt run as fast as that.

Every time i try something it results in a 100% cpu usage.

Does anyone know a good gameloop then can handle 5ms interval

TheLion
11-03-2004, 09:21 AM
Make a GameLoop like the one you used that hogged the CPU and add a Sleep(1), this will take some load of the CPU.

It depends on how I start with my games what kind of gameloop that I use... sometimes I use the OnIdle event loop, which is pretty fast and used by a lot of commercial games and sometimes I just use an "endless" loop that will loop until a flag is set to false.

Normally a doesn't suck up to 100% CPU but around 50% CPU which isn't too bad for a game, however if your loop sucks up 100% add a sleep at the end (about 1 ms), that should take some load off... in your case a bigger sleep time might also work and might take more load off the CPU. :)

P.S. If you want to know how to do a OnIdle event-loop check out my Canvas tutorial, it explains how to do an OnIdle event-loop:

http://terraqueous.f2o.org/dgdev/viewtopic.php?t=199