Cocoa system time?
Im trying to calculate frame rate in cocoa. Is there a good function for getting the system time in cocoa?
Im just learning the Cocoa API's. Sorry if this is a stupid question.. since im sure the answer is silly obvious.
thx
Im just learning the Cocoa API's. Sorry if this is a stupid question.. since im sure the answer is silly obvious.
thx
You'll have to use the following Carbon function: CFAbsoluteTimeGetCurrent() (which returns a value in seconds).
You could also use [NSDate date] but I don't think that's a good decision.
You could also use [NSDate date] but I don't think that's a good decision.
"When you dream, there are no rules..."
+[NSDate timeIntervalSinceReferenceDate]
it returns a double, which is "seconds since 1970", but accurate to a few microseconds.
it returns a double, which is "seconds since 1970", but accurate to a few microseconds.
I do it like this sometimes:
[SOURCECODE]
- (void)setupRenderTimer
{
NSTimeInterval timeInterval = 0.01f;
renderTimer = [ [ NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector( animate ) userInfo:nil repeats:YES ] retain ];
[ [ NSRunLoop currentRunLoop ] addTimer:renderTimer forMode:NSEventTrackingRunLoopMode ];
[ [ NSRunLoop currentRunLoop ] addTimer:renderTimer forMode:NSModalPanelRunLoopMode ];
worldTime = [NSDate timeIntervalSinceReferenceDate];
}
- (void)animate
{
animate([NSDate timeIntervalSinceReferenceDate]-worldTime);
worldTime = [NSDate timeIntervalSinceReferenceDate];
}
[/SOURCECODE]
[SOURCECODE]
- (void)setupRenderTimer
{
NSTimeInterval timeInterval = 0.01f;
renderTimer = [ [ NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector( animate ) userInfo:nil repeats:YES ] retain ];
[ [ NSRunLoop currentRunLoop ] addTimer:renderTimer forMode:NSEventTrackingRunLoopMode ];
[ [ NSRunLoop currentRunLoop ] addTimer:renderTimer forMode:NSModalPanelRunLoopMode ];
worldTime = [NSDate timeIntervalSinceReferenceDate];
}
- (void)animate
{
animate([NSDate timeIntervalSinceReferenceDate]-worldTime);
worldTime = [NSDate timeIntervalSinceReferenceDate];
}
[/SOURCECODE]
Sir, e^iπ + 1 = 0, hence God exists; reply!
Thanks everyone.
I implemented it like this:
I store CFAbsoluteTime oldTime (as global data).
-(void) initGL:
oldTime = CFAbsoluteTimeGetCurrent();
- (void) drawRect: (NSRect)rect:
CFAbsoluteTime newTime = CFAbsoluteTimeGetCurrent();
double frameRate = 1.0/((double)newTime - (double)oldTime);
oldTime = newTime;
// then I print out the frameRate value to the screen
does this make sense?
Of course this is using the carbon libraries in a cocoa app. Hopefully apple wont depreciate carbon anytime soon. =)
I implemented it like this:
I store CFAbsoluteTime oldTime (as global data).
-(void) initGL:
oldTime = CFAbsoluteTimeGetCurrent();
- (void) drawRect: (NSRect)rect:
CFAbsoluteTime newTime = CFAbsoluteTimeGetCurrent();
double frameRate = 1.0/((double)newTime - (double)oldTime);
oldTime = newTime;
// then I print out the frameRate value to the screen
does this make sense?
Of course this is using the carbon libraries in a cocoa app. Hopefully apple wont depreciate carbon anytime soon. =)
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Getting the system time? | tobin | 3 | 2,368 |
Feb 26, 2008 01:23 PM Last Post: Frank C. |
|
| Getting system time | Fenris | 2 | 2,570 |
Apr 25, 2005 07:31 PM Last Post: Puzzler183 |
|

