From d3566a857c630c1c6e1d447bf518670e14718a26 Mon Sep 17 00:00:00 2001 From: CodingJellyfish Date: Sat, 19 Oct 2024 18:10:01 +0800 Subject: [PATCH] Prevent mx fps write in command line benchmarking --- src/main.cpp | 1 - src/main_loop.cpp | 45 ++++++++++++++++++++------------------ src/network/child_loop.cpp | 2 ++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 69972c816bb..9d143f78884 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1713,7 +1713,6 @@ int handleCmdLine(bool has_server_config, bool has_parent_process) { Log::verbose("main", "Benchmark mode requested from command-line"); UserConfigParams::m_no_start_screen = true; - UserConfigParams::m_max_fps = 9999; UserConfigParams::m_benchmark = true; } // --benchmark diff --git a/src/main_loop.cpp b/src/main_loop.cpp index af30f8e0d12..8a06c869b16 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -708,28 +708,31 @@ void MainLoop::run() } } - TimePoint frame_end = std::chrono::steady_clock::now(); - double frame_time = convertToTime(frame_end, frame_start) * 0.001; - const double current_fps = 1.0 / frame_time; - const double max_fps = - (irr_driver->isRecording() && UserConfigParams::m_limit_game_fps) ? - UserConfigParams::m_record_fps : UserConfigParams::m_max_fps; - - // Throttle fps if more than maximum, which can reduce - // the noise the fan on a graphics card makes. - // No need to throttle if vsync is on (m_swap_interval == 1) as - // endScene handles fps according to monitor refresh rate - if ((UserConfigParams::m_swap_interval == 0 || - GUIEngine::isNoGraphics()) && - m_throttle_fps && !ProfileWorld::isProfileMode() && - current_fps > max_fps) + if (!UserConfigParams::m_benchmark) { - double wait_time = 1.0 / max_fps - 1.0 / current_fps; - std::chrono::nanoseconds wait_time_ns( - (uint64_t)(wait_time * 1000.0 * 1000.0 * 1000.0)); - PROFILER_PUSH_CPU_MARKER("Throttle framerate", 0, 0, 0); - std::this_thread::sleep_for(wait_time_ns); - PROFILER_POP_CPU_MARKER(); + TimePoint frame_end = std::chrono::steady_clock::now(); + double frame_time = convertToTime(frame_end, frame_start) * 0.001; + const double current_fps = 1.0 / frame_time; + const double max_fps = + (irr_driver->isRecording() && UserConfigParams::m_limit_game_fps) ? + UserConfigParams::m_record_fps : UserConfigParams::m_max_fps; + + // Throttle fps if more than maximum, which can reduce + // the noise the fan on a graphics card makes. + // No need to throttle if vsync is on (m_swap_interval == 1) as + // endScene handles fps according to monitor refresh rate + if ((UserConfigParams::m_swap_interval == 0 || + GUIEngine::isNoGraphics()) && + m_throttle_fps && !ProfileWorld::isProfileMode() && + current_fps > max_fps) + { + double wait_time = 1.0 / max_fps - 1.0 / current_fps; + std::chrono::nanoseconds wait_time_ns( + (uint64_t)(wait_time * 1000.0 * 1000.0 * 1000.0)); + PROFILER_PUSH_CPU_MARKER("Throttle framerate", 0, 0, 0); + std::this_thread::sleep_for(wait_time_ns); + PROFILER_POP_CPU_MARKER(); + } } PROFILER_POP_CPU_MARKER(); // MainLoop pop diff --git a/src/network/child_loop.cpp b/src/network/child_loop.cpp index 5143fbeed51..ee0324509a6 100644 --- a/src/network/child_loop.cpp +++ b/src/network/child_loop.cpp @@ -58,6 +58,8 @@ float ChildLoop::getLimitedDt() } dt = (float)(m_curr_time - m_prev_time); } + if (UserConfigParams::m_benchmark) + break; const int current_fps = (int)(1000.0f / dt); const int max_fps = UserConfigParams::m_max_fps;