At 5:32 PM -0400 8/31/05, Richard wrote:
My timer code copies a small picture to a canvas, adds some graphics
to it, the draws it into my main window. The timer is set to repeat
at 16mSec. I snatch the Microseconds count at the start and the end
of the code, and use that to display the elapsed time inside the
code and outside. The execution time of the code averages around
4mSec and the delay between executions is around 27mSec. Why isn't
the total cycle time close to my 16mSec period that I set?
16 msec is the system "heartbeat" -- the maximum speed at which the
main event loop can fire. If you want your timer to fire every time
through the main event loop, you shouldn't set it right to this
frequency, as that's just asking for trouble (such as it skipping one
beat because you came in just over the wire, so to speak -- or
"missed it by *that* much", as Max Smart would say). Set it to 1
msec instead, and then it will fire as fast as it can, which will
often be 16 msec apart, though sometimes not, depending on what else
is going on.
2nd question. Running this on Windows I get 0mSec execution time and
31mSec between executions. Changing my timer period to 15mSec and I
get 0mSec execution time and 16mSec between. Looks like the timer
resolution on Windows is 16mSec.
I thought it was actually 10 mSec on Windows, but I could believe 16.
Either way, set your timer to something lower and you'll get more
reliably results.
(This has the effect on Windows of my animation running fast, or
slow, with no in-between.)
Your animation shouldn't depend on the exact frame rate. Instead,
just measure how long it's been since the last frame, and move your
objects accordingly. Then the speed will look constant despite small
variations on the exact firing time.
Best,
- Joe
--
Joe Strout REAL Software, Inc.
Vote for REALbasic (twice!) in the LinuxWorld Reader's Choice Awards:
http://linux.sys-con.com/general/readerschoice.htm
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|