Browse Source

Add "frameRateLimit" to settings.json

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
abea4f5967
3 changed files with 21 additions and 6 deletions
  1. +1
    -0
      include/settings.hpp
  2. +9
    -0
      src/settings.cpp
  3. +11
    -6
      src/window.cpp

+ 1
- 0
include/settings.hpp View File

@@ -18,6 +18,7 @@ extern bool powerMeter;
extern bool lockModules;
extern bool checkVersion;
extern bool skipLoadOnLaunch;
extern float frameRateLimit;


} // namespace settings


+ 9
- 0
src/settings.cpp View File

@@ -77,6 +77,9 @@ static json_t *settingsToJson() {
// paramTooltip
json_object_set_new(rootJ, "paramTooltip", json_boolean(paramTooltip));

// frameRateLimit
json_object_set_new(rootJ, "frameRateLimit", json_real(frameRateLimit));

return rootJ;
}

@@ -163,6 +166,11 @@ static void settingsFromJson(json_t *rootJ) {
json_t *paramTooltipJ = json_object_get(rootJ, "paramTooltip");
if (paramTooltipJ)
paramTooltip = json_boolean_value(paramTooltipJ);

// frameRateLimit
json_t *frameRateLimitJ = json_object_get(rootJ, "frameRateLimit");
if (frameRateLimitJ)
frameRateLimit = json_number_value(frameRateLimitJ);
}


@@ -208,6 +216,7 @@ bool powerMeter = false;
bool lockModules = false;
bool checkVersion = true;
bool skipLoadOnLaunch = false;
float frameRateLimit = 0.0;


} // namespace settings


+ 11
- 6
src/window.cpp View File

@@ -6,6 +6,7 @@
#include "event.hpp"
#include "app.hpp"
#include "patch.hpp"
#include "settings.hpp"

#include <map>
#include <queue>
@@ -221,6 +222,7 @@ Window::Window() {
glfwSetInputMode(win, GLFW_LOCK_KEY_MODS, 1);

glfwMakeContextCurrent(win);
// Enable v-sync
glfwSwapInterval(1);

glfwSetWindowSizeCallback(win, windowSizeCallback);
@@ -371,15 +373,18 @@ void Window::run() {
glfwSwapBuffers(win);
}

// Limit framerate manually if vsync isn't working
// Limit frame rate
double endTime = glfwGetTime();
double frameTime = endTime - startTime;
double minTime = 1 / 120.0;
if (frameTime < minTime) {
std::this_thread::sleep_for(std::chrono::duration<double>(minTime - frameTime));
if (settings::frameRateLimit > 0.0) {
double frameDuration = endTime - startTime;
double waitDuration = 1.0 / settings::frameRateLimit - frameDuration;
if (waitDuration > 0.0) {
std::this_thread::sleep_for(std::chrono::duration<double>(waitDuration));
}
}

// Compute actual frame rate
endTime = glfwGetTime();
// INFO("%lf fps", 1.0 / (endTime - startTime));
frame++;
}
}


Loading…
Cancel
Save