Improve mac fps limit

This commit is contained in:
halx99 2022-07-01 11:02:31 +08:00
parent 5f02d2a656
commit 6017f90907
1 changed files with 4 additions and 6 deletions

View File

@ -61,6 +61,8 @@ int Application::run()
std::chrono::steady_clock::time_point lastTime{};
constexpr std::chrono::nanoseconds _1ms{1000000};
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
@ -75,16 +77,12 @@ int Application::run()
glview->pollEvents();
auto interval = std::chrono::steady_clock::now() - lastTime;
if (interval < _animationInterval)
{
auto waitDuration = _animationInterval - interval;
auto waitDuration = _animationInterval - interval - _1ms;
if (waitDuration.count() > 0)
std::this_thread::sleep_for(waitDuration);
}
else
{
std::this_thread::yield();
}
}
/* Only work on Desktop
* Director::mainLoop is really one frame logic