diff options
| author | JosJuice <josjuice@gmail.com> | 2021-08-08 15:01:12 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2021-09-21 16:34:00 +0200 |
| commit | 53d7d595e694eab21eae2e44f988242063518598 (patch) | |
| tree | 01e4f1672b75af20c1d3203c40b26edd27ebfb03 /Source/Android/app/src/main/java | |
| parent | 2cd09b8eb3bdc39f455f47c40ce165c7965b74e3 (diff) | |
Android: Remove the EmulationState class
The purpose of this class was to keep track of state which the
emulation core was already keeping track of. This is rather risky -
if we update the state of one of the two without updating the other,
the two become out of sync, leading to some rather confusing problems.
This duplicated state was removed from EmulationState in the
previous commits, so now there isn't much left in the class.
Might as well move its members directly into EmulationFragment.
Diffstat (limited to 'Source/Android/app/src/main/java')
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java | 127 |
1 files changed, 54 insertions, 73 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java index aecf2c8a83..4e9e864137 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java @@ -32,7 +32,9 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C private InputOverlay mInputOverlay; - private EmulationState mEmulationState; + private String[] mGamePaths; + private boolean mRunWhenSurfaceIsValid; + private boolean mLoadPreviousTemporaryState; private EmulationActivity activity; @@ -73,8 +75,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C // So this fragment doesn't restart on configuration changes; i.e. rotation. setRetainInstance(true); - String[] gamePaths = getArguments().getStringArray(KEY_GAMEPATHS); - mEmulationState = new EmulationState(gamePaths, getTemporaryStateFilePath()); + mGamePaths = getArguments().getStringArray(KEY_GAMEPATHS); } /** @@ -117,7 +118,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C public void onResume() { super.onResume(); - mEmulationState.run(activity.isActivityRecreated()); + run(activity.isActivityRecreated()); } @Override @@ -178,7 +179,10 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C { Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height); NativeLibrary.SurfaceChanged(holder.getSurface()); - mEmulationState.newSurface(); + if (mRunWhenSurfaceIsValid) + { + runWithValidSurface(); + } } @Override @@ -218,91 +222,68 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C return mInputOverlay != null && mInputOverlay.isInEditMode(); } - private static class EmulationState + private void run(boolean isActivityRecreated) { - private final String[] mGamePaths; - private boolean mRunWhenSurfaceIsValid; - private boolean loadPreviousTemporaryState; - private final String temporaryStatePath; - - EmulationState(String[] gamePaths, String temporaryStatePath) - { - mGamePaths = gamePaths; - this.temporaryStatePath = temporaryStatePath; - } - - public void run(boolean isActivityRecreated) + if (isActivityRecreated) { - if (isActivityRecreated) + if (NativeLibrary.IsRunning()) { - if (NativeLibrary.IsRunning()) - { - loadPreviousTemporaryState = false; - deleteFile(temporaryStatePath); - } - else - { - loadPreviousTemporaryState = true; - } + mLoadPreviousTemporaryState = false; + deleteFile(getTemporaryStateFilePath()); } else { - Log.debug("[EmulationFragment] activity resumed or fresh start"); - loadPreviousTemporaryState = false; - // activity resumed without being killed or this is the first run - deleteFile(temporaryStatePath); - } - - // If the surface is set, run now. Otherwise, wait for it to get set. - if (NativeLibrary.HasSurface()) - { - runWithValidSurface(); - } - else - { - mRunWhenSurfaceIsValid = true; + mLoadPreviousTemporaryState = true; } } + else + { + Log.debug("[EmulationFragment] activity resumed or fresh start"); + mLoadPreviousTemporaryState = false; + // activity resumed without being killed or this is the first run + deleteFile(getTemporaryStateFilePath()); + } - public void newSurface() + // If the surface is set, run now. Otherwise, wait for it to get set. + if (NativeLibrary.HasSurface()) { - if (mRunWhenSurfaceIsValid) - { - runWithValidSurface(); - } + runWithValidSurface(); + } + else + { + mRunWhenSurfaceIsValid = true; } + } - private void runWithValidSurface() + private void runWithValidSurface() + { + mRunWhenSurfaceIsValid = false; + if (!NativeLibrary.IsRunning()) { - mRunWhenSurfaceIsValid = false; - if (!NativeLibrary.IsRunning()) - { - NativeLibrary.SetIsBooting(); + NativeLibrary.SetIsBooting(); - Thread emulationThread = new Thread(() -> - { - if (loadPreviousTemporaryState) - { - Log.debug("[EmulationFragment] Starting emulation thread from previous state."); - NativeLibrary.Run(mGamePaths, temporaryStatePath, true); - } - else - { - Log.debug("[EmulationFragment] Starting emulation thread."); - NativeLibrary.Run(mGamePaths); - } - EmulationActivity.stopIgnoringLaunchRequests(); - }, "NativeEmulation"); - emulationThread.start(); - } - else + Thread emulationThread = new Thread(() -> { - if (!EmulationActivity.getHasUserPausedEmulation() && - !NativeLibrary.IsShowingAlertMessage()) + if (mLoadPreviousTemporaryState) + { + Log.debug("[EmulationFragment] Starting emulation thread from previous state."); + NativeLibrary.Run(mGamePaths, getTemporaryStateFilePath(), true); + } + else { - Log.debug("[EmulationFragment] Resuming emulation."); - NativeLibrary.UnPauseEmulation(); + Log.debug("[EmulationFragment] Starting emulation thread."); + NativeLibrary.Run(mGamePaths); } + EmulationActivity.stopIgnoringLaunchRequests(); + }, "NativeEmulation"); + emulationThread.start(); + } + else + { + if (!EmulationActivity.getHasUserPausedEmulation() && !NativeLibrary.IsShowingAlertMessage()) + { + Log.debug("[EmulationFragment] Resuming emulation."); + NativeLibrary.UnPauseEmulation(); } } } |
