[Android] Handle end emulation better

This commit is contained in:
zilmar 2016-08-11 20:23:56 +10:00
parent 78a89f4bde
commit 084cdaef52
1 changed files with 43 additions and 32 deletions

View File

@ -47,7 +47,7 @@ import android.view.WindowManager.LayoutParams;
public class GameLifecycleHandler implements SurfaceHolder.Callback, GameSurface.SurfaceInfo public class GameLifecycleHandler implements SurfaceHolder.Callback, GameSurface.SurfaceInfo
{ {
private final static boolean LOG_GAMELIFECYCLEHANDLER = true; private final static boolean LOG_GAMELIFECYCLEHANDLER = false;
// Activity and views // Activity and views
private Activity mActivity; private Activity mActivity;
@ -214,6 +214,14 @@ public class GameLifecycleHandler implements SurfaceHolder.Callback, GameSurface
} }
if (NativeExports.SettingsLoadBool(SettingsID.GameRunning_CPU_Running.getValue()) == true) if (NativeExports.SettingsLoadBool(SettingsID.GameRunning_CPU_Running.getValue()) == true)
{ {
Boolean pause = false;
int PauseType = 0;
if (NativeExports.SettingsLoadBool(SettingsID.GameRunning_CPU_Paused.getValue()) == true)
{
pause = true;
PauseType = NativeExports.SettingsLoadDword(SettingsID.GameRunning_CPU_PausedType.getValue());
NativeExports.ExternalEvent( SystemEvent.SysEvent_ResumeCPU_FromMenu.getValue());
}
int CurrentSaveState = NativeExports.SettingsLoadDword(SettingsID.Game_CurrentSaveState.getValue()); int CurrentSaveState = NativeExports.SettingsLoadDword(SettingsID.Game_CurrentSaveState.getValue());
int OriginalSaveTime = NativeExports.SettingsLoadDword(SettingsID.Game_LastSaveTime.getValue()); int OriginalSaveTime = NativeExports.SettingsLoadDword(SettingsID.Game_LastSaveTime.getValue());
NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0);
@ -221,6 +229,10 @@ public class GameLifecycleHandler implements SurfaceHolder.Callback, GameSurface
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
int LastSaveTime = NativeExports.SettingsLoadDword(SettingsID.Game_LastSaveTime.getValue()); int LastSaveTime = NativeExports.SettingsLoadDword(SettingsID.Game_LastSaveTime.getValue());
if (LOG_GAMELIFECYCLEHANDLER)
{
Log.i("GameLifecycleHandler", "LastSaveTime = " + LastSaveTime + " OriginalSaveTime = " + OriginalSaveTime);
}
if (LastSaveTime != OriginalSaveTime) if (LastSaveTime != OriginalSaveTime)
{ {
break; break;
@ -235,6 +247,11 @@ public class GameLifecycleHandler implements SurfaceHolder.Callback, GameSurface
} }
} }
NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), CurrentSaveState); NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), CurrentSaveState);
if (pause)
{
NativeExports.ExternalEvent( SystemEvent.SysEvent_PauseCPU_FromMenu.getValue());
NativeExports.SettingsSaveDword(SettingsID.GameRunning_CPU_PausedType.getValue(), PauseType);
}
} }
else if (LOG_GAMELIFECYCLEHANDLER) else if (LOG_GAMELIFECYCLEHANDLER)
{ {
@ -254,15 +271,9 @@ public class GameLifecycleHandler implements SurfaceHolder.Callback, GameSurface
Log.i("GameLifecycleHandler", "onPause"); Log.i("GameLifecycleHandler", "onPause");
} }
mIsResumed = false; mIsResumed = false;
mStopped = true;
if (NativeExports.SettingsLoadBool(SettingsID.GameRunning_CPU_Running.getValue()) == true) if (NativeExports.SettingsLoadBool(SettingsID.GameRunning_CPU_Running.getValue()) == true)
{ {
AutoSave(); AutoSave();
if (LOG_GAMELIFECYCLEHANDLER)
{
Log.i("GameLifecycleHandler", "Stop Emulation");
}
NativeExports.StopEmulation();
} }
if (LOG_GAMELIFECYCLEHANDLER) if (LOG_GAMELIFECYCLEHANDLER)
{ {