mirror of https://github.com/axmolengine/axmol.git
Improve mac fps limit
This commit is contained in:
parent
5f02d2a656
commit
6017f90907
|
@ -60,6 +60,8 @@ int Application::run()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point lastTime{};
|
std::chrono::steady_clock::time_point lastTime{};
|
||||||
|
|
||||||
|
constexpr std::chrono::nanoseconds _1ms{1000000};
|
||||||
|
|
||||||
auto director = Director::getInstance();
|
auto director = Director::getInstance();
|
||||||
auto glview = director->getOpenGLView();
|
auto glview = director->getOpenGLView();
|
||||||
|
@ -75,15 +77,11 @@ int Application::run()
|
||||||
glview->pollEvents();
|
glview->pollEvents();
|
||||||
|
|
||||||
auto interval = std::chrono::steady_clock::now() - lastTime;
|
auto interval = std::chrono::steady_clock::now() - lastTime;
|
||||||
if (interval < _animationInterval)
|
auto waitDuration = _animationInterval - interval - _1ms;
|
||||||
{
|
if (waitDuration.count() > 0)
|
||||||
auto waitDuration = _animationInterval - interval;
|
|
||||||
std::this_thread::sleep_for(waitDuration);
|
std::this_thread::sleep_for(waitDuration);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only work on Desktop
|
/* Only work on Desktop
|
||||||
|
|
Loading…
Reference in New Issue