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

@ -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