MemoryCallbackSystem: fix #1159

This commit is contained in:
gifvex 2018-04-02 18:19:40 -04:00
parent f968cbdd73
commit f48a795090
1 changed files with 11 additions and 26 deletions

View File

@ -33,8 +33,6 @@ namespace BizHawk.Emulation.Common
private readonly ObservableCollection<IMemoryCallback> _writes = new ObservableCollection<IMemoryCallback>(); private readonly ObservableCollection<IMemoryCallback> _writes = new ObservableCollection<IMemoryCallback>();
private readonly ObservableCollection<IMemoryCallback> _execs = new ObservableCollection<IMemoryCallback>(); private readonly ObservableCollection<IMemoryCallback> _execs = new ObservableCollection<IMemoryCallback>();
private bool _empty = true;
private bool _hasReads; private bool _hasReads;
private bool _hasWrites; private bool _hasWrites;
private bool _hasExecutes; private bool _hasExecutes;
@ -54,24 +52,19 @@ namespace BizHawk.Emulation.Common
{ {
case MemoryCallbackType.Execute: case MemoryCallbackType.Execute:
_execs.Add(callback); _execs.Add(callback);
_hasExecutes = true;
break; break;
case MemoryCallbackType.Read: case MemoryCallbackType.Read:
_reads.Add(callback); _reads.Add(callback);
_hasReads = true;
break; break;
case MemoryCallbackType.Write: case MemoryCallbackType.Write:
_writes.Add(callback); _writes.Add(callback);
_hasWrites = true;
break; break;
} }
if (_empty) if (UpdateHasVariables())
{ {
Changes(); Changes();
} }
_empty = false;
} }
private static void Call(ObservableCollection<IMemoryCallback> cbs, uint addr, string scope) private static void Call(ObservableCollection<IMemoryCallback> cbs, uint addr, string scope)
@ -130,11 +123,17 @@ namespace BizHawk.Emulation.Common
return _execs.Where(e => e.Scope == scope).Any(); return _execs.Where(e => e.Scope == scope).Any();
} }
private void UpdateHasVariables() private bool UpdateHasVariables()
{ {
bool hadReads = _hasReads;
bool hadWrites = _hasWrites;
bool hadExecutes = _hasExecutes;
_hasReads = _reads.Count > 0; _hasReads = _reads.Count > 0;
_hasWrites = _writes.Count > 0; _hasWrites = _writes.Count > 0;
_hasExecutes = _execs.Count > 0; _hasExecutes = _execs.Count > 0;
return (_hasReads != hadReads || _hasWrites != hadWrites || _hasExecutes != hadExecutes);
} }
private int RemoveInternal(Action action) private int RemoveInternal(Action action)
@ -158,8 +157,6 @@ namespace BizHawk.Emulation.Common
_execs.Remove(exec); _execs.Remove(exec);
} }
UpdateHasVariables();
return readsToRemove.Count + writesToRemove.Count + execsToRemove.Count; return readsToRemove.Count + writesToRemove.Count + execsToRemove.Count;
} }
@ -167,13 +164,10 @@ namespace BizHawk.Emulation.Common
{ {
if (RemoveInternal(action) > 0) if (RemoveInternal(action) > 0)
{ {
bool newEmpty = !HasReads && !HasWrites && !HasExecutes; if (UpdateHasVariables())
if (newEmpty != _empty)
{ {
Changes(); Changes();
} }
_empty = newEmpty;
} }
} }
@ -187,16 +181,11 @@ namespace BizHawk.Emulation.Common
if (changed) if (changed)
{ {
bool newEmpty = !HasReads && !HasWrites && !HasExecutes; if (UpdateHasVariables())
if (newEmpty != _empty)
{ {
Changes(); Changes();
} }
_empty = newEmpty;
} }
UpdateHasVariables();
} }
public void Clear() public void Clear()
@ -217,14 +206,10 @@ namespace BizHawk.Emulation.Common
_execs.RemoveAt(i); _execs.RemoveAt(i);
} }
if (!_empty) if (UpdateHasVariables())
{ {
Changes(); Changes();
} }
_empty = true;
UpdateHasVariables();
} }
public delegate void ActiveChangedEventHandler(); public delegate void ActiveChangedEventHandler();