From 4cf5a549997a33ce941703d8be373a45ff2606fb Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 13 Dec 2016 06:22:35 +1100 Subject: [PATCH] [Android] Do not create system on show menu --- Source/Android/Bridge/jniBridge.cpp | 5 +- Source/Project64-core/N64System/N64Class.cpp | 67 +++++++++++--------- Source/Project64-core/N64System/N64Class.h | 2 + 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/Source/Android/Bridge/jniBridge.cpp b/Source/Android/Bridge/jniBridge.cpp index 0397857c9..4a915a856 100644 --- a/Source/Android/Bridge/jniBridge.cpp +++ b/Source/Android/Bridge/jniBridge.cpp @@ -313,8 +313,7 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_LoadGame(JNIEnv* env, jcla { const char *fileLoc = env->GetStringUTFChars(FileLoc, 0); WriteTrace(TraceUserInterface, TraceDebug, "FileLoc: %s",fileLoc); - g_Settings->SaveBool(Setting_AutoStart,false); - CN64System::RunFileImage(fileLoc); + CN64System::LoadFileImage(fileLoc); env->ReleaseStringUTFChars(FileLoc, fileLoc); WriteTrace(TraceUserInterface, TraceDebug, "Image loaded"); } @@ -323,7 +322,7 @@ EXPORT void CALL Java_emu_project64_jni_NativeExports_StartGame(JNIEnv* env, jcl { g_Activity = env->NewGlobalRef(activity); g_GLThread = env->NewGlobalRef(GLThread); - g_BaseSystem->StartEmulation(true); + CN64System::RunLoadedImage(); } EXPORT void CALL Java_emu_project64_jni_NativeExports_RefreshRomDir(JNIEnv* env, jclass cls, jstring RomDir, jboolean Recursive) diff --git a/Source/Project64-core/N64System/N64Class.cpp b/Source/Project64-core/N64System/N64Class.cpp index 59c639c4b..61d753f1d 100644 --- a/Source/Project64-core/N64System/N64Class.cpp +++ b/Source/Project64-core/N64System/N64Class.cpp @@ -241,9 +241,9 @@ void CN64System::ExternalEvent(SystemEvent action) } } -bool CN64System::RunFileImage(const char * FileLoc) +bool CN64System::LoadFileImage(const char * FileLoc) { - WriteTrace(TraceN64System, TraceDebug, "FileLoc: %s", FileLoc); + WriteTrace(TraceN64System, TraceDebug, "Start (FileLoc: %s)", FileLoc); CloseSystem(); g_Settings->SaveBool(Setting_EnableDisk, false); g_Settings->SaveDword(Game_CurrentSaveState, g_Settings->LoadDefaultDword(Game_CurrentSaveState)); @@ -282,6 +282,11 @@ bool CN64System::RunFileImage(const char * FileLoc) g_DDRom->LoadN64ImageIPL(FileLoc); g_Settings->SaveString(File_DiskIPLPath, FileLoc); } + else if (g_DDRom != NULL) + { + delete g_DDRom; + g_DDRom = NULL; + } if (g_DDRom != NULL) { @@ -294,33 +299,6 @@ bool CN64System::RunFileImage(const char * FileLoc) g_Settings->SaveBool(GameRunning_LoadingInProgress, false); WriteTrace(TraceN64System, TraceDebug, "Finished Loading (GoodName: %s)", g_Settings->LoadStringVal(Game_GoodName).c_str()); - - g_BaseSystem = new CN64System(g_Plugins, false, false); - if (g_BaseSystem) - { - if (g_Settings->LoadBool(Setting_AutoStart) != 0) - { - WriteTrace(TraceN64System, TraceDebug, "Automattically starting rom"); - g_BaseSystem->StartEmulation(true); - } - else - { - bool bSetActive = true; - if (g_BaseSystem->m_SyncCPU != NULL) - { - bSetActive = g_BaseSystem->m_SyncCPU->SetActiveSystem(true); - } - - if (bSetActive) - { - bSetActive = g_BaseSystem->SetActiveSystem(true); - } - } - } - else - { - WriteTrace(TraceN64System, TraceError, "Failed to create CN64System"); - } } else { @@ -329,11 +307,42 @@ bool CN64System::RunFileImage(const char * FileLoc) delete g_Rom; g_Rom = NULL; g_Settings->SaveBool(GameRunning_LoadingInProgress, false); + WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); return false; } + WriteTrace(TraceN64System, TraceDebug, "Done (res: true)"); return true; } +bool CN64System::RunFileImage(const char * FileLoc) +{ + if (!LoadFileImage(FileLoc)) + { + return false; + } + if (g_Settings->LoadBool(Setting_AutoStart) != 0) + { + WriteTrace(TraceN64System, TraceDebug, "Automattically starting rom"); + RunLoadedImage(); + } + return true; +} + +void CN64System::RunLoadedImage(void) +{ + WriteTrace(TraceN64System, TraceDebug, "Start"); + g_BaseSystem = new CN64System(g_Plugins, false, false); + if (g_BaseSystem) + { + g_BaseSystem->StartEmulation(true); + } + else + { + WriteTrace(TraceN64System, TraceError, "Failed to create CN64System"); + } + WriteTrace(TraceN64System, TraceDebug, "Done"); +} + bool CN64System::RunFileImageIPL(const char * FileLoc) { CloseSystem(); diff --git a/Source/Project64-core/N64System/N64Class.h b/Source/Project64-core/N64System/N64Class.h index 4f01b861f..3c5ba5939 100644 --- a/Source/Project64-core/N64System/N64Class.h +++ b/Source/Project64-core/N64System/N64Class.h @@ -56,9 +56,11 @@ public: SAVE_CHIP_TYPE m_SaveUsing; //Methods + static bool LoadFileImage(const char * FileLoc); static bool RunFileImage(const char * FileLoc); static bool RunFileImageIPL(const char * FileLoc); static bool RunDiskImage(const char * FileLoc); + static void RunLoadedImage(void); static void CloseSystem(void); void CloseCpu();