[Scummvm-git-logs] scummvm branch-2-2 -> 4822404de3b1c95c6a13bee206e09004edb97b56
criezy
criezy at scummvm.org
Sat Sep 12 23:47:09 UTC 2020
This automated email contains information about 7 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f767b6ccfb GUI: Add exitLoop() method to GuiManager
4f8e07773c IOS7: Call pauseEngine() when suspending the application
97af5542b1 IOS7: Implement game state save/restore when switching tasks
ecaa8e5440 IOS7: Save state as a background task when entering background
947db98d9b IOS7: Properly restore state when the process has been terminated
9b0b470987 IOS7: Do not overwrite user saves when saving state
4822404de3 NEWS: Mention game state save and restore on iOS when switching tasks
Commit: f767b6ccfb2640095523d2bc5f3d349f66282a0b
https://github.com/scummvm/scummvm/commit/f767b6ccfb2640095523d2bc5f3d349f66282a0b
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:46:31+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 a8e88a4be2..3752dde49c 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: 4f8e07773c836e2d77224309a4a187f1640a3525
https://github.com/scummvm/scummvm/commit/4f8e07773c836e2d77224309a4a187f1640a3525
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:46:31+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: 97af5542b151031726aa597bc84b9cf5afbfe2e0
https://github.com/scummvm/scummvm/commit/97af5542b151031726aa597bc84b9cf5afbfe2e0
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:46:31+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 0387503739..4e07798104 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 6319ef5ce3..097f62292a 100644
--- a/backends/platform/ios7/ios7_osys_main.h
+++ b/backends/platform/ios7/ios7_osys_main.h
@@ -226,6 +226,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);
@@ -237,6 +239,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: ecaa8e54408dd7fe5ec87fc27052f406c7166362
https://github.com/scummvm/scummvm/commit/ecaa8e54408dd7fe5ec87fc27052f406c7166362
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:46:32+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 4e07798104..c29f2beb87 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 1f9232c12e..3634b583ce 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]) {
@@ -108,3 +110,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: 947db98d9bdf7564e974eaa8f1228f384d98ae76
https://github.com/scummvm/scummvm/commit/947db98d9bdf7564e974eaa8f1228f384d98ae76
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:46:32+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 c29f2beb87..2c6a656d8e 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 097f62292a..a7aef2de31 100644
--- a/backends/platform/ios7/ios7_osys_main.h
+++ b/backends/platform/ios7/ios7_osys_main.h
@@ -228,6 +228,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);
@@ -239,8 +240,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 3634b583ce..8cee4a50f2 100644
--- a/backends/platform/ios7/ios7_osys_misc.mm
+++ b/backends/platform/ios7/ios7_osys_misc.mm
@@ -111,12 +111,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: 9b0b4709879f04137d4238380a50d94913d0ed30
https://github.com/scummvm/scummvm/commit/9b0b4709879f04137d4238380a50d94913d0ed30
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:46:32+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() {
Commit: 4822404de3b1c95c6a13bee206e09004edb97b56
https://github.com/scummvm/scummvm/commit/4822404de3b1c95c6a13bee206e09004edb97b56
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-09-13T00:46:32+01:00
Commit Message:
NEWS: Mention game state save and restore on iOS when switching tasks
Changed paths:
NEWS.md
diff --git a/NEWS.md b/NEWS.md
index 3b74e0761f..d95f702b40 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -130,6 +130,8 @@ For a more comprehensive changelog of the latest experimental code, see:
- Removed Quit button to follow the iOS design guidelines.
- Removed virtual keyboard input assistant bar. In particular this means that we
no longer see a bar at the bottom of the screen when using an external keyboard.
+ - Added save of current game state if possible when switching to a different task
+ and restore game state when returning to the ScummVM task.
Linux port:
- Added option to use the system file browser instead of the ScummVM file browser.
More information about the Scummvm-git-logs
mailing list