diff options
| author | Markus Wick <degasus@users.noreply.github.com> | 2018-01-05 13:45:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-05 13:45:36 +0100 |
| commit | e705d433126e00e3dc39e7a25a182fcd3b555a2b (patch) | |
| tree | d362f74f96adb576fe0bfbff3e8b11cf4236b100 /Source/Android/jni/MainAndroid.cpp | |
| parent | e31f8f8ecb901a81cdf6075ca305032a6ba3366b (diff) | |
| parent | 136e835fb489f2b0412c760739dd5c668055fb56 (diff) | |
Merge pull request #6270 from mahdihijazi/suppport_restore_state
[Android] Support restore emulator state
Diffstat (limited to 'Source/Android/jni/MainAndroid.cpp')
| -rw-r--r-- | Source/Android/jni/MainAndroid.cpp | 73 |
1 files changed, 64 insertions, 9 deletions
diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index c6c40da097..56523d9eb4 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -11,8 +11,10 @@ #include <jni.h> #include <memory> #include <mutex> +#include <optional> #include <string> #include <thread> +#include <utility> #include "ButtonManager.h" @@ -403,6 +405,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulati jobject obj); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv* env, jobject obj); +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv* env, + jobject obj); JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent( JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent( @@ -447,10 +451,18 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetFilename( jstring jFile); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env, jobject obj, - jint slot); + jint slot, + jboolean wait); +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env, + jobject obj, + jstring path, + jboolean wait); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv* env, jobject obj, jint slot); +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env, + jobject obj, + jstring path); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_CreateUserDirectories( JNIEnv* env, jobject obj); @@ -467,8 +479,11 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv* env, jobject obj); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj); -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv* env, jobject obj, - jstring jFile); +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2( + JNIEnv* env, jobject obj, jstring jFile); +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z( + JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate); JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env, jobject obj, jobject surf); @@ -496,11 +511,19 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulatio Core::Stop(); s_update_main_frame_event.Set(); // Kick the waiting event } + +JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv* env, + jobject obj) +{ + return Core::IsRunning(); +} + JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent( JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action) { return ButtonManager::GamepadEvent(GetJString(env, jDevice), Button, Action); } + JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent( JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value) { @@ -643,10 +666,20 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig( JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env, jobject obj, - jint slot) + jint slot, + jboolean wait) { std::lock_guard<std::mutex> guard(s_host_identity_lock); - State::Save(slot); + State::Save(slot, wait); +} + +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env, + jobject obj, + jstring path, + jboolean wait) +{ + std::lock_guard<std::mutex> guard(s_host_identity_lock); + State::SaveAs(GetJString(env, path), wait); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv* env, @@ -657,6 +690,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JN State::Load(slot); } +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env, + jobject obj, + jstring path) +{ + std::lock_guard<std::mutex> guard(s_host_identity_lock); + State::LoadAs(GetJString(env, path)); +} + JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_SetSysDirectory( JNIEnv* env, jobject obj, jstring jPath) @@ -762,10 +803,9 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimo WiimoteReal::Refresh(); } -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv* env, jobject obj, - jstring jFile) +static void Run(const std::string& path, std::optional<std::string> savestate_path = {}, + bool delete_savestate = false) { - const std::string path = GetJString(env, jFile); __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", path.c_str()); // Install our callbacks @@ -781,7 +821,9 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv* // No use running the loop when booting fails s_have_wm_user_stop = false; - if (BootManager::BootCore(BootParameters::GenerateFromFile(path))) + std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(path, savestate_path); + boot->delete_savestate = delete_savestate; + if (BootManager::BootCore(std::move(boot))) { static constexpr int TIMEOUT = 10000; static constexpr int WAIT_STEP = 25; @@ -812,6 +854,19 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv* } } +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2( + JNIEnv* env, jobject obj, jstring jFile) +{ + Run(GetJString(env, jFile)); +} + +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z( + JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate) +{ + Run(GetJString(env, jFile), GetJString(env, jSavestate), jDeleteSavestate); +} + #ifdef __cplusplus } #endif |
