Browse Source

Replace "frameRateLimit" and "frameRateSync" in settings with "frameSwapInterval".

tags/v1.1.5
Andrew Belt 4 years ago
parent
commit
e631131aea
4 changed files with 27 additions and 32 deletions
  1. +1
    -2
      include/settings.hpp
  2. +5
    -0
      src/app/Scene.cpp
  3. +5
    -12
      src/settings.cpp
  4. +16
    -18
      src/window.cpp

+ 1
- 2
include/settings.hpp View File

@@ -34,8 +34,7 @@ extern int threadCount;
extern bool paramTooltip;
extern bool cpuMeter;
extern bool lockModules;
extern float frameRateLimit;
extern bool frameRateSync;
extern int frameSwapInterval;
extern float autosavePeriod;
extern bool skipLoadOnLaunch;
extern std::string patchPath;


+ 5
- 0
src/app/Scene.cpp View File

@@ -56,6 +56,11 @@ void Scene::step() {

void Scene::draw(const DrawArgs& args) {
Widget::draw(args);

// nvgBeginPath(args.vg);
// nvgRect(args.vg, 0, 0, box.size.x, box.size.y);
// nvgFillColor(args.vg, color::mult(color::WHITE, APP->window->frame % 2));
// nvgFill(args.vg);
}

void Scene::onHoverKey(const event::HoverKey& e) {


+ 5
- 12
src/settings.cpp View File

@@ -29,8 +29,7 @@ int threadCount = 1;
bool paramTooltip = false;
bool cpuMeter = false;
bool lockModules = false;
float frameRateLimit = 70.0;
bool frameRateSync = true;
int frameSwapInterval = 1;
float autosavePeriod = 15.0;
bool skipLoadOnLaunch = false;
std::string patchPath;
@@ -75,9 +74,7 @@ json_t* toJson() {

json_object_set_new(rootJ, "lockModules", json_boolean(lockModules));

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

json_object_set_new(rootJ, "frameRateSync", json_boolean(frameRateSync));
json_object_set_new(rootJ, "frameSwapInterval", json_integer(frameSwapInterval));

json_object_set_new(rootJ, "autosavePeriod", json_real(autosavePeriod));

@@ -160,13 +157,9 @@ void fromJson(json_t* rootJ) {
if (lockModulesJ)
lockModules = json_boolean_value(lockModulesJ);

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

json_t* frameRateSyncJ = json_object_get(rootJ, "frameRateSync");
if (frameRateSyncJ)
frameRateSync = json_boolean_value(frameRateSyncJ);
json_t* frameSwapIntervalJ = json_object_get(rootJ, "frameSwapInterval");
if (frameSwapIntervalJ)
frameSwapInterval = json_integer_value(frameSwapIntervalJ);

json_t* autosavePeriodJ = json_object_get(rootJ, "autosavePeriod");
if (autosavePeriodJ)


+ 16
- 18
src/window.cpp View File

@@ -95,6 +95,7 @@ struct Window::Internal {
int lastWindowHeight = 0;

bool ignoreNextMouseDelta = false;
int frameSwapInterval = -1;
};


@@ -248,8 +249,7 @@ Window::Window() {
glfwSetInputMode(win, GLFW_LOCK_KEY_MODS, 1);

glfwMakeContextCurrent(win);
// Enable v-sync
glfwSwapInterval(settings::frameRateSync ? 1 : 0);
glfwSwapInterval(1);

// Set window callbacks
glfwSetWindowSizeCallback(win, windowSizeCallback);
@@ -333,8 +333,14 @@ void Window::run() {

// Poll events
glfwPollEvents();
// In case glfwPollEvents() set another OpenGL context

// In case glfwPollEvents() sets another OpenGL context
glfwMakeContextCurrent(win);
if (settings::frameSwapInterval != internal->frameSwapInterval) {
internal->frameSwapInterval = settings::frameSwapInterval;
glfwSwapInterval(settings::frameSwapInterval);
}

// Call cursorPosCallback every frame, not just when the mouse moves
{
double xpos, ypos;
@@ -396,23 +402,13 @@ void Window::run() {
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
nvgEndFrame(vg);

glfwSwapBuffers(win);
}

// Limit frame rate
double frameTimeEnd = glfwGetTime();
if (settings::frameRateLimit > 0.0) {
double frameDuration = frameTimeEnd - frameTimeStart;
double waitDuration = 1.0 / settings::frameRateLimit - frameDuration;
if (waitDuration > 0.0) {
std::this_thread::sleep_for(std::chrono::duration<double>(waitDuration));
}
}
glfwSwapBuffers(win);

// Compute actual frame rate
frameTimeEnd = glfwGetTime();
// DEBUG("%g fps", 1 / (endTime - startTime));
double frameTimeEnd = glfwGetTime();
DEBUG("%g fps", 1 / (frameTimeEnd - frameTimeStart));
frame++;
}
}
@@ -523,10 +519,12 @@ bool Window::isFullScreen() {
}

bool Window::isFrameOverdue() {
if (settings::frameRateLimit == 0.0)
if (settings::frameSwapInterval == 0)
return false;
double frameDuration = glfwGetTime() - frameTimeStart;
return frameDuration > 1.0 / settings::frameRateLimit;
// This is fudged a bit because it assumes the monitor refresh rate is 60 Hz.
double frameDeadline = settings::frameSwapInterval / 60.0;
return frameDuration > frameDeadline;
}

std::shared_ptr<Font> Window::loadFont(const std::string& filename) {


Loading…
Cancel
Save