From 37272a5b9592952950858a0d1c0343efc1c203a5 Mon Sep 17 00:00:00 2001 From: Ayndpa Date: Wed, 19 Nov 2025 22:29:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B8=A7=E7=8E=87=E9=99=90?= =?UTF-8?q?=E5=88=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E7=AA=97=E5=8F=A3=E8=81=9A?= =?UTF-8?q?=E7=84=A6=E6=97=B6=E7=9A=84=E6=80=A7=E8=83=BD=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- online_game_tool.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/online_game_tool.cpp b/online_game_tool.cpp index eaa5615..9ec1d92 100644 --- a/online_game_tool.cpp +++ b/online_game_tool.cpp @@ -344,9 +344,26 @@ int main() } }; + // Frame rate limiting + const double targetFrameTimeForeground = 1.0 / 60.0; // 60 FPS when focused + const double targetFrameTimeBackground = 1.0; // 1 FPS when in background + double lastFrameTime = glfwGetTime(); + // Main loop while (!glfwWindowShouldClose(window)) { + // Frame rate control based on window focus + bool isFocused = glfwGetWindowAttrib(window, GLFW_FOCUSED); + double targetFrameTime = isFocused ? targetFrameTimeForeground : targetFrameTimeBackground; + + double currentTime = glfwGetTime(); + double deltaTime = currentTime - lastFrameTime; + if (deltaTime < targetFrameTime) + { + std::this_thread::sleep_for(std::chrono::duration(targetFrameTime - deltaTime)); + } + lastFrameTime = glfwGetTime(); + // Poll events glfwPollEvents();