From f090597fbea0024c3a26d4dacd7e4398ee2f5a5f Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 26 Dec 2013 23:12:41 +0000 Subject: [PATCH] make MainForm.Rewind.cs into a separate class instead of a partial class of Mainform. Still dependent on the Mainform context so is still a part of the EmuHawk project for now --- .../BizHawk.Client.EmuHawk.csproj | 5 +---- BizHawk.Client.EmuHawk/GlobalWin.cs | 1 + BizHawk.Client.EmuHawk/MainForm.cs | 17 +++++++++-------- .../{MainForm.Rewind.cs => Rewind.cs} | 11 +++++++---- BizHawk.Client.EmuHawk/config/RewindConfig.cs | 12 ++++++------ .../tools/Lua/Libraries/EmuLuaLibrary.Client.cs | 4 ++-- 6 files changed, 26 insertions(+), 24 deletions(-) rename BizHawk.Client.EmuHawk/{MainForm.Rewind.cs => Rewind.cs} (95%) diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index b7a51f6002..48e47e47a1 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -383,10 +383,6 @@ MainForm.cs Form - - MainForm.cs - Form - Form @@ -436,6 +432,7 @@ + Form diff --git a/BizHawk.Client.EmuHawk/GlobalWin.cs b/BizHawk.Client.EmuHawk/GlobalWin.cs index cfed14692e..8b137dc543 100644 --- a/BizHawk.Client.EmuHawk/GlobalWin.cs +++ b/BizHawk.Client.EmuHawk/GlobalWin.cs @@ -9,6 +9,7 @@ namespace BizHawk.Client.EmuHawk { public static MainForm MainForm; public static ToolManager Tools; + public static Rewinder Rewinder; #if WINDOWS public static DirectSound DSound; public static Direct3D Direct3D; diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index a1945f85a1..5fc7423621 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -47,6 +47,7 @@ namespace BizHawk.Client.EmuHawk public MainForm(string[] args) { GlobalWin.MainForm = this; + GlobalWin.Rewinder = new Rewinder(); Global.ControllerInputCoalescer = new ControllerInputCoalescer(); Global.FirmwareManager = new FirmwareManager(); Global.MovieSession = new MovieSession @@ -459,7 +460,6 @@ namespace BizHawk.Client.EmuHawk public bool TurboFastForward = false; public bool RestoreReadWriteOnStop = false; public bool UpdateFrame = false; - public bool RewindActive = true; public bool EmulatorPaused { get; private set; } #endregion @@ -2467,12 +2467,13 @@ namespace BizHawk.Client.EmuHawk runFrame = true; } + // TODO: mostly likely this will need to be whacked, if not then refactor bool ReturnToRecording = Global.MovieSession.Movie.IsRecording; - if (RewindActive && (Global.ClientControls["Rewind"] || PressRewind)) + if (GlobalWin.Rewinder.RewindActive && (Global.ClientControls["Rewind"] || PressRewind)) { - Rewind(1); + GlobalWin.Rewinder.Rewind(1); suppressCaptureRewind = true; - if (0 == RewindBuf.Count) + if (0 == GlobalWin.Rewinder.RewindBuf.Count) { runFrame = false; } @@ -2538,7 +2539,7 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.FPS = fps_string; } - if (!suppressCaptureRewind && RewindActive) CaptureRewindState(); + if (!suppressCaptureRewind && GlobalWin.Rewinder.RewindActive) GlobalWin.Rewinder.CaptureRewindState(); if (!_runloopFrameadvance) genSound = true; else if (!Global.Config.MuteFrameAdvance) @@ -2928,7 +2929,7 @@ namespace BizHawk.Client.EmuHawk } Text = DisplayNameForSystem(loader.Game.System) + " - " + loader.Game.Name; - ResetRewindBuffer(); + GlobalWin.Rewinder.ResetRewindBuffer(); if (Global.Emulator.CoreComm.RomStatusDetails == null && loader.Rom != null) { @@ -2979,7 +2980,7 @@ namespace BizHawk.Client.EmuHawk UpdateStatusSlots(); UpdateDumpIcon(); - CaptureRewindState(); + GlobalWin.Rewinder.CaptureRewindState(); Global.StickyXORAdapter.ClearStickies(); Global.StickyXORAdapter.ClearStickyFloats(); @@ -3163,7 +3164,7 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.Restart(); RewireSound(); - ResetRewindBuffer(); + GlobalWin.Rewinder.ResetRewindBuffer(); Text = "BizHawk" + (VersionInfo.INTERIM ? " (interim) " : String.Empty); HandlePlatformMenus(); _stateSlots.Clear(); diff --git a/BizHawk.Client.EmuHawk/MainForm.Rewind.cs b/BizHawk.Client.EmuHawk/Rewind.cs similarity index 95% rename from BizHawk.Client.EmuHawk/MainForm.Rewind.cs rename to BizHawk.Client.EmuHawk/Rewind.cs index 005b64001f..1e658d131b 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Rewind.cs +++ b/BizHawk.Client.EmuHawk/Rewind.cs @@ -8,8 +8,10 @@ using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { - public partial class MainForm + public class Rewinder { + public bool RewindActive = true; + public StreamBlobDatabase RewindBuf;// = new StreamBlobDatabase(Global.Config.Rewind_OnDisk, Global.Config.Rewind_BufferSize * (long)1024 * (long)1024); private RewindThreader RewindThread; @@ -264,9 +266,9 @@ namespace BizHawk.Client.EmuHawk // which will kill N64 for sure... public static bool IsThreaded = false; - MainForm mf; + Rewinder mf; - public RewindThreader(MainForm mf, bool isThreaded) + public RewindThreader(Rewinder mf, bool isThreaded) { IsThreaded = isThreaded; this.mf = mf; @@ -382,7 +384,8 @@ namespace BizHawk.Client.EmuHawk ConcurrentQueue Jobs = new ConcurrentQueue(); } - private void CaptureRewindState() + // TOOD: this should not be parameterless?! It is only possible due to passing a static context in + public void CaptureRewindState() { if (RewindImpossible) return; diff --git a/BizHawk.Client.EmuHawk/config/RewindConfig.cs b/BizHawk.Client.EmuHawk/config/RewindConfig.cs index c244920e9e..0b3c64540e 100644 --- a/BizHawk.Client.EmuHawk/config/RewindConfig.cs +++ b/BizHawk.Client.EmuHawk/config/RewindConfig.cs @@ -19,10 +19,10 @@ namespace BizHawk.Client.EmuHawk private void RewindConfig_Load(object sender, EventArgs e) { - if (GlobalWin.MainForm.RewindBuf != null) + if (GlobalWin.Rewinder.RewindBuf != null) { - FullnessLabel.Text = String.Format("{0:0.00}", GlobalWin.MainForm.Rewind_FullnessRatio * 100) + "%"; - RewindFramesUsedLabel.Text = GlobalWin.MainForm.Rewind_Count.ToString(); + FullnessLabel.Text = String.Format("{0:0.00}", GlobalWin.Rewinder.Rewind_FullnessRatio * 100) + "%"; + RewindFramesUsedLabel.Text = GlobalWin.Rewinder.Rewind_Count.ToString(); } else { @@ -127,7 +127,7 @@ namespace BizHawk.Client.EmuHawk Global.Config.RewindEnabledMedium = MediumStateEnabledBox.Checked; Global.Config.RewindEnabledLarge = LargeStateEnabledBox.Checked; - GlobalWin.MainForm.DoRewindSettings(); + GlobalWin.Rewinder.DoRewindSettings(); Global.Config.Rewind_UseDelta = UseDeltaCompression.Checked; @@ -260,9 +260,9 @@ namespace BizHawk.Client.EmuHawk if (UseDeltaCompression.Checked || _stateSize == 0) { - if (GlobalWin.MainForm.Rewind_Count > 0) + if (GlobalWin.Rewinder.Rewind_Count > 0) { - avg_state_size = GlobalWin.MainForm.Rewind_Size / GlobalWin.MainForm.Rewind_Count; + avg_state_size = GlobalWin.Rewinder.Rewind_Size / GlobalWin.Rewinder.Rewind_Count; } else { diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs index cc440adc6c..acc00ba2c0 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Client.cs @@ -67,12 +67,12 @@ namespace BizHawk.Client.EmuHawk { if (temp == "0" || temp.ToLower() == "false") { - GlobalWin.MainForm.RewindActive = false; + GlobalWin.Rewinder.RewindActive = false; GlobalWin.OSD.AddMessage("Rewind suspended"); } else { - GlobalWin.MainForm.RewindActive = true; + GlobalWin.Rewinder.RewindActive = true; GlobalWin.OSD.AddMessage("Rewind enabled"); } }