re: Per Frame/Timed "Update"?
re: Per Frame/Timed "Update"?
- Subject: re: Per Frame/Timed "Update"?
- From: George Warner <email@hidden>
- Date: Fri, 16 May 2008 08:08:54 -0700
- Thread-topic: Per Frame/Timed "Update"?
On Thu, 15 May 2008 17:38:49 -0700 (PDT), Clancy John Imislund
<email@hidden> wrote:
> Hi all,
>
> I have an App that needs to call an "Update()" function every 1/30th of a
second on certain objects (not just respond to asynch messages). Does anyone
know the proper XCode way to do this?
This is more of a Carbon/Cocoa API question; it really doesn't have anything
to do with Xcode. I'd suggest asking this on ether the Carbon or Cocoa dev
mailing lists.
That said there are different solutions depending on your criteria: If
you're doing animation the you may want to use core animation or QuickTime;
if you're doing simulation (physics?) you may want to use timers, etc. If
you're doing data acquisition you may need to use scheduled I/O, etc.
Brute force you could just write a loop:
for ( int idx = 0; idx < 600; idx++ ) {
Duration tDuration = kDurationMillisecond * 1000 / 30;
AbsoluteTime nextTime = AddDurationToAbsolute( tDuration, UpTime() );
Update();
MPDelayUntil( nextTime );
}
Note that we compute "nextTime" before calling Update; this prevents
Update's computational time from effecting the interval at which it's
called. If you use timers that are dispatched by a runloop then the interval
at which its handlers are dispatched can be effected by the runtimes of
other handlers called by that runloop (this is because the runloop timers
handlers won't be dispatched until control is returned to the runloop from
those other handlers).
--
Enjoy,
George Warner,
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden