From e23c5ead869a8a19951ef627059dc4e536c1bb10 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 27 Sep 2014 12:19:50 +0000 Subject: [PATCH] Tastudio - instead of disabling rewind, take it over with IControlMainform --- BizHawk.Client.EmuHawk/IControlMainform.cs | 36 ++++++++---- BizHawk.Client.EmuHawk/MainForm.cs | 58 ++++++++++++++----- .../TAStudio/TAStudio.IControlMainForm.cs | 14 +++++ .../tools/TAStudio/TAStudio.cs | 5 +- 4 files changed, 84 insertions(+), 29 deletions(-) diff --git a/BizHawk.Client.EmuHawk/IControlMainform.cs b/BizHawk.Client.EmuHawk/IControlMainform.cs index 965b93320f..f74bdc7e0c 100644 --- a/BizHawk.Client.EmuHawk/IControlMainform.cs +++ b/BizHawk.Client.EmuHawk/IControlMainform.cs @@ -3,20 +3,34 @@ public interface IControlMainform { bool WantsToControlReadOnly { get; } - /// - /// Function that is called by Mainform instead of using its own code - /// when a Tool sets WantsToControlReadOnly. - /// Should not be called directly. - /// + + /// + /// Function that is called by Mainform instead of using its own code + /// when a Tool sets WantsToControlReadOnly. + /// Should not be called directly. + /// void ToggleReadOnly(); bool WantsToControlStopMovie { get; } - /// - /// Function that is called by Mainform instead of using its own code - /// when a Tool sets WantsToControlStopMovie. - /// Should not be called directly. - /// Like MainForm's StopMovie(), saving the movie is part of this function's responsibility. - /// + + /// + /// Function that is called by Mainform instead of using its own code + /// when a Tool sets WantsToControlStopMovie. + /// Should not be called directly. + /// Like MainForm's StopMovie(), saving the movie is part of this function's responsibility. + /// void StopMovie(); + + bool WantsToControlRewind { get; } + + void CaptureRewind(); + + /// + /// Function that is called by Mainform instead of using its own code + /// when a Tool sets WantsToControlRewind + /// Returns whether or not the rewind action actually occured + /// + /// + bool Rewind(); } } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index efa2bbfad7..2f4664e6b3 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2580,16 +2580,7 @@ namespace BizHawk.Client.EmuHawk runFrame = true; } - bool isRewinding = false; - if (Global.Rewinder.RewindActive && (Global.ClientControls["Rewind"] || PressRewind) - && !Global.MovieSession.Movie.IsRecording) // Rewind isn't "bulletproof" and can desync a recording movie! - { - Global.Rewinder.Rewind(1); - suppressCaptureRewind = true; - - runFrame = Global.Rewinder.Count != 0; - isRewinding = true; - } + bool isRewinding = suppressCaptureRewind = Rewind(ref runFrame); if (UpdateFrame) { @@ -2663,10 +2654,7 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.FPS = fps_string; } - if (!suppressCaptureRewind && Global.Rewinder.RewindActive) - { - Global.Rewinder.CaptureRewindState(); - } + CaptureRewind(suppressCaptureRewind); if (!_runloopFrameadvance) { @@ -3418,6 +3406,11 @@ namespace BizHawk.Client.EmuHawk } } + public void ClearRewindData() + { + Global.Rewinder.ResetRewindBuffer(); + } + #endregion #region Tool Control API @@ -3478,6 +3471,43 @@ namespace BizHawk.Client.EmuHawk GenericCoreConfig.DoDialog(this, "Gameboy Advance Settings"); } + + private void CaptureRewind(bool suppressCaptureRewind) + { + if (IsSlave && master.WantsToControlRewind) + { + master.CaptureRewind(); + } + else if (!suppressCaptureRewind && Global.Rewinder.RewindActive) + { + Global.Rewinder.CaptureRewindState(); + } + } + + private bool Rewind(ref bool runFrame) + { + if (IsSlave && master.WantsToControlRewind) + { + if (Global.ClientControls["Rewind"] || PressRewind) + { + runFrame = false; // TODO: the master should be deciding this! + return master.Rewind(); + } + } + + var isRewinding = false; + if (Global.Rewinder.RewindActive && (Global.ClientControls["Rewind"] || PressRewind) + && !Global.MovieSession.Movie.IsRecording) // Rewind isn't "bulletproof" and can desync a recording movie! + { + Global.Rewinder.Rewind(1); + + runFrame = Global.Rewinder.Count != 0; + isRewinding = true; + } + + return isRewinding; + } + #endregion private void LinkConnectStatusBarButton_Click(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs index a515386195..5b3e8feb9d 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs @@ -15,5 +15,19 @@ this.Focus(); //NewTasMenuItem_Click(null, null); } + + public bool WantsToControlRewind { get { return true; } } + + public void CaptureRewind() + { + // Do nothing, Tastudio handles this just fine + } + + public bool Rewind() + { + GoToPreviousFrame(); + + return true; + } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index bed60baece..91267e3dd4 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -26,7 +26,6 @@ namespace BizHawk.Client.EmuHawk private int _defaultWidth; private int _defaultHeight; private TasMovie _currentTasMovie; - private bool _originalRewindStatus; // The client rewind status before TAStudio was engaged (used to restore when disengaged) private MovieEndAction _originalEndAction; // The movie end behavior selected by the user (that is overridden by TAStudio) private Dictionary GenerateColumnNames() @@ -80,10 +79,9 @@ namespace BizHawk.Client.EmuHawk SetTextProperty(); GlobalWin.MainForm.PauseEmulator(); GlobalWin.MainForm.RelinquishControl(this); - _originalRewindStatus = Global.Rewinder.RewindActive; _originalEndAction = Global.Config.MovieEndAction; MarkerControl.Markers = _currentTasMovie.Markers; - GlobalWin.MainForm.EnableRewind(false); + GlobalWin.MainForm.ClearRewindData(); Global.Config.MovieEndAction = MovieEndAction.Record; GlobalWin.MainForm.SetMainformMovieInfo(); } @@ -94,7 +92,6 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage("TAStudio disengaged"); Global.MovieSession.Movie = MovieService.DefaultInstance; GlobalWin.MainForm.TakeBackControl(); - GlobalWin.MainForm.EnableRewind(_originalRewindStatus); Global.Config.MovieEndAction = _originalEndAction; GlobalWin.MainForm.SetMainformMovieInfo(); }