Browse Source

Rename and negate Window::getFrameTimeOverdue() to getFrameDurationRemaining().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
44568cd617
3 changed files with 8 additions and 13 deletions
  1. +1
    -1
      include/Window.hpp
  2. +6
    -11
      src/Window.cpp
  3. +1
    -1
      src/widget/FramebufferWidget.cpp

+ 1
- 1
include/Window.hpp View File

@@ -84,7 +84,7 @@ struct Window {
double getMonitorRefreshRate();
double getFrameTime();
double getLastFrameDuration();
double getFrameTimeOverdue();
double getFrameDurationRemaining();

std::shared_ptr<Font> loadFont(const std::string& filename);
std::shared_ptr<Image> loadImage(const std::string& filename);


+ 6
- 11
src/Window.cpp View File

@@ -485,13 +485,9 @@ void Window::step() {
glfwSwapBuffers(win);

// On some platforms, glfwSwapBuffers() doesn't wait on monitor refresh, so we have to sleep as a fallback.
if (internal->frameSwapInterval > 0) {
double frameDurationExpected = internal->frameSwapInterval / internal->monitorRefreshRate * 0.90;
double swapBuffersTime = system::getTime();
double frameDurationRemaining = frameDurationExpected - (swapBuffersTime - frameTime);
if (frameDurationRemaining > 0.0) {
std::this_thread::sleep_for(std::chrono::duration<double>(frameDurationRemaining));
}
double frameDurationRemaining = getFrameDurationRemaining();
if (frameDurationRemaining > 0.0) {
std::this_thread::sleep_for(std::chrono::duration<double>(frameDurationRemaining));
}

t5 = system::getTime();
@@ -666,10 +662,9 @@ double Window::getLastFrameDuration() {
}


double Window::getFrameTimeOverdue() {
double desiredFrameDuration = internal->frameSwapInterval / internal->monitorRefreshRate;
double frameDuration = system::getTime() - internal->frameTime;
return frameDuration - desiredFrameDuration;
double Window::getFrameDurationRemaining() {
double frameDurationDesired = internal->frameSwapInterval / internal->monitorRefreshRate;
return frameDurationDesired - (system::getTime() - internal->frameTime);
}




+ 1
- 1
src/widget/FramebufferWidget.cpp View File

@@ -114,7 +114,7 @@ void FramebufferWidget::draw(const DrawArgs& args) {
}

// It's more important to not lag the frame than to draw the framebuffer
if (dirty && APP->window->getFrameTimeOverdue() < 0.0) {
if (dirty && APP->window->getFrameDurationRemaining() > 0.0) {
render(scale, offsetF);
}



Loading…
Cancel
Save