Fix crashing when turning the modern renderer on or off before benchmarking

This commit is contained in:
Alayan 2024-04-28 18:32:51 +02:00
parent 9206b923f7
commit 01d62be5de
No known key found for this signature in database
4 changed files with 65 additions and 16 deletions

View File

@ -146,6 +146,7 @@ RaceManager::RaceManager()
setRaceGhostKarts(false);
setWatchingReplay(false);
setBenchmarking(false);
m_scheduled_benchmark = false;
setTrack("jungle");
m_default_ai_list.clear();
setNumPlayers(0);
@ -1330,6 +1331,7 @@ core::stringw RaceManager::getDifficultyName(Difficulty diff) const
void RaceManager::setBenchmarking(bool benchmark)
{
m_benchmarking = benchmark;
m_scheduled_benchmark = false;
// If the benchmark mode is turned off and the profiler is still activated,
// turn the profiler off and reset the drawing mode to default.
@ -1339,3 +1341,11 @@ void RaceManager::setBenchmarking(bool benchmark)
profiler.setDrawing(true);
}
} // setBenchmarking
//---------------------------------------------------------------------------------------------
/** Schedule a benchmark. This function is used because the video options screen
* might need to be reloaded when switching between old and modern renderer.*/
void RaceManager::scheduleBenchmark()
{
m_scheduled_benchmark = true;
} // scheduleBenchmark

View File

@ -368,6 +368,7 @@ private:
bool m_has_ghost_karts;
bool m_watching_replay;
bool m_benchmarking;
bool m_scheduled_benchmark;
public:
// ----------------------------------------------------------------------------------------
@ -438,6 +439,7 @@ public:
void setDefaultAIKartList(const std::vector<std::string> &ai_list);
void computeRandomKartList();
void setBenchmarking(bool benchmark);
void scheduleBenchmark();
// ----------------------------------------------------------------------------------------
bool hasTimeTarget() const { return m_time_target > 0.0f; }
@ -875,6 +877,11 @@ public:
return m_benchmarking;
} // isBenchmarking
// ----------------------------------------------------------------------------------------
bool isBenchmarkScheduled() const
{
return m_scheduled_benchmark;
} // isBenchmarkSchedule
// ----------------------------------------------------------------------------------------
void addSpareTireKart(const std::string& name)
{
m_kart_status.push_back(KartStatus(name, 0, -1, -1,

View File

@ -371,6 +371,12 @@ void OptionsScreenVideo::init()
m_fullscreen_checkbox_focus = false;
getWidget("fullscreen")->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
// If a benchmark was requested and the game had to reload
// the graphics engine, start the benchmark when the
// video settings screen is loaded back afterwards.
if (RaceManager::get()->isBenchmarkScheduled())
startBenchmark();
} // init
// --------------------------------------------------------------------------------------------
@ -882,7 +888,7 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
updateBlurSlider();
}
else if (name == "vsync")
else if (name == "vsync") // Also handles the FPS limiter
{
GUIEngine::SpinnerWidget* vsync = getWidget<GUIEngine::SpinnerWidget>("vsync");
assert( vsync != NULL );
@ -904,7 +910,7 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
#if !defined(SERVER_ONLY) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
update_swap_interval(UserConfigParams::m_swap_interval);
#endif
}
} // vSync
else if (name == "scale_rtts")
{
GUIEngine::SpinnerWidget* scale_rtts_level =
@ -924,7 +930,7 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
}
#endif
updateScaleRTTsSlider();
}
} // scale_rtts
else if (name == "benchmarkCurrent")
{
// TODO - Add the possibility to benchmark more tracks and define replay benchmarks in
@ -935,20 +941,27 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
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);
RaceManager::get()->startWatchingReplay(bench_rd.m_track_name, bench_rd.m_laps);
}
// Avoid crashing, when switching between advanced lighting and the old renderer
// before starting a performance test, ensure the image quality setting is applied
if (m_prev_adv_pipline != UserConfigParams::m_dynamic_lights &&
CVS->isGLSL())
{
irr_driver->sameRestart();
// We cannot start the benchmark immediately, in case we just restarted the graphics engine
RaceManager::get()->scheduleBenchmark();
}
else if (m_prev_img_quality != getImageQuality())
{
// TODO - check if this is enough for the setting to be properly applied
irr_driver->setMaxTextureSize();
startBenchmark();
}
else
{
startBenchmark();
}
} // benchmarkCurrent
// TODO - Add a standard benchmark testing multiple presets
/*else if (name == "benchmarkStandard")
{
@ -998,6 +1011,24 @@ 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()
{
if (getWidget("fullscreen")->isVisible() &&

View File

@ -104,6 +104,7 @@ private:
void updateResolutionsList();
void configResolutionsList();
void initPresets();
void startBenchmark();
static void onScrollResolutionsList(void* data);
public:
friend class GUIEngine::ScreenSingleton<OptionsScreenVideo>;