mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
Android: Remove state from EmulationState
This commit is contained in:
parent
2c564a0b9d
commit
446e2d9119
@ -410,6 +410,13 @@ public final class NativeLibrary
|
|||||||
*/
|
*/
|
||||||
public static native void StopEmulation();
|
public static native void StopEmulation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that IsRunning will return true from now on until emulation exits.
|
||||||
|
* (If this is not called, IsRunning will start returning true at some point
|
||||||
|
* after calling Run.)
|
||||||
|
*/
|
||||||
|
public static native void SetIsBooting();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if emulation is running (or is paused).
|
* Returns true if emulation is running (or is paused).
|
||||||
*/
|
*/
|
||||||
@ -417,6 +424,8 @@ public final class NativeLibrary
|
|||||||
|
|
||||||
public static native boolean IsRunningAndStarted();
|
public static native boolean IsRunningAndStarted();
|
||||||
|
|
||||||
|
public static native boolean IsRunningAndUnpaused();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables CPU block profiling
|
* Enables or disables CPU block profiling
|
||||||
*
|
*
|
||||||
|
@ -123,8 +123,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
@Override
|
@Override
|
||||||
public void onPause()
|
public void onPause()
|
||||||
{
|
{
|
||||||
if (mEmulationState.isRunning() && !NativeLibrary.IsShowingAlertMessage())
|
if (NativeLibrary.IsRunningAndUnpaused() && !NativeLibrary.IsShowingAlertMessage())
|
||||||
mEmulationState.pause();
|
{
|
||||||
|
Log.debug("[EmulationFragment] Pausing emulation.");
|
||||||
|
NativeLibrary.PauseEmulation();
|
||||||
|
}
|
||||||
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +190,8 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
|
|
||||||
public void stopEmulation()
|
public void stopEmulation()
|
||||||
{
|
{
|
||||||
mEmulationState.stop();
|
Log.debug("[EmulationFragment] Stopping emulation.");
|
||||||
|
NativeLibrary.StopEmulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startConfiguringControls()
|
public void startConfiguringControls()
|
||||||
@ -214,13 +219,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
|
|
||||||
private static class EmulationState
|
private static class EmulationState
|
||||||
{
|
{
|
||||||
private enum State
|
|
||||||
{
|
|
||||||
STOPPED, RUNNING, PAUSED
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String[] mGamePaths;
|
private final String[] mGamePaths;
|
||||||
private State state;
|
|
||||||
private boolean mRunWhenSurfaceIsValid;
|
private boolean mRunWhenSurfaceIsValid;
|
||||||
private boolean loadPreviousTemporaryState;
|
private boolean loadPreviousTemporaryState;
|
||||||
private final String temporaryStatePath;
|
private final String temporaryStatePath;
|
||||||
@ -229,56 +228,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
{
|
{
|
||||||
mGamePaths = gamePaths;
|
mGamePaths = gamePaths;
|
||||||
this.temporaryStatePath = temporaryStatePath;
|
this.temporaryStatePath = temporaryStatePath;
|
||||||
// Starting state is stopped.
|
|
||||||
state = State.STOPPED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters for the current state
|
|
||||||
|
|
||||||
public synchronized boolean isStopped()
|
|
||||||
{
|
|
||||||
return state == State.STOPPED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean isPaused()
|
|
||||||
{
|
|
||||||
return state == State.PAUSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean isRunning()
|
|
||||||
{
|
|
||||||
return state == State.RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// State changing methods
|
|
||||||
|
|
||||||
public synchronized void stop()
|
|
||||||
{
|
|
||||||
if (state != State.STOPPED)
|
|
||||||
{
|
|
||||||
Log.debug("[EmulationFragment] Stopping emulation.");
|
|
||||||
state = State.STOPPED;
|
|
||||||
NativeLibrary.StopEmulation();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.warning("[EmulationFragment] Stop called while already stopped.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void pause()
|
|
||||||
{
|
|
||||||
if (state != State.PAUSED)
|
|
||||||
{
|
|
||||||
state = State.PAUSED;
|
|
||||||
Log.debug("[EmulationFragment] Pausing emulation.");
|
|
||||||
|
|
||||||
NativeLibrary.PauseEmulation();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.warning("[EmulationFragment] Pause called while already paused.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void run(boolean isActivityRecreated)
|
public synchronized void run(boolean isActivityRecreated)
|
||||||
@ -288,7 +237,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
if (NativeLibrary.IsRunning())
|
if (NativeLibrary.IsRunning())
|
||||||
{
|
{
|
||||||
loadPreviousTemporaryState = false;
|
loadPreviousTemporaryState = false;
|
||||||
state = State.PAUSED;
|
|
||||||
deleteFile(temporaryStatePath);
|
deleteFile(temporaryStatePath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -326,8 +274,10 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
private void runWithValidSurface()
|
private void runWithValidSurface()
|
||||||
{
|
{
|
||||||
mRunWhenSurfaceIsValid = false;
|
mRunWhenSurfaceIsValid = false;
|
||||||
if (state == State.STOPPED)
|
if (!NativeLibrary.IsRunning())
|
||||||
{
|
{
|
||||||
|
NativeLibrary.SetIsBooting();
|
||||||
|
|
||||||
Thread emulationThread = new Thread(() ->
|
Thread emulationThread = new Thread(() ->
|
||||||
{
|
{
|
||||||
if (loadPreviousTemporaryState)
|
if (loadPreviousTemporaryState)
|
||||||
@ -344,7 +294,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
}, "NativeEmulation");
|
}, "NativeEmulation");
|
||||||
emulationThread.start();
|
emulationThread.start();
|
||||||
}
|
}
|
||||||
else if (state == State.PAUSED)
|
else
|
||||||
{
|
{
|
||||||
if (!EmulationActivity.getHasUserPausedEmulation() &&
|
if (!EmulationActivity.getHasUserPausedEmulation() &&
|
||||||
!NativeLibrary.IsShowingAlertMessage())
|
!NativeLibrary.IsShowingAlertMessage())
|
||||||
@ -353,11 +303,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
|
|||||||
NativeLibrary.UnPauseEmulation();
|
NativeLibrary.UnPauseEmulation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.debug("[EmulationFragment] Bug, run called while already running.");
|
|
||||||
}
|
|
||||||
state = State.RUNNING;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Event.h"
|
#include "Common/Event.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
#include "Common/Flag.h"
|
||||||
#include "Common/IniFile.h"
|
#include "Common/IniFile.h"
|
||||||
#include "Common/Logging/LogManager.h"
|
#include "Common/Logging/LogManager.h"
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
@ -81,6 +82,7 @@ Common::Event s_update_main_frame_event;
|
|||||||
std::mutex s_surface_lock;
|
std::mutex s_surface_lock;
|
||||||
bool s_need_nonblocking_alert_msg;
|
bool s_need_nonblocking_alert_msg;
|
||||||
|
|
||||||
|
Common::Flag s_is_booting;
|
||||||
bool s_have_wm_user_stop = false;
|
bool s_have_wm_user_stop = false;
|
||||||
bool s_game_metadata_is_valid = false;
|
bool s_game_metadata_is_valid = false;
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
@ -247,9 +249,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulatio
|
|||||||
s_update_main_frame_event.Set();
|
s_update_main_frame_event.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetIsBooting(JNIEnv*, jclass)
|
||||||
|
{
|
||||||
|
s_is_booting.Set();
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass)
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass)
|
||||||
{
|
{
|
||||||
return static_cast<jboolean>(Core::IsRunning());
|
return s_is_booting.IsSet() || static_cast<jboolean>(Core::IsRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndStarted(JNIEnv*,
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndStarted(JNIEnv*,
|
||||||
@ -258,6 +265,12 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunnin
|
|||||||
return static_cast<jboolean>(Core::IsRunningAndStarted());
|
return static_cast<jboolean>(Core::IsRunningAndStarted());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL
|
||||||
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndUnpaused(JNIEnv*, jclass)
|
||||||
|
{
|
||||||
|
return static_cast<jboolean>(Core::GetState() == Core::State::Running);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
||||||
JNIEnv* env, jclass, jstring jDevice, jint Button, jint Action)
|
JNIEnv* env, jclass, jstring jDevice, jint Button, jint Action)
|
||||||
{
|
{
|
||||||
@ -561,6 +574,7 @@ static void Run(JNIEnv* env, const std::vector<std::string>& paths,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s_is_booting.Clear();
|
||||||
s_need_nonblocking_alert_msg = false;
|
s_need_nonblocking_alert_msg = false;
|
||||||
surface_guard.unlock();
|
surface_guard.unlock();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user