From 7cc5822dfd82bb8da2237381e46ae3a9d580fb3e Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 5 Dec 2014 02:07:56 +0000 Subject: [PATCH] Add ActiveChanged event to MemoryCallbackSystem --- .../MemoryCallbackSystem.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs index 996a3fb4a1..e05f459e47 100644 --- a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs @@ -18,20 +18,35 @@ namespace BizHawk.Emulation.Common public void AddRead(Action function, uint? addr) { + var hadAny = _reads.Any() || _writes.Any() || _executes.Any(); + _reads.Add(function); _readAddrs.Add(addr); + + var hasAny = _reads.Any() || _writes.Any() || _executes.Any(); + Changes(hadAny, hasAny); } public void AddWrite(Action function, uint? addr) { + var hadAny = _reads.Any() || _writes.Any() || _executes.Any(); + _writes.Add(function); _writeAddrs.Add(addr); + + var hasAny = _reads.Any() || _writes.Any() || _executes.Any(); + Changes(hadAny, hasAny); } public void AddExecute(Action function, uint addr) { + var hadAny = _reads.Any() || _writes.Any() || _executes.Any(); + _executes.Add(function); _execAddrs.Add(addr); + + var hasAny = _reads.Any() || _writes.Any() || _executes.Any(); + Changes(hadAny, hasAny); } public void CallRead(uint addr) @@ -73,6 +88,8 @@ namespace BizHawk.Emulation.Common public void Remove(Action action) { + var hadAny = _reads.Any() || _writes.Any() || _executes.Any(); + for (int i = 0; i < _reads.Count; i++) { if (_reads[i] == action) @@ -99,24 +116,51 @@ namespace BizHawk.Emulation.Common _execAddrs.Remove(_execAddrs[i]); } } + + var hasAny = _reads.Any() || _writes.Any() || _executes.Any(); + Changes(hadAny, hasAny); } public void RemoveAll(IEnumerable actions) { + var hadAny = _reads.Any() || _writes.Any() || _executes.Any(); + foreach (var action in actions) { Remove(action); } + + var hasAny = _reads.Any() || _writes.Any() || _executes.Any(); + Changes(hadAny, hasAny); } public void Clear() { + var hadAny = _reads.Any() || _writes.Any() || _executes.Any(); + _reads.Clear(); _readAddrs.Clear(); _writes.Clear(); _writes.Clear(); _executes.Clear(); _execAddrs.Clear(); + + + Changes(hadAny, false); + } + + public delegate void ActiveChangedEventHandler(); + public event ActiveChangedEventHandler ActiveChanged; + + private void Changes(bool hadAny, bool hasAny) + { + if ((hadAny && !hasAny) || (!hadAny && hasAny)) + { + if (ActiveChanged != null) + { + ActiveChanged(); + } + } } } }