From 4f81c56d8f80402c8d14f6daa3d1925507f6cfe2 Mon Sep 17 00:00:00 2001 From: pelya Date: Wed, 5 Apr 2017 21:50:24 +0300 Subject: [PATCH] Bad fix for changing video depth resetting all settings to zero --- src/gfx.cpp | 1 + src/openttd.cpp | 21 +++++++++++++++++++++ src/openttd.h | 1 + src/settings_gui.cpp | 14 +++++++------- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 06123fd73e..7623e7f3bb 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -47,6 +47,7 @@ Point _right_button_down_pos; ///< Pos of right mouse button click, for drag and DrawPixelInfo _screen; bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot) bool _exit_game; +bool _restart_game; GameMode _game_mode; SwitchMode _switch_mode; ///< The next mainloop command. PauseModeByte _pause_mode; diff --git a/src/openttd.cpp b/src/openttd.cpp index 3830c6d6c1..5231f4f71a 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -491,6 +491,20 @@ struct AfterNewGRFScan : NewGRFScanCallback { } #endif /* ENABLE_NETWORK */ + // TODO: remove this hack in one year + // Check if OpenTTD config is broken by blitter changing code + static bool checked = false; + DEBUG(misc, 0, "========= Limits for vehicles: %d %d %d %d", _settings_newgame.vehicle.max_trains, _settings_newgame.vehicle.max_roadveh, _settings_newgame.vehicle.max_aircraft, _settings_newgame.vehicle.max_ships); + if (!checked && + _settings_newgame.vehicle.max_trains == 0 && _settings_newgame.vehicle.max_roadveh == 0 && + _settings_newgame.vehicle.max_aircraft == 0 && _settings_newgame.vehicle.max_ships == 0) { + unlink("libsdl-DownloadFinished-1.flag"); + //_exit_game = true; + //_restart_game = true; + abort(); // Kill myself with contempt, user will restart the app, because otherwise we enter infinite restart loop + } + checked = true; + /* After the scan we're not used anymore. */ delete this; } @@ -925,6 +939,13 @@ exit_normal: } #endif /* ENABLE_NETWORK */ + if (_restart_game) { +#ifdef __ANDROID__ + // This makes OpenTTD reset all it's settings for some reason. Just abort and pretend we crashed + //SDL_ANDROID_RestartMyself("restart-settings"); +#endif + } + return ret; } diff --git a/src/openttd.h b/src/openttd.h index 5e360d6fcd..0a92475f51 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -52,6 +52,7 @@ enum DisplayOptions { extern GameMode _game_mode; extern SwitchMode _switch_mode; extern bool _exit_game; +extern bool _restart_game; /** Modes of pausing we've got */ enum PauseMode { diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 0fdad13794..77a06c1c78 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -187,7 +187,7 @@ struct GameOptionsWindow : Window { { DeleteWindowById(WC_CUSTOM_CURRENCY, 0); if (this->reload) _switch_mode = SM_MENU; - SaveToConfig(); // save all settins immediately on Android, because users tend to kill the app instead of pressing 'Quit' button + if (!_exit_game) SaveToConfig(); // Save all settings immediately on Android, because users tend to kill the app instead of pressing 'Quit' button } /** @@ -494,10 +494,10 @@ struct GameOptionsWindow : Window { if (this->IsWidgetLowered(WID_GO_8BPP_BUTTON)) break; free(_ini_blitter); _ini_blitter = stredup("8bpp-optimized"); - SaveToConfig(); + _exit_game = true; + _restart_game = true; #ifdef __ANDROID__ SDL_ANDROID_SetConfigOption(SDL_ANDROID_CONFIG_VIDEO_DEPTH_BPP, 16); - SDL_ANDROID_RestartMyself("restart-settings"); // We terminate here, no need to update widget state #endif break; @@ -505,10 +505,10 @@ struct GameOptionsWindow : Window { if (this->IsWidgetLowered(WID_GO_16BPP_BUTTON)) break; free(_ini_blitter); _ini_blitter = stredup("16bpp-simple"); - SaveToConfig(); + _exit_game = true; + _restart_game = true; #ifdef __ANDROID__ SDL_ANDROID_SetConfigOption(SDL_ANDROID_CONFIG_VIDEO_DEPTH_BPP, 16); - SDL_ANDROID_RestartMyself("restart-settings"); // We terminate here, no need to update widget state #endif break; @@ -516,10 +516,10 @@ struct GameOptionsWindow : Window { if (this->IsWidgetLowered(WID_GO_32BPP_BUTTON)) break; free(_ini_blitter); _ini_blitter = stredup("32bpp-anim"); - SaveToConfig(); + _exit_game = true; + _restart_game = true; #ifdef __ANDROID__ SDL_ANDROID_SetConfigOption(SDL_ANDROID_CONFIG_VIDEO_DEPTH_BPP, 24); - SDL_ANDROID_RestartMyself("restart-settings"); // We terminate here, no need to update widget state #endif break;