Make History Viewer not lock up the program when closed

This commit is contained in:
NovaSquirrel 2020-10-07 21:12:39 -04:00
parent f6bf4d6f2a
commit 1bf62f38fc
5 changed files with 12 additions and 34 deletions

View file

@ -63,7 +63,7 @@ void HistoryViewer::SeekTo(uint32_t seekPosition)
{ {
//Seek to the specified position //Seek to the specified position
if (seekPosition < _history.size()) { if (seekPosition < _history.size()) {
_console->Pause(); _console->Lock();
bool wasPaused = _console->IsPaused(); bool wasPaused = _console->IsPaused();
_console->Resume(); _console->Resume();
@ -78,7 +78,7 @@ void HistoryViewer::SeekTo(uint32_t seekPosition)
_console->Pause(); _console->Pause();
} }
_console->Resume(); _console->Unlock();
} }
} }
@ -104,7 +104,7 @@ bool HistoryViewer::SaveMovie(string movieFile, uint32_t startPosition, uint32_t
//Take a savestate to be able to restore it after generating the movie file //Take a savestate to be able to restore it after generating the movie file
//(the movie generation uses the console's inputs, which could affect the emulation otherwise) //(the movie generation uses the console's inputs, which could affect the emulation otherwise)
stringstream state; stringstream state;
_console->Pause(); _console->Lock();
_console->GetSaveStateManager()->SaveState(state); _console->GetSaveStateManager()->SaveState(state);
//Convert the rewind data to a .mmo file //Convert the rewind data to a .mmo file
@ -113,13 +113,13 @@ bool HistoryViewer::SaveMovie(string movieFile, uint32_t startPosition, uint32_t
//Resume the state and resume //Resume the state and resume
_console->GetSaveStateManager()->LoadState(state); _console->GetSaveStateManager()->LoadState(state);
_console->Resume(); _console->Unlock();
return result; return result;
} }
void HistoryViewer::ResumeGameplay(shared_ptr<Console> console, uint32_t resumePosition) void HistoryViewer::ResumeGameplay(shared_ptr<Console> console, uint32_t resumePosition)
{ {
console->Pause(); console->Lock();
if (_console->GetRomInfo().RomFile.GetSha1Hash() != console->GetRomInfo().RomFile.GetSha1Hash()) { if (_console->GetRomInfo().RomFile.GetSha1Hash() != console->GetRomInfo().RomFile.GetSha1Hash()) {
//Load game on the main window if they aren't the same //Load game on the main window if they aren't the same
console->LoadRom(console->GetRomInfo().RomFile, console->GetRomInfo().PatchFile); console->LoadRom(console->GetRomInfo().RomFile, console->GetRomInfo().PatchFile);
@ -131,7 +131,7 @@ void HistoryViewer::ResumeGameplay(shared_ptr<Console> console, uint32_t resumeP
else { else {
_history[_history.size() - 1].LoadState(console); _history[_history.size() - 1].LoadState(console);
} }
console->Resume(); console->Unlock();
} }
bool HistoryViewer::SetInput(BaseControlDevice* device) bool HistoryViewer::SetInput(BaseControlDevice* device)

View file

@ -264,9 +264,9 @@ extern "C" {
return _logString.c_str(); return _logString.c_str();
} }
DllExport ScreenSize __stdcall GetScreenSize(bool ignoreScale) DllExport ScreenSize __stdcall GetScreenSize(bool ignoreScale, ConsoleId console)
{ {
return _console->GetVideoDecoder()->GetScreenSize(ignoreScale); return GetConsoleById(console)->GetVideoDecoder()->GetScreenSize(ignoreScale);
} }
DllExport void __stdcall ClearCheats() { _console->GetCheatManager()->ClearCheats(); } DllExport void __stdcall ClearCheats() { _console->GetCheatManager()->ClearCheats(); }

View file

@ -34,8 +34,11 @@ extern "C"
_historyConsole.reset(new Console()); _historyConsole.reset(new Console());
// TODO: something about initializing with settings? // TODO: something about initializing with settings?
_historyConsole->Initialize(); _historyConsole->Initialize();
_historyConsole->Lock();
_historyConsole->LoadRom(_console->GetRomInfo().RomFile, _console->GetRomInfo().PatchFile); _historyConsole->LoadRom(_console->GetRomInfo().RomFile, _console->GetRomInfo().PatchFile);
_historyConsole->CopyRewindData(_console); _historyConsole->CopyRewindData(_console);
_historyConsole->Unlock();
//Force some settings //Force some settings
// TODO // TODO
@ -54,20 +57,13 @@ extern "C"
DllExport void __stdcall HistoryViewerRelease() DllExport void __stdcall HistoryViewerRelease()
{ {
_historyConsole->Stop(false); // TODO: Check on this _historyConsole->Stop(true); // TODO: Check on this
_historyConsole->Release(); // had True, "For ShutDown" _historyConsole->Release(); // had True, "For ShutDown"
_historyRenderer.reset(); _historyRenderer.reset();
_historySoundManager.reset(); _historySoundManager.reset();
_historyConsole.reset(); _historyConsole.reset();
} }
DllExport void __stdcall HistoryViewerRun()
{
if (_historyConsole) {
_historyConsole->Run();
}
}
DllExport uint32_t __stdcall HistoryViewerGetHistoryLength() DllExport uint32_t __stdcall HistoryViewerGetHistoryLength()
{ {
if (_historyConsole) { if (_historyConsole) {

View file

@ -51,7 +51,6 @@ namespace Mesen.GUI.Forms
HistoryViewerApi.HistoryViewerInitialize(this.Handle, ctrlRenderer.Handle); HistoryViewerApi.HistoryViewerInitialize(this.Handle, ctrlRenderer.Handle);
trkPosition.Maximum = (int)(HistoryViewerApi.HistoryViewerGetHistoryLength() / 60); trkPosition.Maximum = (int)(HistoryViewerApi.HistoryViewerGetHistoryLength() / 60);
UpdatePositionLabel(0); UpdatePositionLabel(0);
StartEmuThread();
EmuApi.Resume(EmuApi.ConsoleId.HistoryViewer); EmuApi.Resume(EmuApi.ConsoleId.HistoryViewer);
tmrUpdatePosition.Start(); tmrUpdatePosition.Start();
trkVolume.Value = ConfigManager.Config.HistoryViewer.Volume; trkVolume.Value = ConfigManager.Config.HistoryViewer.Volume;
@ -70,22 +69,6 @@ namespace Mesen.GUI.Forms
base.OnClosing(e); base.OnClosing(e);
} }
private void StartEmuThread()
{
if(_emuThread == null) {
_emuThread = new Thread(() => {
try {
HistoryViewerApi.HistoryViewerRun();
_emuThread = null;
} catch(Exception ex) {
MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString());
_emuThread = null;
}
});
_emuThread.Start();
}
}
private void TogglePause() private void TogglePause()
{ {
if(trkPosition.Value == trkPosition.Maximum) { if(trkPosition.Value == trkPosition.Maximum) {

View file

@ -14,7 +14,6 @@ namespace Mesen.GUI
[DllImport(DllPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool HistoryViewerEnabled(); [DllImport(DllPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool HistoryViewerEnabled();
[DllImport(DllPath)] public static extern void HistoryViewerInitialize(IntPtr windowHandle, IntPtr viewerHandle); [DllImport(DllPath)] public static extern void HistoryViewerInitialize(IntPtr windowHandle, IntPtr viewerHandle);
[DllImport(DllPath)] public static extern void HistoryViewerRelease(); [DllImport(DllPath)] public static extern void HistoryViewerRelease();
[DllImport(DllPath)] public static extern void HistoryViewerRun();
[DllImport(DllPath)] public static extern void HistoryViewerStop(); [DllImport(DllPath)] public static extern void HistoryViewerStop();
[DllImport(DllPath)] public static extern UInt32 HistoryViewerGetHistoryLength(); [DllImport(DllPath)] public static extern UInt32 HistoryViewerGetHistoryLength();