Acorn Arcade forums: Programming: Constant frame rate delay
|
Constant frame rate delay |
|
Michael Foot (21:55 25/10/2005) Phlamethrower (21:59 1/11/2005)
|
|
Michael Foot |
Message #86426, posted by Michael Foot at 21:55, 25/10/2005 |
AA refugee
Posts: 25
|
Currently to keep a constant frame rate for my single tasking programs I use the following code: #define TIME_50HZ 2 while (!lquit) { nclock = clock()+TIME_50HZ; /*do some stuff*/ while (clock() < nclock) { } } I'm assuming the tight loop is maxing out the CPU until (clock() >= nclock) and as such is probably not a good way to do it. I'm using Norcroft 'C' and was wondering if there is a better way to do this? Is there a sleep() function or similar that is less taxing on the CPU? Thanks, Mike. |
|
[ Log in to reply ] |
|
Jeffrey Lee |
Message #86427, posted by Phlamethrower at 21:59, 1/11/2005, in reply to message #86426 |
Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff
Posts: 15100
|
If the current monitor refresh rate is the same as the timing you want on your program, then you could use OS_Byte 19 to wait for the VSync signal. Failing that, I think that in a single tasking environment just waiting in a tight loop is the only way to go. Any IRQ events etc. can still run their course during that tight loop, so you're not really keeping the CPU from being used for other things. |
|
[ Log in to reply ] |
|
|
Acorn Arcade forums: Programming: Constant frame rate delay |