feat: refresh on demand in menu (adaptive framerate)
This commit is contained in:
@@ -255,8 +255,8 @@ void Engine::updateFrontend() {
|
||||
gui->postAct();
|
||||
}
|
||||
|
||||
void Engine::nextFrame() {
|
||||
windowControl->nextFrame();
|
||||
void Engine::nextFrame(bool waitForRefresh) {
|
||||
windowControl->nextFrame(waitForRefresh);
|
||||
}
|
||||
|
||||
void Engine::startPauseLoop() {
|
||||
@@ -275,7 +275,7 @@ void Engine::startPauseLoop() {
|
||||
if (isHeadless()) {
|
||||
platform::sleep(1.0 / params.tps * 1000);
|
||||
} else {
|
||||
nextFrame();
|
||||
nextFrame(false);
|
||||
}
|
||||
}
|
||||
if (initialCursorLocked) {
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
void applicationTick();
|
||||
void updateFrontend();
|
||||
void renderFrame();
|
||||
void nextFrame();
|
||||
void nextFrame(bool waitForRefresh);
|
||||
void startPauseLoop();
|
||||
|
||||
/// @brief Set screen (scene).
|
||||
|
||||
@@ -45,7 +45,9 @@ void Mainloop::run() {
|
||||
engine.renderFrame();
|
||||
}
|
||||
engine.postUpdate();
|
||||
engine.nextFrame();
|
||||
engine.nextFrame(
|
||||
dynamic_cast<const MenuScreen*>(engine.getScreen().get()) != nullptr
|
||||
);
|
||||
}
|
||||
logger.info() << "main loop stopped";
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "window/input.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "graphics/core/ImageData.hpp"
|
||||
#include "util/platform.hpp"
|
||||
|
||||
static debug::Logger logger("window-control");
|
||||
|
||||
@@ -78,15 +79,19 @@ void WindowControl::toggleFullscreen() {
|
||||
}
|
||||
}
|
||||
|
||||
void WindowControl::nextFrame() {
|
||||
void WindowControl::nextFrame(bool waitForRefresh) {
|
||||
const auto& settings = engine.getSettings();
|
||||
auto& window = engine.getWindow();
|
||||
auto& input = engine.getInput();
|
||||
window.setFramerate(
|
||||
window.isIconified() && settings.display.limitFpsIconified.get()
|
||||
? 20
|
||||
: settings.display.framerate.get()
|
||||
);
|
||||
if (waitForRefresh) {
|
||||
window.setFramerate(Window::FPS_UNLIMITED);
|
||||
} else {
|
||||
window.setFramerate(
|
||||
window.isIconified() && settings.display.limitFpsIconified.get()
|
||||
? 20
|
||||
: settings.display.framerate.get()
|
||||
);
|
||||
}
|
||||
window.swapBuffers();
|
||||
input.pollEvents();
|
||||
input.pollEvents(waitForRefresh);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
|
||||
Result initialize();
|
||||
|
||||
void nextFrame();
|
||||
void nextFrame(bool waitForRefresh);
|
||||
|
||||
void saveScreenshot();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user