Skip to content

Commit

Permalink
Prevent mx fps write in command line benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed Oct 19, 2024
1 parent a1f78ef commit d3566a8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 24 additions & 21 deletions src/main_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/network/child_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d3566a8

Please sign in to comment.