From 41d6aeaa9959d376696a07b8423e62d2a0abb72c Mon Sep 17 00:00:00 2001 From: Ettore Chimenti Date: Wed, 16 Oct 2024 20:12:15 +0200 Subject: [PATCH] Add benchmark mode to commandline options (#5178) Adding `--benchmark` to commandline options to automatically start benchmark mode, set unlimited FPS, save result and exit. Signed-off-by: Ettore Chimenti Co-authored-by: Ettore Chimenti --- src/config/user_config.hpp | 2 ++ src/main.cpp | 26 +++++++++++++++++++++----- src/states_screens/race_result_gui.cpp | 12 +++++++++++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index ea0887c08be..92b9c54985e 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -849,6 +849,8 @@ namespace UserConfigParams PARAM_PREFIX bool m_disable_addon_tracks PARAM_DEFAULT( false ); + PARAM_PREFIX bool m_benchmark PARAM_DEFAULT( false ); + // ---- Networking PARAM_PREFIX StringToUIntUserConfigParam m_server_bookmarks PARAM_DEFAULT(StringToUIntUserConfigParam("server-bookmarks", diff --git a/src/main.cpp b/src/main.cpp index 678f929eb1b..69972c816bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -592,6 +592,7 @@ void cmdLineHelp() "laps.\n" " --profile-time=n Enable automatic driven profile mode for n " "seconds.\n" + " --benchmark Start Benchmark Mode, save results and exit. \n" " --unlock-all Permanently unlock all karts and tracks for testing.\n" " --no-unlock-all Disable unlock-all (i.e. base unlocking on player achievement).\n" " --xmas=n Toggle Xmas/Christmas mode. n=0 Use current date, n=1, Always enable,\n" @@ -1707,6 +1708,14 @@ int handleCmdLine(bool has_server_config, bool has_parent_process) RaceManager::get()->setNumLaps(n); } } // --profile-laps + + if(CommandLine::has("--benchmark")) + { + 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 if(CommandLine::has("--unlock-all")) { @@ -2552,11 +2561,18 @@ int main(int argc, char *argv[]) { if(UserConfigParams::m_no_start_screen) { - // Quickstart (-N) - // =============== - // all defaults are set in InitTuxkart() - RaceManager::get()->setupPlayerKartInfo(); - RaceManager::get()->startNew(false); + if (UserConfigParams::m_benchmark) + { + profiler.startBenchmark(); + } + else + { + // Quickstart (-N) + // =============== + // all defaults are set in InitTuxkart() + RaceManager::get()->setupPlayerKartInfo(); + RaceManager::get()->startNew(false); + } } } else // profile diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index bf22b9fc669..48e76eff8c7 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -70,6 +70,7 @@ #include "utils/profiler.hpp" #include "utils/string_utils.hpp" #include "utils/translation.hpp" +#include "main_loop.hpp" #include @@ -1269,7 +1270,16 @@ void RaceResultGUI::renderGlobal(float dt) } else if (RaceManager::get()->isBenchmarking()) { - displayBenchmarkSummary(); + if(!UserConfigParams::m_benchmark) + { + displayBenchmarkSummary(); + } + else + { + // Benchmark requested from CLI, write to file and exit + profiler.writeToFile(); + main_loop->requestAbort(); + } } else {