Skip to content

Commit

Permalink
Fix crashing when turning the modern renderer on or off before benchm…
Browse files Browse the repository at this point in the history
…arking
  • Loading branch information
Alayan-stk-2 committed Apr 28, 2024
1 parent 9206b92 commit 01d62be
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 17 deletions.
10 changes: 10 additions & 0 deletions src/race/race_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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
7 changes: 7 additions & 0 deletions src/race/race_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ class RaceManager
bool m_has_ghost_karts;
bool m_watching_replay;
bool m_benchmarking;
bool m_scheduled_benchmark;

public:
// ----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -438,6 +439,7 @@ class RaceManager
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; }
Expand Down Expand Up @@ -875,6 +877,11 @@ class RaceManager
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,
Expand Down
65 changes: 48 additions & 17 deletions src/states_screens/options/options_screen_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

// --------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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 );
Expand All @@ -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 =
Expand All @@ -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
Expand All @@ -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")
{
Expand Down Expand Up @@ -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() &&
Expand Down
1 change: 1 addition & 0 deletions src/states_screens/options/options_screen_video.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class OptionsScreenVideo : public GUIEngine::Screen, public GUIEngine::ScreenSin
void updateResolutionsList();
void configResolutionsList();
void initPresets();
void startBenchmark();
static void onScrollResolutionsList(void* data);
public:
friend class GUIEngine::ScreenSingleton<OptionsScreenVideo>;
Expand Down

0 comments on commit 01d62be

Please sign in to comment.