Very not stable delta from update method CADisplayLink duration or timestamp not used for iOS?

I just created a new clean project and scheduleUpdate();

 void HelloWorld::update(float delta) {
    CCLOG("%f",delta);
 }

Result:

0.018591
0.015011
0.017311
0.015939
0.017793
0.015640
0.016709
0.016957
0.017268
0.015884
0.016776
0.016478
0.016699
0.018520

And the same setup but using cocos2d-iphone v3, so Objective C, gives me rock and solid output:

0.016720
0.016674
0.016676
0.016675
0.016675
0.016675
0.016707
0.016687
0.016672
0.016677
0.016632
0.016644

Why? Is this a bug? Or something more deeper? Please @zhangxm @zhangbin can you comment this? Also summoning @slackmoehrle for ping other developers of cocos2d-x :slight_smile:

@anon98020523 yep, it seems a problem compared to Objective C codes. What’s your engine version? Which platform did you test on?

@zhangxm for sure I’m using latest version for testing this, 3.15 and I love iOS, so I’m testing only on it, specially on iPhone 6 :slight_smile:

In cocos2d there was fixedUpdate too (for physics update, or just for more accurate timing).
Maybe it’s exits in cocos2d-x too, i don’t know.

My question is not about that. What I’m asking is just a difference in behaviour of standard update method, which I believe should be the same, stable, whatever what engine is used. But currently for cocos2d-x is very unstable.

@zhangxm So, is this a bug?
My game actually looks not so solid and nice for eyes(I have fast moving character) as it was on cocos2d-iphone. So quality is different, I really can see this on the device. So I’m very interested in stable update, because it’s obviously should be stable. Should I create an issue on github?

Sorry, i don’t have time to look into it. Indeed, stable update can not be expected as scene becomes more complex. As this issue, i think it may be treated as an issue, should optimize it.

My game is a bit heavy, on cocos2d-iphone it’s loads processor up to 40%, but update stable anyway, so 0.016 all the time. But I just tested this on simple HelloWorld project and got unstable delta.

So, this is 100% some trouble with cocos2d-x code. I will open issue about this.

upd: https://github.com/cocos2d/cocos2d-x/issues/17806

This is really important for me, I want to make a quality game… so everything should be smooth.

@zhangxm, I’ve found some info about that, not sure, probably this Cocos2d-x Windows performance issues examined

But definitely this: http://www.learn-cocos2d.com/2013/10/game-engine-multiply-delta-time-or-not/

Delta time may not be exactly 0.0166…
If you log the delta time of a cocos2d-iphone game running at 60 fps you get fluctuating values like these:

deltaTime = 0.016574
deltaTime = 0.017026
deltaTime = 0.016425
deltaTime = 0.016939
deltaTime = 0.016299
deltaTime = 0.016665
deltaTime = 0.017033
deltaTime = 0.016618

> This is a particular issue with cocos2d because it does not use the CADisplayLink duration property. Instead it relies on system timers to calculate the time difference. As a result, cocos2d’s delta time is merely an approximation and ever-so-slightly disconnected from the actual refresh rate.

So, as I see, this was fixed since that time for cocos2d-iphone v3, but currently a problem for cocos2d-x.

Upd:
Here is how it works for cocos2d-iphone

I believe this should be same for cocos2d-x?

I added some comment at the github issue.
Thanks @anon98020523.

@zhangxm Yes, me too. Actually this is a huge problem, not using VSYNC for iOS gives me shutter frames sometimes, and I can’t fix this anyway. All code in that issue and it works well for cocos2d-iphone v3.

@zhangxm so any ideas when this will be fixed? Also, why this was made that way, so with loosing quality for iOS? It’s just easy to create solution for each platform.

@anon98020523 sorry, i am busy with this issue: https://github.com/cocos2d/cocos2d-x/issues/17480#issuecomment-299401693. I may finish it today and take a look at this issue.

1 Like

@anon98020523 yep, i think cocos2d-x should modify like that. But it is not convenient using Objective-c codes in CCDirector.cpp, i will think more about it.

@zhangxm well, CCDirector.cpp can’t be with Objc, it’s shod be cross-platform class like CCDirector-iOS.mm and “overload” method calculate delta…

Yep, it may work.