[Scummvm-git-logs] scummvm master -> 53bb50c906ed0da7fbc70eba61309292a5e6dd42

criezy criezy at scummvm.org
Sat Sep 12 23:22:08 UTC 2020


This automated email contains information about 6 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
32bbf489e9 GUI: Add exitLoop() method to GuiManager
7c812a52f1 IOS7: Call pauseEngine() when suspending the application
28e9910666 IOS7: Implement game state save/restore when switching tasks
63627dc26d IOS7: Save state as a background task when entering background
c50ffd74c6 IOS7: Properly restore state when the process has been terminated
53bb50c906 IOS7: Do not overwrite user saves when saving state


Commit: 32bbf489e901bfbc2236e3c1136bd5ea7e71e749
    https://github.com/scummvm/scummvm/commit/32bbf489e901bfbc2236e3c1136bd5ea7e71e749
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:21:34+01:00

Commit Message:
GUI: Add exitLoop() method to GuiManager

The idea is to allow backends to start a game even after the
LauncherDialog has been created, and for that they need a way
to close the existing GUI dialogs.

Changed paths:
    gui/gui-manager.cpp
    gui/gui-manager.h


diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index 270c1765ba..50eb8d2a7b 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -449,6 +449,11 @@ void GuiManager::runLoop() {
 #endif
 }
 
+void GuiManager::exitLoop() {
+	while (!_dialogStack.empty())
+		getTopDialog()->close();
+}
+
 #pragma mark -
 
 void GuiManager::saveState() {
diff --git a/gui/gui-manager.h b/gui/gui-manager.h
index dea22189c9..29769900b8 100644
--- a/gui/gui-manager.h
+++ b/gui/gui-manager.h
@@ -75,6 +75,11 @@ public:
 	// until no dialogs are active anymore.
 	void runLoop();
 
+	// If the GUI loop is running close all the dialogs causing the loop to finish.
+	// Typically you may want to use it after setting the ConfMan active domain to
+	// a game domain to cause the game to start.
+	void exitLoop();
+
 	void processEvent(const Common::Event &event, Dialog *const activeDialog);
 	Common::Keymap *getKeymap() const;
 	void scheduleTopDialogRedraw();


Commit: 7c812a52f1476a7584dbb1b93c00ee7b29d7a8ee
    https://github.com/scummvm/scummvm/commit/7c812a52f1476a7584dbb1b93c00ee7b29d7a8ee
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:21:35+01:00

Commit Message:
IOS7: Call pauseEngine() when suspending the application

Changed paths:
    backends/platform/ios7/ios7_osys_main.cpp


diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp
index 90bb5d6933..e918bb868b 100644
--- a/backends/platform/ios7/ios7_osys_main.cpp
+++ b/backends/platform/ios7/ios7_osys_main.cpp
@@ -38,6 +38,8 @@
 
 #include "base/main.h"
 
+#include "engines/engine.h"
+
 #include "backends/saves/default/default-saves.h"
 #include "backends/timer/default/default-timer.h"
 #include "backends/fs/chroot/chroot-fs-factory.h"
@@ -226,6 +228,12 @@ void OSystem_iOS7::suspendLoop() {
 	bool done = false;
 	uint32 startTime = getMillis();
 
+	PauseToken pt;
+	if (g_engine)
+		pt = g_engine->pauseEngine();
+
+	// We also need to stop the audio queue and restart it later in case there
+	// is an audio interruption that render it invalid.
 	stopSoundsystem();
 
 	InternalEvent event;


Commit: 28e991066626654dcbe67f900e9f431766369f9c
    https://github.com/scummvm/scummvm/commit/28e991066626654dcbe67f900e9f431766369f9c
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:21:35+01:00

Commit Message:
IOS7: Implement game state save/restore when switching tasks

This only works if the running engines can save the game at the
time when ScummVM goes to the background.
This should partially fix bug #7871.

Changed paths:
    backends/platform/ios7/ios7_app_delegate.mm
    backends/platform/ios7/ios7_common.h
    backends/platform/ios7/ios7_osys_events.cpp
    backends/platform/ios7/ios7_osys_main.cpp
    backends/platform/ios7/ios7_osys_main.h
    backends/platform/ios7/ios7_video.h
    backends/platform/ios7/ios7_video.mm


diff --git a/backends/platform/ios7/ios7_app_delegate.mm b/backends/platform/ios7/ios7_app_delegate.mm
index 014275d116..6a09f549ef 100644
--- a/backends/platform/ios7/ios7_app_delegate.mm
+++ b/backends/platform/ios7/ios7_app_delegate.mm
@@ -86,6 +86,18 @@
 	[_view applicationResume];
 }
 
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+	[_view applicationEnteredBackground];
+	// Add a delay so that the app continues running and gives time for the scummvm thread to
+	// poll the events and call saveState(). The application says we have 5 seconds to do things
+	// in this function before the app is terminated. Wait 2 seconds as it should be sufficient.
+	usleep(2000000);
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+	[_view applicationEnteredForeground];
+}
+
 - (void)didRotate:(NSNotification *)notification {
 	UIDeviceOrientation screenOrientation = [[UIDevice currentDevice] orientation];
 	[_view deviceOrientationChanged:screenOrientation];
diff --git a/backends/platform/ios7/ios7_common.h b/backends/platform/ios7/ios7_common.h
index dd1e85a884..44ddf75200 100644
--- a/backends/platform/ios7/ios7_common.h
+++ b/backends/platform/ios7/ios7_common.h
@@ -39,6 +39,8 @@ enum InputEvent {
 	kInputKeyPressed,
 	kInputApplicationSuspended,
 	kInputApplicationResumed,
+	kInputApplicationEnteredBackground,
+	kInputApplicationEnteredForeground,
 	kInputSwipe,
 	kInputTap,
 	kInputMainMenu
diff --git a/backends/platform/ios7/ios7_osys_events.cpp b/backends/platform/ios7/ios7_osys_events.cpp
index fa8bb5bb88..de59f06985 100644
--- a/backends/platform/ios7/ios7_osys_events.cpp
+++ b/backends/platform/ios7/ios7_osys_events.cpp
@@ -77,6 +77,14 @@ bool OSystem_iOS7::pollEvent(Common::Event &event) {
 			handleEvent_applicationResumed();
 			return false;
 
+		case kInputApplicationEnteredBackground:
+			handleEvent_applicationEnteredBackground();
+			return false;
+
+		case kInputApplicationEnteredForeground:
+			handleEvent_applicationEnteredForeground();
+			return false;
+
 		case kInputMouseSecondDragged:
 			if (!handleEvent_mouseSecondDragged(event, internalEvent.value1, internalEvent.value2))
 				return false;
@@ -385,6 +393,14 @@ void OSystem_iOS7::handleEvent_applicationResumed() {
 	rebuildSurface();
 }
 
+void OSystem_iOS7::handleEvent_applicationEnteredBackground() {
+	saveState();
+}
+
+void OSystem_iOS7::handleEvent_applicationEnteredForeground() {
+	restoreState();
+}
+
 void  OSystem_iOS7::handleEvent_keyPressed(Common::Event &event, int keyPressed) {
 	int ascii = keyPressed;
 	//printf("key: %i\n", keyPressed);
diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp
index e918bb868b..1d25009346 100644
--- a/backends/platform/ios7/ios7_osys_main.cpp
+++ b/backends/platform/ios7/ios7_osys_main.cpp
@@ -35,11 +35,15 @@
 #include "common/rect.h"
 #include "common/file.h"
 #include "common/fs.h"
+#include "common/config-manager.h"
+#include "common/translation.h"
 
 #include "base/main.h"
 
 #include "engines/engine.h"
 
+#include "gui/gui-manager.h"
+
 #include "backends/saves/default/default-saves.h"
 #include "backends/timer/default/default-timer.h"
 #include "backends/fs/chroot/chroot-fs-factory.h"
@@ -238,9 +242,14 @@ void OSystem_iOS7::suspendLoop() {
 
 	InternalEvent event;
 	while (!done) {
-		if (iOS7_fetchEvent(&event))
+		if (iOS7_fetchEvent(&event)) {
 			if (event.type == kInputApplicationResumed)
 				done = true;
+			else if (event.type == kInputApplicationEnteredBackground)
+				saveState();
+			else if (event.type == kInputApplicationEnteredForeground)
+				restoreState();
+		}
 		usleep(100000);
 	}
 
@@ -249,6 +258,50 @@ void OSystem_iOS7::suspendLoop() {
 	_timeSuspended += getMillis() - startTime;
 }
 
+void OSystem_iOS7::saveState() {
+	// Clear any previous restore state to avoid having and obsolete one if we don't save it again below.
+	if (ConfMan.hasKey("restore_target", Common::ConfigManager::kApplicationDomain) &&
+		ConfMan.hasKey("restore_slot", Common::ConfigManager::kApplicationDomain)) {
+		ConfMan.removeKey("restore_target", Common::ConfigManager::kApplicationDomain);
+		ConfMan.removeKey("restore_slot", Common::ConfigManager::kApplicationDomain);
+	}
+
+	// If there is an engine running and it accepts autosave, do an autosave and add the current
+	// running target to the config file.
+	if (g_engine && g_engine->hasFeature(Engine::kSupportsSavingDuringRuntime) && g_engine->canSaveGameStateCurrently()) {
+		if (g_engine->saveGameState(g_engine->getAutosaveSlot(), _("Autosave"), true).getCode() == Common::kNoError) {
+			ConfMan.set("restore_target", ConfMan.getActiveDomainName(), Common::ConfigManager::kApplicationDomain);
+			ConfMan.setInt("restore_slot", g_engine->getAutosaveSlot(), Common::ConfigManager::kApplicationDomain);
+		}
+	}
+
+	ConfMan.flushToDisk();
+}
+
+void OSystem_iOS7::restoreState() {
+	Common::String target;
+	int slot = -1;
+	if (ConfMan.hasKey("restore_target", Common::ConfigManager::kApplicationDomain) &&
+		ConfMan.hasKey("restore_slot", Common::ConfigManager::kApplicationDomain)) {
+		target = ConfMan.get("restore_target", Common::ConfigManager::kApplicationDomain);
+		slot = ConfMan.getInt("restore_slot", Common::ConfigManager::kApplicationDomain);
+		ConfMan.removeKey("restore_target", Common::ConfigManager::kApplicationDomain);
+		ConfMan.removeKey("restore_slot", Common::ConfigManager::kApplicationDomain);
+		ConfMan.flushToDisk();
+	}
+
+	// If the g_engine is still running (i.e. the application was not terminated) we don't need to do anything.
+	if (g_engine)
+		return;
+
+	if (!target.empty() && slot != -1) {
+		ConfMan.setInt("save_slot", slot, Common::ConfigManager::kTransientDomain);
+		ConfMan.setActiveDomain(target);
+		if (GUI::GuiManager::hasInstance())
+			g_gui.exitLoop();
+	}
+}
+
 uint32 OSystem_iOS7::getMillis(bool skipRecord) {
 	CFTimeInterval timeInSeconds = CACurrentMediaTime();
 	return (uint32) ((timeInSeconds - _startTime) * 1000.0) - _timeSuspended;
diff --git a/backends/platform/ios7/ios7_osys_main.h b/backends/platform/ios7/ios7_osys_main.h
index ff652efeb8..b32ff15f0e 100644
--- a/backends/platform/ios7/ios7_osys_main.h
+++ b/backends/platform/ios7/ios7_osys_main.h
@@ -227,6 +227,8 @@ protected:
 	void dirtyFullScreen();
 	void dirtyFullOverlayScreen();
 	void suspendLoop();
+	void saveState();
+	void restoreState();
 	void drawDirtyRect(const Common::Rect &dirtyRect);
 	void updateMouseTexture();
 	static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB);
@@ -238,6 +240,8 @@ protected:
 	void handleEvent_orientationChanged(int orientation);
 	void handleEvent_applicationSuspended();
 	void handleEvent_applicationResumed();
+	void handleEvent_applicationEnteredBackground();
+	void handleEvent_applicationEnteredForeground();
 
 	bool handleEvent_mouseDown(Common::Event &event, int x, int y);
 	bool handleEvent_mouseUp(Common::Event &event, int x, int y);
diff --git a/backends/platform/ios7/ios7_video.h b/backends/platform/ios7/ios7_video.h
index ca1a0c5efb..733372ffe1 100644
--- a/backends/platform/ios7/ios7_video.h
+++ b/backends/platform/ios7/ios7_video.h
@@ -128,8 +128,9 @@ typedef struct {
 - (BOOL)isKeyboardShown;
 
 - (void)applicationSuspend;
-
 - (void)applicationResume;
+- (void)applicationEnteredBackground;
+- (void)applicationEnteredForeground;
 
 - (bool)fetchEvent:(InternalEvent *)event;
 
diff --git a/backends/platform/ios7/ios7_video.mm b/backends/platform/ios7/ios7_video.mm
index fa506d0ecf..5973f12564 100644
--- a/backends/platform/ios7/ios7_video.mm
+++ b/backends/platform/ios7/ios7_video.mm
@@ -1107,4 +1107,12 @@ uint getSizeNextPOT(uint size) {
 	[self addEvent:InternalEvent(kInputApplicationResumed, 0, 0)];
 }
 
+- (void)applicationEnteredBackground {
+	[self addEvent:InternalEvent(kInputApplicationEnteredBackground, 0, 0)];
+}
+
+- (void)applicationEnteredForeground {
+	[self addEvent:InternalEvent(kInputApplicationEnteredForeground, 0, 0)];
+}
+
 @end


Commit: 63627dc26dda8cb4a1ace1409752fd430d12ac72
    https://github.com/scummvm/scummvm/commit/63627dc26dda8cb4a1ace1409752fd430d12ac72
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:21:35+01:00

Commit Message:
IOS7: Save state as a background task when entering background

This is better than using an hardcoded delay for two main reasons.
The first one is that the application can terminate as soon as it
has finished saving the state, and the second one is that it will
still work if saving the state takes longer than the delay that
was hardcoded.

Changed paths:
    backends/platform/ios7/ios7_app_delegate.mm
    backends/platform/ios7/ios7_osys_events.cpp
    backends/platform/ios7/ios7_osys_main.cpp
    backends/platform/ios7/ios7_osys_misc.mm
    backends/platform/ios7/ios7_video.h
    backends/platform/ios7/ios7_video.mm


diff --git a/backends/platform/ios7/ios7_app_delegate.mm b/backends/platform/ios7/ios7_app_delegate.mm
index 6a09f549ef..b6ad5b03a8 100644
--- a/backends/platform/ios7/ios7_app_delegate.mm
+++ b/backends/platform/ios7/ios7_app_delegate.mm
@@ -87,11 +87,12 @@
 }
 
 - (void)applicationDidEnterBackground:(UIApplication *)application {
+	// Start the background task before sending the application entered background event.
+	// This is because this event will be handled in a separate thread and it will likely
+	// no be started before we return from this function.
+	[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
+
 	[_view applicationEnteredBackground];
-	// Add a delay so that the app continues running and gives time for the scummvm thread to
-	// poll the events and call saveState(). The application says we have 5 seconds to do things
-	// in this function before the app is terminated. Wait 2 seconds as it should be sufficient.
-	usleep(2000000);
 }
 
 - (void)applicationWillEnterForeground:(UIApplication *)application {
diff --git a/backends/platform/ios7/ios7_osys_events.cpp b/backends/platform/ios7/ios7_osys_events.cpp
index de59f06985..ec566002cd 100644
--- a/backends/platform/ios7/ios7_osys_events.cpp
+++ b/backends/platform/ios7/ios7_osys_events.cpp
@@ -393,14 +393,6 @@ void OSystem_iOS7::handleEvent_applicationResumed() {
 	rebuildSurface();
 }
 
-void OSystem_iOS7::handleEvent_applicationEnteredBackground() {
-	saveState();
-}
-
-void OSystem_iOS7::handleEvent_applicationEnteredForeground() {
-	restoreState();
-}
-
 void  OSystem_iOS7::handleEvent_keyPressed(Common::Event &event, int keyPressed) {
 	int ascii = keyPressed;
 	//printf("key: %i\n", keyPressed);
diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp
index 1d25009346..77bd37f057 100644
--- a/backends/platform/ios7/ios7_osys_main.cpp
+++ b/backends/platform/ios7/ios7_osys_main.cpp
@@ -246,9 +246,9 @@ void OSystem_iOS7::suspendLoop() {
 			if (event.type == kInputApplicationResumed)
 				done = true;
 			else if (event.type == kInputApplicationEnteredBackground)
-				saveState();
+				handleEvent_applicationEnteredBackground();
 			else if (event.type == kInputApplicationEnteredForeground)
-				restoreState();
+				handleEvent_applicationEnteredForeground();
 		}
 		usleep(100000);
 	}
diff --git a/backends/platform/ios7/ios7_osys_misc.mm b/backends/platform/ios7/ios7_osys_misc.mm
index 26fe66cf74..7be836d135 100644
--- a/backends/platform/ios7/ios7_osys_misc.mm
+++ b/backends/platform/ios7/ios7_osys_misc.mm
@@ -28,6 +28,8 @@
 #include <UIKit/UIKit.h>
 #include <SystemConfiguration/SCNetworkReachability.h>
 #include "common/translation.h"
+#include "backends/platform/ios7/ios7_app_delegate.h"
+#include "backends/platform/ios7/ios7_video.h"
 
 static inline void execute_on_main_thread_async(void (^block)(void)) {
 	if ([NSThread currentThread] == [NSThread mainThread]) {
@@ -119,3 +121,13 @@ bool OSystem_iOS7::isConnectionLimited() {
 	CFRelease(ref);
 	return (flags & kSCNetworkReachabilityFlagsIsWWAN);
 }
+
+void OSystem_iOS7::handleEvent_applicationEnteredBackground() {
+	[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
+	saveState();
+	[[iOS7AppDelegate iPhoneView] endBackgroundSaveStateTask];
+}
+
+void OSystem_iOS7::handleEvent_applicationEnteredForeground() {
+	restoreState();
+}
diff --git a/backends/platform/ios7/ios7_video.h b/backends/platform/ios7/ios7_video.h
index 733372ffe1..1ed79f1f98 100644
--- a/backends/platform/ios7/ios7_video.h
+++ b/backends/platform/ios7/ios7_video.h
@@ -50,6 +50,8 @@ typedef struct {
 	SoftKeyboard *_keyboardView;
 	BOOL _keyboardVisible;
 
+	UIBackgroundTaskIdentifier _backgroundSaveStateTask;
+
 	EAGLContext *_context;
 	GLuint _viewRenderbuffer;
 	GLuint _viewFramebuffer;
@@ -132,6 +134,9 @@ typedef struct {
 - (void)applicationEnteredBackground;
 - (void)applicationEnteredForeground;
 
+- (void) beginBackgroundSaveStateTask;
+- (void) endBackgroundSaveStateTask;
+
 - (bool)fetchEvent:(InternalEvent *)event;
 
 @end
diff --git a/backends/platform/ios7/ios7_video.mm b/backends/platform/ios7/ios7_video.mm
index 5973f12564..cdc13dc228 100644
--- a/backends/platform/ios7/ios7_video.mm
+++ b/backends/platform/ios7/ios7_video.mm
@@ -421,6 +421,8 @@ uint getSizeNextPOT(uint size) {
 - (id)initWithFrame:(struct CGRect)frame {
 	self = [super initWithFrame: frame];
 
+	_backgroundSaveStateTask = UIBackgroundTaskInvalid;
+
 #if defined(USE_SCALERS) || defined(USE_HQ_SCALERS)
 	InitScalers(565);
 #endif
@@ -1115,4 +1117,19 @@ uint getSizeNextPOT(uint size) {
 	[self addEvent:InternalEvent(kInputApplicationEnteredForeground, 0, 0)];
 }
 
+- (void) beginBackgroundSaveStateTask {
+	if (_backgroundSaveStateTask == UIBackgroundTaskInvalid) {
+		_backgroundSaveStateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
+			[self endBackgroundSaveStateTask];
+		}];
+	}
+}
+
+- (void) endBackgroundSaveStateTask {
+	if (_backgroundSaveStateTask != UIBackgroundTaskInvalid) {
+		[[UIApplication sharedApplication] endBackgroundTask: _backgroundSaveStateTask];
+		_backgroundSaveStateTask = UIBackgroundTaskInvalid;
+	}
+}
+
 @end


Commit: c50ffd74c69f6553889e5560b71c2f61dd1fd318
    https://github.com/scummvm/scummvm/commit/c50ffd74c69f6553889e5560b71c2f61dd1fd318
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:21:36+01:00

Commit Message:
IOS7: Properly restore state when the process has been terminated

Changed paths:
    backends/platform/ios7/ios7_app_delegate.mm
    backends/platform/ios7/ios7_common.h
    backends/platform/ios7/ios7_osys_events.cpp
    backends/platform/ios7/ios7_osys_main.cpp
    backends/platform/ios7/ios7_osys_main.h
    backends/platform/ios7/ios7_osys_misc.mm
    backends/platform/ios7/ios7_video.h
    backends/platform/ios7/ios7_video.mm


diff --git a/backends/platform/ios7/ios7_app_delegate.mm b/backends/platform/ios7/ios7_app_delegate.mm
index b6ad5b03a8..eeea48b4ed 100644
--- a/backends/platform/ios7/ios7_app_delegate.mm
+++ b/backends/platform/ios7/ios7_app_delegate.mm
@@ -29,12 +29,14 @@
 	UIWindow *_window;
 	iOS7ScummVMViewController *_controller;
 	iPhoneView *_view;
+	BOOL _restoreState;
 }
 
 - (id)init {
 	if (self = [super init]) {
 		_window = nil;
 		_view = nil;
+		_restoreState = NO;
 	}
 	return self;
 }
@@ -76,6 +78,11 @@
 	dispatch_async(dispatch_get_global_queue(0, 0), ^{
 		iOS7_main(iOS7_argc, iOS7_argv);
 	});
+	
+	if (_restoreState)
+		[_view restoreApplicationState];
+	else
+		[_view clearApplicationState];
 }
 
 - (void)applicationWillResignActive:(UIApplication *)application {
@@ -92,11 +99,19 @@
 	// no be started before we return from this function.
 	[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
 
-	[_view applicationEnteredBackground];
+	[_view saveApplicationState];
 }
 
-- (void)applicationWillEnterForeground:(UIApplication *)application {
-	[_view applicationEnteredForeground];
+- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder {
+	return YES;
+}
+
+- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder {
+	return YES;
+}
+
+- (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder {
+	_restoreState = YES;
 }
 
 - (void)didRotate:(NSNotification *)notification {
diff --git a/backends/platform/ios7/ios7_common.h b/backends/platform/ios7/ios7_common.h
index 44ddf75200..1d3d3fbfdd 100644
--- a/backends/platform/ios7/ios7_common.h
+++ b/backends/platform/ios7/ios7_common.h
@@ -39,8 +39,9 @@ enum InputEvent {
 	kInputKeyPressed,
 	kInputApplicationSuspended,
 	kInputApplicationResumed,
-	kInputApplicationEnteredBackground,
-	kInputApplicationEnteredForeground,
+	kInputApplicationSaveState,
+	kInputApplicationClearState,
+	kInputApplicationRestoreState,
 	kInputSwipe,
 	kInputTap,
 	kInputMainMenu
diff --git a/backends/platform/ios7/ios7_osys_events.cpp b/backends/platform/ios7/ios7_osys_events.cpp
index ec566002cd..30d32d857d 100644
--- a/backends/platform/ios7/ios7_osys_events.cpp
+++ b/backends/platform/ios7/ios7_osys_events.cpp
@@ -77,12 +77,16 @@ bool OSystem_iOS7::pollEvent(Common::Event &event) {
 			handleEvent_applicationResumed();
 			return false;
 
-		case kInputApplicationEnteredBackground:
-			handleEvent_applicationEnteredBackground();
+		case kInputApplicationSaveState:
+			handleEvent_applicationSaveState();
 			return false;
 
-		case kInputApplicationEnteredForeground:
-			handleEvent_applicationEnteredForeground();
+		case kInputApplicationRestoreState:
+			handleEvent_applicationRestoreState();
+			return false;
+
+		case kInputApplicationClearState:
+			handleEvent_applicationClearState();
 			return false;
 
 		case kInputMouseSecondDragged:
diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp
index 77bd37f057..e1e2444f13 100644
--- a/backends/platform/ios7/ios7_osys_main.cpp
+++ b/backends/platform/ios7/ios7_osys_main.cpp
@@ -245,10 +245,8 @@ void OSystem_iOS7::suspendLoop() {
 		if (iOS7_fetchEvent(&event)) {
 			if (event.type == kInputApplicationResumed)
 				done = true;
-			else if (event.type == kInputApplicationEnteredBackground)
-				handleEvent_applicationEnteredBackground();
-			else if (event.type == kInputApplicationEnteredForeground)
-				handleEvent_applicationEnteredForeground();
+			else if (event.type == kInputApplicationSaveState)
+				handleEvent_applicationSaveState();
 		}
 		usleep(100000);
 	}
@@ -260,11 +258,7 @@ void OSystem_iOS7::suspendLoop() {
 
 void OSystem_iOS7::saveState() {
 	// Clear any previous restore state to avoid having and obsolete one if we don't save it again below.
-	if (ConfMan.hasKey("restore_target", Common::ConfigManager::kApplicationDomain) &&
-		ConfMan.hasKey("restore_slot", Common::ConfigManager::kApplicationDomain)) {
-		ConfMan.removeKey("restore_target", Common::ConfigManager::kApplicationDomain);
-		ConfMan.removeKey("restore_slot", Common::ConfigManager::kApplicationDomain);
-	}
+	clearState();
 
 	// If there is an engine running and it accepts autosave, do an autosave and add the current
 	// running target to the config file.
@@ -285,9 +279,7 @@ void OSystem_iOS7::restoreState() {
 		ConfMan.hasKey("restore_slot", Common::ConfigManager::kApplicationDomain)) {
 		target = ConfMan.get("restore_target", Common::ConfigManager::kApplicationDomain);
 		slot = ConfMan.getInt("restore_slot", Common::ConfigManager::kApplicationDomain);
-		ConfMan.removeKey("restore_target", Common::ConfigManager::kApplicationDomain);
-		ConfMan.removeKey("restore_slot", Common::ConfigManager::kApplicationDomain);
-		ConfMan.flushToDisk();
+		clearState();
 	}
 
 	// If the g_engine is still running (i.e. the application was not terminated) we don't need to do anything.
@@ -302,6 +294,15 @@ void OSystem_iOS7::restoreState() {
 	}
 }
 
+void OSystem_iOS7::clearState() {
+	if (ConfMan.hasKey("restore_target", Common::ConfigManager::kApplicationDomain) &&
+	ConfMan.hasKey("restore_slot", Common::ConfigManager::kApplicationDomain)) {
+		ConfMan.removeKey("restore_target", Common::ConfigManager::kApplicationDomain);
+		ConfMan.removeKey("restore_slot", Common::ConfigManager::kApplicationDomain);
+		ConfMan.flushToDisk();
+	}
+}
+
 uint32 OSystem_iOS7::getMillis(bool skipRecord) {
 	CFTimeInterval timeInSeconds = CACurrentMediaTime();
 	return (uint32) ((timeInSeconds - _startTime) * 1000.0) - _timeSuspended;
diff --git a/backends/platform/ios7/ios7_osys_main.h b/backends/platform/ios7/ios7_osys_main.h
index b32ff15f0e..b6525d36fc 100644
--- a/backends/platform/ios7/ios7_osys_main.h
+++ b/backends/platform/ios7/ios7_osys_main.h
@@ -229,6 +229,7 @@ protected:
 	void suspendLoop();
 	void saveState();
 	void restoreState();
+	void clearState();
 	void drawDirtyRect(const Common::Rect &dirtyRect);
 	void updateMouseTexture();
 	static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB);
@@ -240,8 +241,9 @@ protected:
 	void handleEvent_orientationChanged(int orientation);
 	void handleEvent_applicationSuspended();
 	void handleEvent_applicationResumed();
-	void handleEvent_applicationEnteredBackground();
-	void handleEvent_applicationEnteredForeground();
+	void handleEvent_applicationSaveState();
+	void handleEvent_applicationRestoreState();
+	void handleEvent_applicationClearState();
 
 	bool handleEvent_mouseDown(Common::Event &event, int x, int y);
 	bool handleEvent_mouseUp(Common::Event &event, int x, int y);
diff --git a/backends/platform/ios7/ios7_osys_misc.mm b/backends/platform/ios7/ios7_osys_misc.mm
index 7be836d135..6693715f15 100644
--- a/backends/platform/ios7/ios7_osys_misc.mm
+++ b/backends/platform/ios7/ios7_osys_misc.mm
@@ -122,12 +122,16 @@ bool OSystem_iOS7::isConnectionLimited() {
 	return (flags & kSCNetworkReachabilityFlagsIsWWAN);
 }
 
-void OSystem_iOS7::handleEvent_applicationEnteredBackground() {
+void OSystem_iOS7::handleEvent_applicationSaveState() {
 	[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
 	saveState();
 	[[iOS7AppDelegate iPhoneView] endBackgroundSaveStateTask];
 }
 
-void OSystem_iOS7::handleEvent_applicationEnteredForeground() {
+void OSystem_iOS7::handleEvent_applicationRestoreState() {
 	restoreState();
 }
+
+void OSystem_iOS7::handleEvent_applicationClearState() {
+	clearState();
+}
diff --git a/backends/platform/ios7/ios7_video.h b/backends/platform/ios7/ios7_video.h
index 1ed79f1f98..a8d0d6b064 100644
--- a/backends/platform/ios7/ios7_video.h
+++ b/backends/platform/ios7/ios7_video.h
@@ -131,8 +131,10 @@ typedef struct {
 
 - (void)applicationSuspend;
 - (void)applicationResume;
-- (void)applicationEnteredBackground;
-- (void)applicationEnteredForeground;
+
+- (void)saveApplicationState;
+- (void)clearApplicationState;
+- (void)restoreApplicationState;
 
 - (void) beginBackgroundSaveStateTask;
 - (void) endBackgroundSaveStateTask;
diff --git a/backends/platform/ios7/ios7_video.mm b/backends/platform/ios7/ios7_video.mm
index cdc13dc228..cad34d97a5 100644
--- a/backends/platform/ios7/ios7_video.mm
+++ b/backends/platform/ios7/ios7_video.mm
@@ -1109,12 +1109,16 @@ uint getSizeNextPOT(uint size) {
 	[self addEvent:InternalEvent(kInputApplicationResumed, 0, 0)];
 }
 
-- (void)applicationEnteredBackground {
-	[self addEvent:InternalEvent(kInputApplicationEnteredBackground, 0, 0)];
+- (void)saveApplicationState {
+	[self addEvent:InternalEvent(kInputApplicationSaveState, 0, 0)];
 }
 
-- (void)applicationEnteredForeground {
-	[self addEvent:InternalEvent(kInputApplicationEnteredForeground, 0, 0)];
+- (void)clearApplicationState {
+	[self addEvent:InternalEvent(kInputApplicationClearState, 0, 0)];
+}
+
+- (void)restoreApplicationState {
+	[self addEvent:InternalEvent(kInputApplicationRestoreState, 0, 0)];
 }
 
 - (void) beginBackgroundSaveStateTask {


Commit: 53bb50c906ed0da7fbc70eba61309292a5e6dd42
    https://github.com/scummvm/scummvm/commit/53bb50c906ed0da7fbc70eba61309292a5e6dd42
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:21:36+01:00

Commit Message:
IOS7: Do not overwrite user saves when saving state

Changed paths:
    backends/platform/ios7/ios7_osys_main.cpp


diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp
index e1e2444f13..8cfd766918 100644
--- a/backends/platform/ios7/ios7_osys_main.cpp
+++ b/backends/platform/ios7/ios7_osys_main.cpp
@@ -41,6 +41,7 @@
 #include "base/main.h"
 
 #include "engines/engine.h"
+#include "engines/metaengine.h"
 
 #include "gui/gui-manager.h"
 
@@ -262,14 +263,21 @@ void OSystem_iOS7::saveState() {
 
 	// If there is an engine running and it accepts autosave, do an autosave and add the current
 	// running target to the config file.
-	if (g_engine && g_engine->hasFeature(Engine::kSupportsSavingDuringRuntime) && g_engine->canSaveGameStateCurrently()) {
-		if (g_engine->saveGameState(g_engine->getAutosaveSlot(), _("Autosave"), true).getCode() == Common::kNoError) {
-			ConfMan.set("restore_target", ConfMan.getActiveDomainName(), Common::ConfigManager::kApplicationDomain);
-			ConfMan.setInt("restore_slot", g_engine->getAutosaveSlot(), Common::ConfigManager::kApplicationDomain);
+	if (g_engine && g_engine->hasFeature(Engine::kSupportsSavingDuringRuntime) && g_engine->canSaveAutosaveCurrently()) {
+		Common::String targetName(ConfMan.getActiveDomainName());
+		int saveSlot = g_engine->getAutosaveSlot();
+		// Make sure we do not overwrite a user save
+		SaveStateDescriptor desc = g_engine->getMetaEngine().querySaveMetaInfos(targetName.c_str(), saveSlot);
+		if (desc.getSaveSlot() != -1 && !desc.isAutosave())
+			return;
+
+		// Do the auto-save, and if successful store this it in the config
+		if (g_engine->saveGameState(saveSlot, _("Autosave"), true).getCode() == Common::kNoError) {
+			ConfMan.set("restore_target", targetName, Common::ConfigManager::kApplicationDomain);
+			ConfMan.setInt("restore_slot", saveSlot, Common::ConfigManager::kApplicationDomain);
+			ConfMan.flushToDisk();
 		}
 	}
-
-	ConfMan.flushToDisk();
 }
 
 void OSystem_iOS7::restoreState() {




More information about the Scummvm-git-logs mailing list