From 5fe58846132147502f8a8def56c28425e8a30323 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 26 Dec 2020 10:54:01 +0000 Subject: [PATCH] Debug: Add experimental command to switch baseset --- src/console_cmds.cpp | 23 +++++++++++++++++++++++ src/date.cpp | 1 + src/gfx.cpp | 2 ++ src/openttd.cpp | 29 +++++++++++++++++++++++------ src/openttd.h | 1 + 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 4d1e9dc59f..a178d567fd 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -49,6 +49,7 @@ #include "industry.h" #include "string_func_extra.h" #include "linkgraph/linkgraphjob.h" +#include "base_media_base.h" #include #include "safeguards.h" @@ -2810,6 +2811,27 @@ DEF_CONSOLE_CMD(ConRailTypeMapColourCtl) return true; } +DEF_CONSOLE_CMD(ConSwitchBaseset) +{ + if (argc != 2) { + IConsoleHelp("Debug: Try to switch baseset and reload NewGRFs. Usage: 'switch_baseset '"); + return true; + } + + for (int i = 0; i < BaseGraphics::GetNumSets(); i++) { + const GraphicsSet *basegfx = BaseGraphics::GetSet(i); + if (argv[1] == basegfx->name) { + extern std::string _switch_baseset; + _switch_baseset = basegfx->name; + _check_special_modes = true; + return true; + } + } + + IConsolePrintF(CC_WARNING, "No such baseset: %s.", argv[1]); + return 1; +} + #ifdef _DEBUG /****************** * debug commands @@ -3031,6 +3053,7 @@ void IConsoleStdLibRegister() IConsoleCmdRegister("delete_company", ConDeleteCompany, ConHookNewGRFDeveloperTool, true); IConsoleCmdRegister("road_type_flag_ctl", ConRoadTypeFlagCtl, ConHookNewGRFDeveloperTool, true); IConsoleCmdRegister("rail_type_map_colour_ctl", ConRailTypeMapColourCtl, ConHookNewGRFDeveloperTool, true); + IConsoleCmdRegister("switch_baseset", ConSwitchBaseset, ConHookNewGRFDeveloperTool, true); /* Bug workarounds */ IConsoleCmdRegister("jgrpp_bug_workaround_unblock_heliports", ConResetBlockedHeliports, ConHookNoNetwork, true); diff --git a/src/date.cpp b/src/date.cpp index 5ce208e67a..45c19ae6f9 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -245,6 +245,7 @@ static void OnNewMonth() { if (_settings_client.gui.autosave != 0 && (_cur_date_ymd.month % _autosave_months[_settings_client.gui.autosave]) == 0) { _do_autosave = true; + _check_special_modes = true; SetWindowDirty(WC_STATUS_BAR, 0); } diff --git a/src/gfx.cpp b/src/gfx.cpp index 9d506b7dbd..1b5af57cd9 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -47,11 +47,13 @@ bool _right_button_down; ///< Is right mouse button pressed? bool _right_button_clicked; ///< Is right mouse button clicked? DrawPixelInfo _screen; bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot) +bool _check_special_modes; bool _exit_game; GameMode _game_mode; SwitchMode _switch_mode; ///< The next mainloop command. PauseMode _pause_mode; Palette _cur_palette; +std::string _switch_baseset; static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of often used characters. @see GetCharacterWidth() DrawPixelInfo *_cur_dpi; diff --git a/src/openttd.cpp b/src/openttd.cpp index 5698e42c58..15d3ca188f 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1889,6 +1889,28 @@ static void DoAutosave() } } +void GameLoopSpecial() +{ + /* autosave game? */ + if (_do_autosave) { + DoAutosave(); + _do_autosave = false; + SetWindowDirty(WC_STATUS_BAR, 0); + } + + extern std::string _switch_baseset; + if (!_switch_baseset.empty()) { + if (BaseGraphics::GetUsedSet()->name != _switch_baseset) { + BaseGraphics::SetSet(_switch_baseset); + + ReloadNewGRFData(); + } + _switch_baseset.clear(); + } + + _check_special_modes = false; +} + void GameLoop() { if (_game_mode == GM_BOOTSTRAP) { @@ -1900,12 +1922,7 @@ void GameLoop() ProcessAsyncSaveFinish(); - /* autosave game? */ - if (_do_autosave) { - DoAutosave(); - _do_autosave = false; - SetWindowDirty(WC_STATUS_BAR, 0); - } + if (unlikely(_check_special_modes)) GameLoopSpecial(); /* switch game mode? */ if (_switch_mode != SM_NONE && !HasModalProgress()) { diff --git a/src/openttd.h b/src/openttd.h index 1a2dae1bff..ded4254b02 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -55,6 +55,7 @@ enum ExtraDisplayOptions { extern GameMode _game_mode; extern SwitchMode _switch_mode; +extern bool _check_special_modes; extern bool _exit_game; /** Modes of pausing we've got */