From 3bc178ee788ae7ca7c66b2f38fa892000dd491fa Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 26 Sep 2016 20:51:55 +1000 Subject: [PATCH] [Android] Add force gfx reset --- Android/res/xml/settings_advanced.xml | 5 +++- Android/src/emu/project64/jni/SettingsID.java | 1 + .../project64/settings/SettingsActivity.java | 2 ++ Source/Project64-core/N64System/N64Class.cpp | 26 ++++++++++++++++--- Source/Project64-core/Plugins/GFXPlugin.cpp | 4 +-- Source/Project64-core/Plugins/PluginClass.cpp | 16 ++++++++---- Source/Project64-core/Settings/Settings.h | 1 + .../Project64-core/Settings/SettingsClass.cpp | 6 ++++- 8 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Android/res/xml/settings_advanced.xml b/Android/res/xml/settings_advanced.xml index 3e7324cef..ce8fe0cba 100644 --- a/Android/res/xml/settings_advanced.xml +++ b/Android/res/xml/settings_advanced.xml @@ -23,7 +23,6 @@ android:key="Debugger_LimitFPS" android:summary="@string/LimitFPS_summary" android:title="@string/LimitFPS_title" /> - + LoadDword(Game_ScreenHertz); if (gameHertz == 0) { @@ -97,6 +98,7 @@ CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem) m_Recomp = new CRecompiler(m_Reg, m_Profile, m_EndEmulation); } } + WriteTrace(TraceN64System, TraceDebug, "Done"); } CN64System::~CN64System() @@ -316,6 +318,10 @@ bool CN64System::RunFileImage(const char * FileLoc) } } } + else + { + WriteTrace(TraceN64System, TraceError, "Failed to create CN64System"); + } } else { @@ -624,6 +630,7 @@ void CN64System::PluginReset() void CN64System::Reset(bool bInitReg, bool ClearMenory) { + WriteTrace(TraceN64System, TraceDebug, "Start (bInitReg: %s, ClearMenory: %s)", bInitReg ? "true" : "false", ClearMenory ? "true" : "false"); g_Settings->SaveBool(GameRunning_InReset, true); RefreshGameSettings(); m_Audio.Reset(); @@ -664,12 +671,21 @@ void CN64System::Reset(bool bInitReg, bool ClearMenory) { m_Recomp->Reset(); } - if (m_Plugins) { m_Plugins->GameReset(); } + if (m_Plugins && g_Settings->LoadBool(GameRunning_CPU_Running)) + { + if (g_Settings->LoadBool(Plugin_ForceGfxReset)) + { + m_Plugins->Reset(this); + } + m_Plugins->RomClosed(); + m_Plugins->RomOpened(); + } if (m_SyncCPU) { m_SyncCPU->Reset(bInitReg, ClearMenory); } g_Settings->SaveBool(GameRunning_InReset, true); + WriteTrace(TraceN64System, TraceDebug, "Done"); } bool CN64System::SetActiveSystem(bool bActive) @@ -680,6 +696,7 @@ bool CN64System::SetActiveSystem(bool bActive) if (bActive && g_System == this) { + WriteTrace(TraceN64System, TraceDebug, "Done (Res: true)"); return true; } @@ -721,6 +738,8 @@ bool CN64System::SetActiveSystem(bool bActive) { if (!m_MMU_VM.Initialize()) { + WriteTrace(TraceN64System, TraceWarning, "MMU failed to Initialize"); + WriteTrace(TraceN64System, TraceDebug, "Done (Res: false)"); return false; } bReset = true; @@ -758,6 +777,8 @@ bool CN64System::SetActiveSystem(bool bActive) if (!bRes) { WriteTrace(TraceN64System, TraceError, "g_Plugins->Initiate Failed"); + WriteTrace(TraceN64System, TraceDebug, "Done (Res: false)"); + return false; } } @@ -1072,7 +1093,6 @@ void CN64System::SyncCPU(CN64System * const SecondCPU) bool ErrorFound = false; m_SyncCount += 1; - //WriteTraceF(TraceError,"SyncCPU PC = %08X",m_Reg.m_PROGRAM_COUNTER); g_SystemTimer->UpdateTimers(); #ifdef TEST_SP_TRACKING @@ -2036,7 +2056,6 @@ void CN64System::RefreshScreen() uint32_t VI_INTR_TIME = 500000; if (bShowCPUPer()) { CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_RefreshScreen); } - //if (bProfiling) { ProfilingAddr = m_Profile.StartTimer(Timer_RefreshScreen); } //Calculate how many cycles to next refresh if (m_Reg.VI_V_SYNC_REG == 0) @@ -2069,7 +2088,6 @@ void CN64System::RefreshScreen() } if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_UpdateScreen); } - // if (bProfiling) { m_Profile.StartTimer(Timer_UpdateScreen); } __except_try() { diff --git a/Source/Project64-core/Plugins/GFXPlugin.cpp b/Source/Project64-core/Plugins/GFXPlugin.cpp index 71356073a..ac6220409 100644 --- a/Source/Project64-core/Plugins/GFXPlugin.cpp +++ b/Source/Project64-core/Plugins/GFXPlugin.cpp @@ -108,7 +108,7 @@ bool CGfxPlugin::LoadFunctions(void) bool CGfxPlugin::Initiate(CN64System * System, RenderWindow * Window) { - WriteTrace(TraceGFXPlugin, TraceDebug, "Starting"); + WriteTrace(TraceGFXPlugin, TraceDebug, "Start"); if (m_Initialized) { Close(Window); @@ -259,7 +259,7 @@ bool CGfxPlugin::Initiate(CN64System * System, RenderWindow * Window) pjutil::DynLibCallDllMain(); #endif - WriteTrace(TraceGFXPlugin, TraceDebug, "InitiateGFX done (res: %s)", m_Initialized ? "true" : "false"); + WriteTrace(TraceGFXPlugin, TraceDebug, "Done (res: %s)", m_Initialized ? "true" : "false"); return m_Initialized; } diff --git a/Source/Project64-core/Plugins/PluginClass.cpp b/Source/Project64-core/Plugins/PluginClass.cpp index 80bc6407a..a5324bb97 100644 --- a/Source/Project64-core/Plugins/PluginClass.cpp +++ b/Source/Project64-core/Plugins/PluginClass.cpp @@ -192,7 +192,9 @@ void CPlugins::DestroyGfxPlugin(void) { return; } - WriteTrace(TraceGFXPlugin, TraceInfo, "Start"); + WriteTrace(TraceGFXPlugin, TraceDebug, "before close"); + m_Gfx->Close(m_MainWindow); + WriteTrace(TraceGFXPlugin, TraceInfo, "deleting"); delete m_Gfx; WriteTrace(TraceGFXPlugin, TraceInfo, "m_Gfx deleted"); m_Gfx = NULL; @@ -324,14 +326,18 @@ bool CPlugins::Reset(CN64System * System) bool bRspChange = _stricmp(m_RSPFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_RSP).c_str()) != 0; bool bContChange = _stricmp(m_ControlFile.c_str(), g_Settings->LoadStringVal(Game_Plugin_Controller).c_str()) != 0; -#ifdef ANDROID - //this is a hack and should not be here, glide64 is not correctly freeing something on restart, this needs to be fixed but this is a short term workaround - bGfxChange = true; -#endif + + if (g_Settings->LoadBool(Plugin_ForceGfxReset)) + { + //this is a hack and should not be here, glide64 is not correctly freeing something on restart, this needs to be fixed but this is a short term workaround + bGfxChange = true; + } //if GFX and Audio has changed we also need to force reset of RSP if (bGfxChange || bAudioChange) + { bRspChange = true; + } if (bGfxChange) { DestroyGfxPlugin(); } if (bAudioChange) { DestroyAudioPlugin(); } diff --git a/Source/Project64-core/Settings/Settings.h b/Source/Project64-core/Settings/Settings.h index 593ae402b..502b0f606 100644 --- a/Source/Project64-core/Settings/Settings.h +++ b/Source/Project64-core/Settings/Settings.h @@ -258,6 +258,7 @@ enum SettingID Plugin_UseHleGfx, Plugin_UseHleAudio, Plugin_EnableAudio, + Plugin_ForceGfxReset, Logging_GenerateLog, Logging_LogRDRamRegisters, diff --git a/Source/Project64-core/Settings/SettingsClass.cpp b/Source/Project64-core/Settings/SettingsClass.cpp index c230bb0cf..33302664b 100644 --- a/Source/Project64-core/Settings/SettingsClass.cpp +++ b/Source/Project64-core/Settings/SettingsClass.cpp @@ -359,7 +359,11 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(Plugin_UseHleGfx, new CSettingTypeApplication("RSP", "HLE GFX", true)); AddHandler(Plugin_UseHleAudio, new CSettingTypeApplication("RSP", "HLE Audio", false)); AddHandler(Plugin_EnableAudio, new CSettingTypeApplication("Audio", "Enable Audio", true)); - +#ifdef ANDROID + AddHandler(Plugin_ForceGfxReset, new CSettingTypeApplication("Plugin", "Force Gfx Reset", true)); +#else + AddHandler(Plugin_ForceGfxReset, new CSettingTypeApplication("Plugin", "Force Gfx Reset", false)); +#endif //Logging AddHandler(Logging_GenerateLog, new CSettingTypeApplication("Logging", "Generate Log Files", false)); AddHandler(Logging_LogRDRamRegisters, new CSettingTypeApplication("Logging", "Log RDRam Registers", false));