log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- RISC OS London Show Report 2024 (News:1)
- Announcing the TIB 2024 Advent Calendar (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- RISCOSbits releases a new laptop solution (News:)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
- WROCC November 2024 talk o...ay - Andrew Rawnsley (ROD) (News:2)
- October 2024 News Summary (News:3)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
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
PhlamethrowerHot 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