0

Its my first post . Any mistake , please bear with me .

I am new to iPhone development . I was using CADisplayLink to execute "Update" loop of my game . In XCode 8.2 I am using following code to calculate deltaTime between two consecutive frames .

Inside my AppDelegate.mm file

{
    mDisplayLink = [CADisplayLink displayLinkWithTarget: self selector:@selector(gameLoop)];
    mDisplayLink.preferredFramesPerSecond = 60 ;
    [mDisplayLink addToRunLoop :[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}

Inside my gameLoop() function

{
    if (mDisplayLink==NULL) return;
    mApp->CoreLoopUpdate((double)mDisplayLink.timestamp );
}

Inside my CoreLoopUpdate( double timeStamp) function

{

     mDeltaTime = timestamp - mLastTimeStamp ;

     if( mGame->IsInitialized() )
     {
          Update( mDeltaTime );
          PreRender( mDeltaTime );
          Render( mDeltaTime );
      }

      mLastTimeStamp = timestamp ;

     std::cout<<"\nFPS : " << 1.0/mDeltaTime ;

} 

It was printing correct fps ( 29 - 30 ) in my old system ( mac book pro , OS - Yosemite , XCode 7.1 ). When I upgraded my system (OS - Sierra , XCode - 8.2 ) , the value is not proper . It varies drastically between ( 2 fps to 30 fps ) which spoils my game play .

I have also implemented a variation to my deltaTime calculation according to http://www.gamasutra.com/blogs/KwasiMensah/20110211/88949/Game_Loops_on_IOS.php#note9 . But it did not solve the issue .

Any suggestion will be helpful .

1 Answers1

3

From your post, it seems that you are trying your app in the simulator. Does it do the same on a real device? CADisplayLink works better on devices than on simulator. Another thing: if you want to be synchronized with the display frame rate, you should remove that line:

    mDisplayLink.preferredFramesPerSecond = 60 ;

Finally, you may want to check your Update/PreRender/Render code. If it takes too much time to process, you will skip frames.

Beg2k1
  • 61
  • 5
  • 1
    Sorry , I was out of station for 2 weeks . Thanks a lot for your help . As per your feed back , I checked it on device . It works fine . Thanks a lot again . – Ashish Tosh Mar 27 '17 at 07:50