mirror of https://github.com/axmolengine/axmol.git
fix invalid dt at start on iOS release mode (#18041)
This commit is contained in:
parent
74a6fd3293
commit
e7c69e253a
|
@ -26,6 +26,8 @@
|
|||
#include "platform/CCPlatformConfig.h"
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
#import "platform/ios/CCDirectorCaller-ios.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
@ -51,7 +53,7 @@ static id s_sharedDirectorCaller;
|
|||
{
|
||||
if (s_sharedDirectorCaller == nil)
|
||||
{
|
||||
s_sharedDirectorCaller = [CCDirectorCaller new];
|
||||
s_sharedDirectorCaller = [[CCDirectorCaller alloc] init];
|
||||
}
|
||||
|
||||
return s_sharedDirectorCaller;
|
||||
|
@ -64,20 +66,17 @@ static id s_sharedDirectorCaller;
|
|||
s_sharedDirectorCaller = nil;
|
||||
}
|
||||
|
||||
-(void) alloc
|
||||
{
|
||||
interval = 1;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
if (self = [super init])
|
||||
{
|
||||
isAppActive = [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc addObserver:self selector:@selector(appDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
|
||||
[nc addObserver:self selector:@selector(appDidBecomeInactive) name:UIApplicationWillResignActiveNotification object:nil];
|
||||
|
||||
self.interval = 1;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -104,6 +103,10 @@ static id s_sharedDirectorCaller;
|
|||
// Director::setAnimationInterval() is called, we should invalidate it first
|
||||
[self stopMainLoop];
|
||||
|
||||
// initialize initLastDisplayTime, or the dt of of first frame is invalid
|
||||
// should init before start displayLink
|
||||
[self initLastDisplayTime];
|
||||
|
||||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
||||
[displayLink setFrameInterval: self.interval];
|
||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
|
@ -143,6 +146,16 @@ static id s_sharedDirectorCaller;
|
|||
}
|
||||
}
|
||||
|
||||
-(void)initLastDisplayTime
|
||||
{
|
||||
struct mach_timebase_info timeBaseInfo;
|
||||
mach_timebase_info(&timeBaseInfo);
|
||||
CGFloat clockFrequency = (CGFloat)timeBaseInfo.denom / (CGFloat)timeBaseInfo.numer;
|
||||
clockFrequency *= 1000000000.0;
|
||||
// convert absolute time to seconds and should minus one frame time interval
|
||||
lastDisplayTime = (mach_absolute_time() / clockFrequency) - ((1.0 / 60) * self.interval);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||
|
|
Loading…
Reference in New Issue