impr: Try to improve framerate limiting once more
This commit is contained in:
parent
642722bdb1
commit
95da957f73
@ -186,12 +186,11 @@ namespace hex {
|
|||||||
// Determine if the application should be in long sleep mode
|
// Determine if the application should be in long sleep mode
|
||||||
bool shouldLongSleep = !m_unlockFrameRate;
|
bool shouldLongSleep = !m_unlockFrameRate;
|
||||||
|
|
||||||
// Wait 5 frames before actually enabling the long sleep mode to make animations not stutter
|
static double lockTimeout = 0;
|
||||||
static i32 lockTimeout = 0;
|
|
||||||
if (!shouldLongSleep) {
|
if (!shouldLongSleep) {
|
||||||
lockTimeout = m_lastFrameTime * 10'000;
|
lockTimeout = 0.05;
|
||||||
} else if (lockTimeout > 0) {
|
} else if (lockTimeout > 0) {
|
||||||
lockTimeout -= 1;
|
lockTimeout -= m_lastFrameTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldLongSleep && lockTimeout > 0)
|
if (shouldLongSleep && lockTimeout > 0)
|
||||||
@ -209,6 +208,7 @@ namespace hex {
|
|||||||
// Long sleep mode is enabled automatically after a few frames if the window content hasn't changed
|
// Long sleep mode is enabled automatically after a few frames if the window content hasn't changed
|
||||||
// and no events have been received
|
// and no events have been received
|
||||||
if (shouldLongSleep) {
|
if (shouldLongSleep) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
// Calculate the time until the next frame
|
// Calculate the time until the next frame
|
||||||
constexpr static auto LongSleepFPS = 5.0;
|
constexpr static auto LongSleepFPS = 5.0;
|
||||||
const double timeout = std::max(0.0, (1.0 / LongSleepFPS) - (glfwGetTime() - m_lastStartFrameTime));
|
const double timeout = std::max(0.0, (1.0 / LongSleepFPS) - (glfwGetTime() - m_lastStartFrameTime));
|
||||||
@ -244,6 +244,7 @@ namespace hex {
|
|||||||
} else {
|
} else {
|
||||||
if (!shouldLongSleep) {
|
if (!shouldLongSleep) {
|
||||||
glfwSwapInterval(0);
|
glfwSwapInterval(0);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
const auto frameTime = glfwGetTime() - m_lastStartFrameTime;
|
const auto frameTime = glfwGetTime() - m_lastStartFrameTime;
|
||||||
const auto targetFrameTime = 1.0 / targetFPS;
|
const auto targetFrameTime = 1.0 / targetFPS;
|
||||||
if (frameTime < targetFrameTime) {
|
if (frameTime < targetFrameTime) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user