From 570f77cc68cd895de11b98ec6fbbc67cfc212d09 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 25 Jul 2014 01:55:21 +0000 Subject: [PATCH] Implement FastUpdate() on IToolForm. The intent here is for tools to do the minimum amount necessary when updating. This allows them to avoid slow things like drawing, but do critical activities such as Ram tools incrementing change counters, and loggers can continue logging. When Turboing, instead of bypassing tool updates, the client will run the fast update instead. Note: a few tools still need to be thought out as to what they need to do in a fast update --- BizHawk.Client.EmuHawk/MainForm.cs | 8 +++++ .../config/NES/NESSoundConfig.cs | 5 +++ .../tools/Atari2600/Atari2600Debugger.cs | 5 +++ BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 7 +++- BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs | 5 +++ .../tools/GB/GBGameGenie.cs | 5 +++ .../tools/GBA/GBAGPUView.cs | 5 +++ .../tools/Genesis/GenGameGenie.cs | 5 +++ .../tools/Genesis/VDPViewer.cs | 5 +++ .../tools/HexEditor/HexEditor.cs | 5 +++ BizHawk.Client.EmuHawk/tools/IToolForm.cs | 9 ++++- .../tools/Lua/LuaConsole.cs | 10 +++++- .../tools/NES/NESDebugger.cs | 5 +++ .../tools/NES/NESGameGenie.cs | 5 +++ .../tools/NES/NESNameTableViewer.cs | 5 +++ BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs | 5 +++ .../tools/PCE/PCEBGViewer.cs | 5 +++ BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs | 5 +++ .../tools/PCE/PCESoundDebugger.cs | 5 +++ .../tools/PCE/PCETileViewer.cs | 4 +++ BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs | 5 +++ .../tools/SNES/SNESGameGenie.cs | 5 +++ .../tools/SNES/SNESGraphicsDebugger.cs | 5 +++ .../tools/TAStudio/TAStudio.IToolForm.cs | 11 ++++++ .../tools/TI83/TI83KeyPad.cs | 5 +++ BizHawk.Client.EmuHawk/tools/ToolBox.cs | 5 +++ BizHawk.Client.EmuHawk/tools/ToolManager.cs | 26 ++++++++++++++ BizHawk.Client.EmuHawk/tools/TraceLogger.cs | 10 ++++++ .../tools/VirtualPads/VirtualpadsTool.cs | 10 ++++++ .../tools/Watch/RamSearch.cs | 13 +++++++ .../tools/Watch/RamWatch.cs | 34 +++++++++++++++++++ 31 files changed, 239 insertions(+), 3 deletions(-) diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 1a22788b6e..056d55d3ab 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2551,6 +2551,10 @@ namespace BizHawk.Client.EmuHawk { GlobalWin.Tools.UpdateToolsBefore(); } + else + { + GlobalWin.Tools.FastUpdateBefore(); + } _runloopFps++; @@ -2636,6 +2640,10 @@ namespace BizHawk.Client.EmuHawk { UpdateToolsAfter(); } + else + { + GlobalWin.Tools.FastUpdateAfter(); + } } if (Global.ClientControls["Rewind"] || PressRewind) diff --git a/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs b/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs index d6f41dacbe..c09f8a3d96 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESSoundConfig.cs @@ -21,6 +21,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public void Restart() { if (!(Global.Emulator is NES)) diff --git a/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs b/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs index dae621a9ff..5a47f7cc2d 100644 --- a/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Atari2600/Atari2600Debugger.cs @@ -207,6 +207,11 @@ namespace BizHawk.Client.EmuHawk _programmaticUpdateOfRegisterBoxes = false; } + public void FastUpdate() + { + /* TODO */ + } + private void UpdateTraceLog() { var instructions = Global.CoreComm.Tracer.TakeContents().Split('\n'); diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index d509dcb012..d4dac6045c 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -70,7 +70,12 @@ namespace BizHawk.Client.EmuHawk public void UpdateValues() { - // Do nothing; + // Do nothing + } + + public void FastUpdate() + { + // Do nothing } public void Restart() diff --git a/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs b/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs index 94d2afd49c..cddd82f188 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs @@ -584,6 +584,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + #endregion #region mouseovers diff --git a/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs b/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs index cbdacd29f5..db9c42b242 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs @@ -35,6 +35,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public GBGameGenie() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs b/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs index 03b8463f22..67b2f8094c 100644 --- a/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs +++ b/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs @@ -718,6 +718,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + private void GBAGPUView_Load(object sender, EventArgs e) { Restart(); diff --git a/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs b/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs index 47adc10131..5c5e5d847f 100644 --- a/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/Genesis/GenGameGenie.cs @@ -80,6 +80,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public GenGameGenie() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs index 16dada284d..5579d081f0 100644 --- a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs @@ -132,6 +132,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public void Restart() { Emu = Global.Emulator as GPGX; diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index d1a1bdc875..bb2d0c5499 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -110,6 +110,11 @@ namespace BizHawk.Client.EmuHawk AddressLabel.Text = GenerateAddressString(); } + public void FastUpdate() + { + // Do nothing + } + public void Restart() { if (!IsHandleCreated || IsDisposed) diff --git a/BizHawk.Client.EmuHawk/tools/IToolForm.cs b/BizHawk.Client.EmuHawk/tools/IToolForm.cs index 1182647cb3..04f5490898 100644 --- a/BizHawk.Client.EmuHawk/tools/IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/IToolForm.cs @@ -6,7 +6,14 @@ /// Will be called by the client anytime an Update needs to occur, such as after an emulated frame, a loadstate, or a related dialog has made a relevant change /// void UpdateValues(); - + + /// + /// Will be called by the client when performance is critical, + /// The tool should only do the minimum to still function, + /// Drawing should not occur if possible, during a fast update + /// + void FastUpdate(); + /// /// Will be called anytime the dialog needs to be restarted, such as when a new ROM is loaded /// The tool implementing this needs to account for a Game and Core change diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 63adf6d838..44ea4d041e 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -76,7 +76,15 @@ namespace BizHawk.Client.EmuHawk Owner = Global.Config.LuaSettings.FloatingWindow ? null : GlobalWin.MainForm; } - public void UpdateValues() { } + public void UpdateValues() + { + // Do nothing + } + + public void FastUpdate() + { + // Do nothing + } public LuaConsole Get() { return this; } diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs b/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs index f718b75d90..db18a57aab 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESDebugger.cs @@ -65,6 +65,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + private void UpdateDebugView() { DebugView.BlazingFast = true; diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs b/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs index a09b41401d..d50348500e 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESGameGenie.cs @@ -55,6 +55,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public NESGameGenie() { InitializeComponent(); diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs index 66f34405bc..3ba1e41d6d 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs @@ -70,6 +70,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + #endregion private unsafe void DrawTile(int* dst, int pitch, byte* pal, byte* tile, int* finalpal) diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs b/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs index c99c4504cb..8eefba1ad3 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs @@ -67,6 +67,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public void Restart() { if (Global.Emulator is NES) diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs index 41dee3b6e1..3ecb4902dd 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCEBGViewer.cs @@ -125,6 +125,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + #endregion #region Events diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs index fbffa4fbc4..39b9c59fa6 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCECDL.cs @@ -46,6 +46,11 @@ namespace BizHawk.Client.EmuHawk UpdateDisplay(); } + public void FastUpdate() + { + // TODO + } + public void Restart() { if (Global.Emulator is PCEngine) diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs index 24dd2f55fc..e927cf66c4 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCESoundDebugger.cs @@ -146,6 +146,11 @@ namespace BizHawk.Client.EmuHawk lvChannels.EndUpdate(); } + public void FastUpdate() + { + // Todo + } + class PSGEntry { public int index; diff --git a/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs b/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs index 6042eb4eee..80f3ca05d3 100644 --- a/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/PCE/PCETileViewer.cs @@ -46,6 +46,10 @@ namespace BizHawk.Client.EmuHawk bmpViewSPPal.Refresh(); } + public void FastUpdate() + { + // Do nothing + } unsafe static void Draw16x16(byte* src, int* dest, int pitch, int* pal) { diff --git a/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs b/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs index ae91c9e770..5224d8f5f6 100644 --- a/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/SMS/VDPViewer.cs @@ -150,6 +150,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public void Restart() { if (!(Global.Emulator is SMS)) diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs index 925efd7f53..b8f3e437ec 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGameGenie.cs @@ -77,6 +77,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + #endregion private void SnesGGDecode(string code, ref int val, ref int add) diff --git a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs index 995bc07172..f78860dbaa 100644 --- a/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs @@ -145,6 +145,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // To do + } + public void UpdateToolsLoadstate() { SyncCore(); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs index 83addb602a..7a8aebd07d 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IToolForm.cs @@ -31,6 +31,17 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // TODO: think more about this + + if (StopFrame.HasValue && Global.Emulator.Frame == StopFrame.Value) + { + GlobalWin.MainForm.PauseEmulator(); + StopFrame = null; + } + } + public void Restart() { if (!IsHandleCreated || IsDisposed) diff --git a/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs b/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs index 70abf898fc..d9ecb2f47f 100644 --- a/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs +++ b/BizHawk.Client.EmuHawk/tools/TI83/TI83KeyPad.cs @@ -45,6 +45,11 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // Do nothing + } + public void Restart() { if (!(Global.Emulator is TI83)) diff --git a/BizHawk.Client.EmuHawk/tools/ToolBox.cs b/BizHawk.Client.EmuHawk/tools/ToolBox.cs index aea52fb506..08dd18a209 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolBox.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolBox.cs @@ -39,6 +39,11 @@ namespace BizHawk.Client.EmuHawk public bool UpdateBefore { get { return false; } } public void UpdateValues() { } + public void FastUpdate() + { + // Do nothing + } + public void Restart() { SetTools(); diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index ffdbfe738b..ac11bf0548 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -252,6 +252,32 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdateBefore() + { + var beforeList = _tools.Where(x => x.UpdateBefore); + foreach (var tool in beforeList) + { + if (!tool.IsDisposed || + (tool is RamWatch && Global.Config.DisplayRamWatch)) // Ram Watch hack, on screen display should run even if Ram Watch is closed + { + tool.FastUpdate(); + } + } + } + + public void FastUpdateAfter() + { + var afterList = _tools.Where(x => !x.UpdateBefore); + foreach (var tool in afterList) + { + if (!tool.IsDisposed || + (tool is RamWatch && Global.Config.DisplayRamWatch)) // Ram Watch hack, on screen display should run even if Ram Watch is closed + { + tool.FastUpdate(); + } + } + } + // Note: Referencing these properties creates an instance of the tool and persists it. They should be referenced by type if this is not desired #region Tools diff --git a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index 1f8c8da78e..57f24f40c1 100644 --- a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -90,6 +90,16 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + // TODO: think more about this logic + if (!ToWindowRadio.Checked) + { + LogToFile(); + } + } + + public void Restart() { if (!IsHandleCreated || IsDisposed) diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs index 29aecb03eb..826a85bdf7 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs @@ -198,6 +198,16 @@ namespace BizHawk.Client.EmuHawk Pads.ForEach(pad => pad.Refresh()); } + public void FastUpdate() + { + // TODO: SetPrevious logic should go here too or that will get out of whack + + if (!Readonly && !Global.Config.VirtualPadSticky) + { + Pads.ForEach(pad => pad.Clear()); + } + } + #endregion #region Events diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 1358c2b5ea..1dbbb3f512 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -243,6 +243,19 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + if (_searches.Count > 0) + { + _searches.Update(); + + if (_autoSearch) + { + DoSearch(); + } + } + } + public void Restart() { if (!IsHandleCreated || IsDisposed) diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 4cf663b79a..0497590c35 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -240,6 +240,40 @@ namespace BizHawk.Client.EmuHawk } } + public void FastUpdate() + { + if (_paused) + { + return; + } + + if ((!IsHandleCreated || IsDisposed) && !Global.Config.DisplayRamWatch) + { + return; + } + + if (_watches.Any()) + { + _watches.UpdateValues(); + + if (Global.Config.DisplayRamWatch) + { + for (var i = 0; i < _watches.Count; i++) + { + var frozen = !_watches[i].IsSeparator && Global.CheatList.IsActive(_watches[i].Domain, _watches[i].Address ?? 0); + GlobalWin.OSD.AddGUIText( + _watches[i].ToString(), + Global.Config.DispRamWatchx, + Global.Config.DispRamWatchy + (i * 14), + Color.Black, + frozen ? Color.Cyan : Color.White, + 0 + ); + } + } + } + } + #endregion #region Private Methods