From 6576872074f0c81b32572ac9609bcca8fcfd95cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 22 Jan 2025 16:02:03 +0100 Subject: [PATCH] Remove emscripten-only vsync fps limit type This was ill-designed: "vsync" should be a draw cap limit, if anything. We can't currently think of a way to allow both vsync and a different arbitrary fps limit without banishing the simulation to another thread, so this gets shelved now. --- src/FpsLimit.h | 6 ++---- src/PowderToySDL.cpp | 2 +- src/PowderToySDLEmscripten.cpp | 16 ++++++++-------- src/gui/game/GameView.cpp | 6 +----- src/lua/LuaMisc.cpp | 12 ++---------- 5 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/FpsLimit.h b/src/FpsLimit.h index 88f4e6fd8..cd821e3b2 100644 --- a/src/FpsLimit.h +++ b/src/FpsLimit.h @@ -1,9 +1,6 @@ #pragma once #include -struct FpsLimitVsync -{ -}; struct FpsLimitNone { }; @@ -11,7 +8,7 @@ struct FpsLimitExplicit { float value; }; -using FpsLimit = std::variant; +using FpsLimit = std::variant; struct DrawLimitDisplay { @@ -23,4 +20,5 @@ struct DrawLimitExplicit { int value; }; +// TODO: DrawLimitVsync using DrawLimit = std::variant; diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 1eb73912e..c3d4dc750 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -204,7 +204,7 @@ void SDLClose() void SDLSetScreen() { auto newFrameOps = ui::Engine::Ref().windowFrameOps; - auto newVsyncHint = std::holds_alternative(ui::Engine::Ref().GetFpsLimit()); + auto newVsyncHint = false; // TODO: DrawLimitVsync if (FORCE_WINDOW_FRAME_OPS == forceWindowFrameOpsEmbedded) { newFrameOps.resizable = false; diff --git a/src/PowderToySDLEmscripten.cpp b/src/PowderToySDLEmscripten.cpp index 42b84f504..4b52c0692 100644 --- a/src/PowderToySDLEmscripten.cpp +++ b/src/PowderToySDLEmscripten.cpp @@ -22,13 +22,13 @@ void SetFpsLimit(FpsLimit newFpsLimit) emscripten_set_main_loop(MainLoopBody, 0, 0); mainLoopSet = true; } - if (std::get_if(&newFpsLimit)) - { - emscripten_set_main_loop_timing(EM_TIMING_RAF, 1); - std::cerr << "implicit fps limit via vsync" << std::endl; - } - else - { + // if (std::get_if(&newFpsLimit)) // TODO: DrawLimitVsync + // { + // emscripten_set_main_loop_timing(EM_TIMING_RAF, 1); + // std::cerr << "implicit fps limit via vsync" << std::endl; + // } + // else + // { auto delay = 0; if (auto *fpsLimitExplicit = std::get_if(&newFpsLimit)) { @@ -36,7 +36,7 @@ void SetFpsLimit(FpsLimit newFpsLimit) } emscripten_set_main_loop_timing(EM_TIMING_SETTIMEOUT, delay); std::cerr << "explicit fps limit: " << delay << "ms delays" << std::endl; - } + // } } void UpdateFpsLimit() diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index a051b7149..b2c1a9bbf 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -2564,11 +2564,7 @@ void GameView::OnDraw() fpsInfo << "\nSimulation"; fpsInfo << "\n FPS cap: "; auto fpsLimit = ui::Engine::Ref().GetFpsLimit(); - if (std::holds_alternative(fpsLimit)) - { - fpsInfo << "vsync"; - } - else if (std::holds_alternative(fpsLimit)) + if (std::holds_alternative(fpsLimit)) { fpsInfo << "none"; } diff --git a/src/lua/LuaMisc.cpp b/src/lua/LuaMisc.cpp index a8f1b124b..1d5126edc 100644 --- a/src/lua/LuaMisc.cpp +++ b/src/lua/LuaMisc.cpp @@ -201,11 +201,7 @@ static int fpsCap(lua_State *L) if (acount == 0) { auto fpsLimit = ui::Engine::Ref().GetFpsLimit(); - if (std::holds_alternative(fpsLimit)) - { - lua_pushliteral(L, "vsync"); - } - else if (std::holds_alternative(fpsLimit)) + if (std::holds_alternative(fpsLimit)) { lua_pushnumber(L, 2); } @@ -215,11 +211,6 @@ static int fpsCap(lua_State *L) } return 1; } - if (lua_isstring(L, 1) && byteStringEqualsLiteral(tpt_lua_toByteString(L, 1), "vsync")) - { - ui::Engine::Ref().SetFpsLimit(FpsLimitVsync{}); - return 0; - } float fpscap = luaL_checknumber(L, 1); if (fpscap < 2) { @@ -254,6 +245,7 @@ static int drawCap(lua_State *L) } return 1; } + // if (lua_isstring(L, 1) && byteStringEqualsLiteral(tpt_lua_toByteString(L, 1), "vsync")) // TODO: DrawLimitVsync if (lua_isstring(L, 1) && byteStringEqualsLiteral(tpt_lua_toByteString(L, 1), "display")) { ui::Engine::Ref().SetDrawingFrequencyLimit(DrawLimitDisplay{});