Move the start benchmark function to the profiler

This simplifies its reuse for the recommend video settings function
This commit is contained in:
Alayan 2024-05-20 11:46:06 +02:00
parent fb3596f699
commit dca91a6ee8
No known key found for this signature in database
5 changed files with 34 additions and 33 deletions

View File

@ -249,7 +249,7 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
// Auto-compute the rendering distance, but use a high scaling factor
// to ensure that even at low settings, on-track items only become invisible
// when already quite far.
lodnode->autoComputeLevel(24); // The distance grows with the square of the scaling factor
lodnode->autoComputeLevel(24); // The distance grows with the square root of the scaling factor
m_node = lodnode;
}
setType(type);

View File

@ -21,10 +21,9 @@
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
#include "race/race_manager.hpp"
#include "replay/replay_play.hpp"
#include "states_screens/dialogs/custom_video_settings.hpp"
#include "states_screens/dialogs/recommend_video_settings.hpp"
#include "utils/profiler.hpp"
#ifndef SERVER_ONLY
#include <ge_main.hpp>
@ -317,7 +316,7 @@ void OptionsScreenVideo::init()
// the graphics engine, start the benchmark when the
// video settings screen is loaded back afterwards.
if (RaceManager::get()->isBenchmarkScheduled())
startBenchmark();
profiler.startBenchmark();
} // init
// --------------------------------------------------------------------------------------------
@ -665,20 +664,11 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
else if (name == "benchmarkCurrent")
{
#ifndef SERVER_ONLY
// TODO - Add the possibility to benchmark more tracks and define replay benchmarks in
// a config file
const std::string bf_bench("benchmark_black_forest.replay");
const bool result = ReplayPlay::get()->addReplayFile(file_manager
->getAsset(FileManager::REPLAY, bf_bench), true/*custom_replay*/);
if (!result)
Log::fatal("OptionsScreenVideo", "Can't open replay for benchmark!");
// To avoid crashes and ensure the proper settings are used during the benchmark,
// we apply the settings. If this doesn't require restarting the screen, we start
// the benchmark immediately, otherwise we schedule it to start after the restart.
if (applySettings() == 0)
startBenchmark();
profiler.startBenchmark();
else
RaceManager::get()->scheduleBenchmark();
#endif
@ -691,24 +681,6 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
// --------------------------------------------------------------------------------------------
void OptionsScreenVideo::startBenchmark()
{
RaceManager::get()->setRaceGhostKarts(true);
RaceManager::get()->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
ReplayPlay::ReplayData bench_rd = ReplayPlay::get()->getCurrentReplayData();
RaceManager::get()->setReverseTrack(bench_rd.m_reverse);
RaceManager::get()->setRecordRace(false);
RaceManager::get()->setWatchingReplay(true);
RaceManager::get()->setDifficulty((RaceManager::Difficulty)bench_rd.m_difficulty);
// The race manager automatically adds karts for the ghosts
RaceManager::get()->setNumKarts(0);
RaceManager::get()->setBenchmarking(true); // Also turns off the scheduled benchmark if needed
RaceManager::get()->startWatchingReplay(bench_rd.m_track_name, bench_rd.m_laps);
} // startBenchmark
// --------------------------------------------------------------------------------------------
void OptionsScreenVideo::tearDown()
{
#ifndef SERVER_ONLY

View File

@ -72,7 +72,6 @@ private:
void updateTooltip();
void updateBlurTooltip();
void initPresets();
void startBenchmark();
static void onScrollResolutionsList(void* data);
/* Returns 1 or 2 if a restart will be done, 0 otherwise */
int applySettings();

View File

@ -26,6 +26,8 @@
#include "graphics/irr_driver.hpp"
#include "guiengine/scalable_font.hpp"
#include "io/file_manager.hpp"
#include "race/race_manager.hpp"
#include "replay/replay_play.hpp"
#include "tracks/track.hpp"
#include "utils/file_utils.hpp"
#include "utils/string_utils.hpp"
@ -653,6 +655,33 @@ void Profiler::computeStableFPS()
m_lock.unlock();
} // computeStableFPS
// --------------------------------------------------------------------------------------------
void Profiler::startBenchmark()
{
// TODO - Add the possibility to benchmark more tracks and define replay benchmarks in
// a config file
const std::string bf_bench("benchmark_black_forest.replay");
const bool result = ReplayPlay::get()->addReplayFile(file_manager
->getAsset(FileManager::REPLAY, bf_bench), true/*custom_replay*/);
if (!result)
Log::fatal("OptionsScreenVideo", "Can't open replay for benchmark!");
RaceManager::get()->setRaceGhostKarts(true);
RaceManager::get()->setMinorMode(RaceManager::MINOR_MODE_TIME_TRIAL);
ReplayPlay::ReplayData bench_rd = ReplayPlay::get()->getCurrentReplayData();
RaceManager::get()->setReverseTrack(bench_rd.m_reverse);
RaceManager::get()->setRecordRace(false);
RaceManager::get()->setWatchingReplay(true);
RaceManager::get()->setDifficulty((RaceManager::Difficulty)bench_rd.m_difficulty);
// The race manager automatically adds karts for the ghosts
RaceManager::get()->setNumKarts(0);
RaceManager::get()->setBenchmarking(true); // Also turns off the scheduled benchmark if needed
RaceManager::get()->startWatchingReplay(bench_rd.m_track_name, bench_rd.m_laps);
} // startBenchmark
//-----------------------------------------------------------------------------
/** Saves the collected profile data to a file. Filename is based on the
* stdout name (with -profile appended).

View File

@ -322,6 +322,7 @@ public:
void draw();
void onClick(const core::vector2di& mouse_pos);
void computeStableFPS();
void startBenchmark();
void writeToFile();
// ------------------------------------------------------------------------