Skip to content

Commit

Permalink
Next revision
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Jan 18, 2024
1 parent 6906d88 commit 95347b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
18 changes: 0 additions & 18 deletions builtin/mainmenu/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,3 @@
function core.sound_stop(handle, ...)
return handle:stop(...)
end

-- On Android, closing the app via the "Recents" screen won't result in a clean
-- shutdown, discarding any setting changes made by the user.
-- To avoid that, we write the settings file in more cases on Android.
-- We don't do this on desktop platforms because you can have multiple
-- instances of Minetest running at the same time there.
function write_settings_early()
if PLATFORM == "Android" then
core.settings:write()
end
end

local old_core_start = core.start
core.start = function()
-- Necessary for saving the selected world, server address, player name, etc.
write_settings_early()
old_core_start()
end
10 changes: 10 additions & 0 deletions builtin/mainmenu/settings/dlg_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ local function get_formspec(dialogdata)
end


-- On Android, closing the app via the "Recents" screen won't result in a clean
-- shutdown, discarding any setting changes made by the user.
-- To avoid that, we write the settings file in more cases on Android.
function write_settings_early()
if PLATFORM == "Android" then
core.settings:write()
end
end


local function buttonhandler(this, fields)
local dialogdata = this.data
dialogdata.leftscroll = core.explode_scrollbar_event(fields.leftscroll).value or dialogdata.leftscroll
Expand Down
25 changes: 21 additions & 4 deletions src/client/clientlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
}

// Break out of menu-game loop to shut down cleanly
if (!m_rendering_engine->run() || *kill) {
if (!g_settings_path.empty())
g_settings->updateConfigFile(g_settings_path.c_str());
if (!m_rendering_engine->run() || *kill)
break;
}

m_rendering_engine->get_video_driver()->setTextureCreationFlag(
video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
Expand Down Expand Up @@ -295,6 +292,16 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
receiver->m_touchscreengui = NULL;
#endif

/* Save the settings when leaving the game.
* This makes sure that setting changes made in-game are persisted even in
* case of an unclean shutdown (e.g. a crash).
* This is useful on Android because closing the app from the
* "Recents screen" results in an unclean shutdown.
* Caveat: This means that the settings are saved twice when exiting Minetest.
*/
if (!g_settings_path.empty())
g_settings->updateConfigFile(g_settings_path.c_str());

// If no main menu, show error and exit
if (skip_main_menu) {
if (!error_message.empty()) {
Expand Down Expand Up @@ -558,6 +565,16 @@ void ClientLauncher::main_menu(MainMenuData *menudata)

/* leave scene manager in a clean state */
m_rendering_engine->get_scene_manager()->clear();

/* Save the settings when leaving the mainmenu.
* This makes sure that settings like the selected world or the player name
* are persisted even in case of an unclean shutdown (e.g. a crash).
* This is necessary on Android because closing the app from the
* "Recents screen" results in an unclean shutdown.
* Caveat: This means that the settings are saved twice when exiting Minetest.
*/
if (!g_settings_path.empty())
g_settings->updateConfigFile(g_settings_path.c_str());
}

void ClientLauncher::speed_tests()
Expand Down

0 comments on commit 95347b1

Please sign in to comment.