diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index e45c2737e05..823ddf60680 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -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 \ No newline at end of file diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index 4341674b38f..3f5d28a659f 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -368,6 +368,7 @@ class RaceManager bool m_has_ghost_karts; bool m_watching_replay; bool m_benchmarking; + bool m_scheduled_benchmark; public: // ---------------------------------------------------------------------------------------- @@ -438,6 +439,7 @@ class RaceManager void setDefaultAIKartList(const std::vector &ai_list); void computeRandomKartList(); void setBenchmarking(bool benchmark); + void scheduleBenchmark(); // ---------------------------------------------------------------------------------------- bool hasTimeTarget() const { return m_time_target > 0.0f; } @@ -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, diff --git a/src/states_screens/options/options_screen_video.cpp b/src/states_screens/options/options_screen_video.cpp index f8163365367..5c6de359c04 100644 --- a/src/states_screens/options/options_screen_video.cpp +++ b/src/states_screens/options/options_screen_video.cpp @@ -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("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() && diff --git a/src/states_screens/options/options_screen_video.hpp b/src/states_screens/options/options_screen_video.hpp index 38fcdbd3ecc..cbdbc2bbc7f 100644 --- a/src/states_screens/options/options_screen_video.hpp +++ b/src/states_screens/options/options_screen_video.hpp @@ -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;