Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct handling of the explicitly passed delta time #19135

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions cocos/base/CCDirector.cpp
Expand Up @@ -335,25 +335,31 @@ void Director::drawScene()

void Director::calculateDeltaTime()
{
auto now = std::chrono::steady_clock::now();

// new delta time. Re-fixed issue #1277
if (_nextDeltaTimeZero)
{
_deltaTime = 0;
_nextDeltaTimeZero = false;
_lastUpdate = std::chrono::steady_clock::now();
}
else
{
// delta time may passed by invoke mainLoop(dt)
if (!_deltaTimePassedByCaller)
if (_deltaTimePassedByCaller)
{
_deltaTimePassedByCaller = false;
}
else
{
auto now = std::chrono::steady_clock::now();
_deltaTime = std::chrono::duration_cast<std::chrono::microseconds>(now - _lastUpdate).count() / 1000000.0f;
_lastUpdate = now;
}

_deltaTime = MAX(0, _deltaTime);
}

_lastUpdate = now;

#if COCOS2D_DEBUG
// If we are debugging our code, prevent big delta time
if (_deltaTime > 0.2f)
Expand Down