Ram Tools - speed up many situations that are slow when freezing/unfreezing addresses with multiple tools open due to sloppy handling of change events
This commit is contained in:
parent
827e2c44f8
commit
97bf870b74
|
@ -160,38 +160,41 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
public void Enable(bool handleChange = true)
|
||||
{
|
||||
if (!IsSeparator)
|
||||
{
|
||||
var wasEnabled = _enabled;
|
||||
_enabled = true;
|
||||
if (!wasEnabled)
|
||||
if (!wasEnabled && handleChange)
|
||||
{
|
||||
Changes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
public void Disable(bool handleChange = true)
|
||||
{
|
||||
if (!IsSeparator)
|
||||
{
|
||||
var wasEnabled = _enabled;
|
||||
_enabled = false;
|
||||
if (wasEnabled)
|
||||
if (wasEnabled && handleChange)
|
||||
{
|
||||
Changes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
public void Toggle(bool handleChange = true)
|
||||
{
|
||||
if (!IsSeparator)
|
||||
{
|
||||
_enabled ^= true;
|
||||
Changes();
|
||||
if (handleChange)
|
||||
{
|
||||
Changes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,5 +279,59 @@ namespace BizHawk.Client.Common
|
|||
Changed(this);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Watch)
|
||||
{
|
||||
var watch = obj as Watch;
|
||||
return this.Domain == watch.Domain && this.Address == watch.Address;
|
||||
}
|
||||
|
||||
if (obj is Cheat)
|
||||
{
|
||||
var cheat = obj as Cheat;
|
||||
return this.Domain == cheat.Domain && this.Address == cheat.Address;
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Domain.GetHashCode() + this.Address ?? 0;
|
||||
}
|
||||
|
||||
public static bool operator ==(Cheat a, Cheat b)
|
||||
{
|
||||
// If one is null, but not both, return false.
|
||||
if (((object)a == null) || ((object)b == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return a.Domain == b.Domain && a.Address == b.Address;
|
||||
}
|
||||
|
||||
public static bool operator !=(Cheat a, Cheat b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public static bool operator ==(Cheat a, Watch b)
|
||||
{
|
||||
// If one is null, but not both, return false.
|
||||
if (((object)a == null) || ((object)b == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return a.Domain == b.Domain && a.Address == b.Address;
|
||||
}
|
||||
|
||||
public static bool operator !=(Cheat a, Watch b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,12 @@ namespace BizHawk.Client.Common
|
|||
Changes = true;
|
||||
}
|
||||
|
||||
public void AddRange(IEnumerable<Cheat> cheats)
|
||||
{
|
||||
_cheatList.AddRange(cheats);
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
public void Insert(int index, Cheat c)
|
||||
{
|
||||
c.Changed += CheatChanged;
|
||||
|
@ -156,10 +162,10 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool Remove(Watch w)
|
||||
public bool Remove(Watch watch)
|
||||
{
|
||||
var cheat = _cheatList.FirstOrDefault(x => x.Domain == w.Domain && x.Address == w.Address);
|
||||
if (cheat != null)
|
||||
var cheat = _cheatList.FirstOrDefault(c => c == watch);
|
||||
if (cheat != (Cheat)null)
|
||||
{
|
||||
_cheatList.Remove(cheat);
|
||||
Changes = true;
|
||||
|
@ -171,7 +177,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public bool Contains(Cheat cheat)
|
||||
{
|
||||
return _cheatList.Any(x => x.Domain == cheat.Domain && x.Address == cheat.Address);
|
||||
return _cheatList.Any(c => c == cheat);
|
||||
}
|
||||
|
||||
public void CopyTo(Cheat[] array, int arrayIndex)
|
||||
|
@ -189,6 +195,17 @@ namespace BizHawk.Client.Common
|
|||
Changes = true;
|
||||
}
|
||||
|
||||
public void RemoveRange(IEnumerable<Watch> watches)
|
||||
{
|
||||
var removeList = _cheatList.Where(cheat => watches.Any(w => w == cheat)).ToList();
|
||||
foreach (var cheat in removeList)
|
||||
{
|
||||
_cheatList.Remove(cheat);
|
||||
}
|
||||
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_cheatList.Clear();
|
||||
|
@ -197,12 +214,14 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void DisableAll()
|
||||
{
|
||||
_cheatList.ForEach(x => x.Disable());
|
||||
_cheatList.ForEach(c => c.Disable(false));
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
public void EnableAll()
|
||||
{
|
||||
_cheatList.ForEach(x => x.Enable());
|
||||
_cheatList.ForEach(c => c.Enable(false));
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
public bool IsActive(MemoryDomain domain, int address)
|
||||
|
|
|
@ -255,6 +255,60 @@ namespace BizHawk.Client.Common
|
|||
public abstract string Diff { get; }
|
||||
|
||||
public abstract void Update();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Watch)
|
||||
{
|
||||
var watch = obj as Watch;
|
||||
return this.Domain == watch.Domain && this.Address == watch.Address;
|
||||
}
|
||||
|
||||
if (obj is Cheat)
|
||||
{
|
||||
var cheat = obj as Cheat;
|
||||
return this.Domain == cheat.Domain && this.Address == cheat.Address;
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Domain.GetHashCode() + this.Address ?? 0;
|
||||
}
|
||||
|
||||
public static bool operator ==(Watch a, Watch b)
|
||||
{
|
||||
// If one is null, but not both, return false.
|
||||
if (((object)a == null) || ((object)b == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return a.Domain == b.Domain && a.Address == b.Address;
|
||||
}
|
||||
|
||||
public static bool operator !=(Watch a, Watch b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public static bool operator ==(Watch a, Cheat b)
|
||||
{
|
||||
// If one is null, but not both, return false.
|
||||
if (((object)a == null) || ((object)b == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return a.Domain == b.Domain && a.Address == b.Address;
|
||||
}
|
||||
|
||||
public static bool operator !=(Watch a, Cheat b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SeparatorWatch : Watch
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public static FileInfo GetTasProjFileFromUser(string currentFile)
|
||||
{
|
||||
var ofd = new OpenFileDialog();
|
||||
if (!String.IsNullOrWhiteSpace(currentFile))
|
||||
if (!string.IsNullOrWhiteSpace(currentFile))
|
||||
{
|
||||
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public static FileInfo GetTasProjSaveFileFromUser(string currentFile)
|
||||
{
|
||||
var sfd = new SaveFileDialog();
|
||||
if (!String.IsNullOrWhiteSpace(currentFile))
|
||||
if (!string.IsNullOrWhiteSpace(currentFile))
|
||||
{
|
||||
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
||||
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
|
||||
|
@ -65,7 +65,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public static FileInfo GetWatchFileFromUser(string currentFile)
|
||||
{
|
||||
var ofd = new OpenFileDialog();
|
||||
if (!String.IsNullOrWhiteSpace(currentFile))
|
||||
if (!string.IsNullOrWhiteSpace(currentFile))
|
||||
{
|
||||
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public static FileInfo GetWatchSaveFileFromUser(string currentFile)
|
||||
{
|
||||
var sfd = new SaveFileDialog();
|
||||
if (!String.IsNullOrWhiteSpace(currentFile))
|
||||
if (!string.IsNullOrWhiteSpace(currentFile))
|
||||
{
|
||||
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
||||
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
|
||||
|
@ -116,7 +116,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public static FileInfo GetCheatFileFromUser(string currentFile)
|
||||
{
|
||||
var ofd = new OpenFileDialog();
|
||||
if (!String.IsNullOrWhiteSpace(currentFile))
|
||||
if (!string.IsNullOrWhiteSpace(currentFile))
|
||||
{
|
||||
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public static FileInfo GetCheatSaveFileFromUser(string currentFile)
|
||||
{
|
||||
var sfd = new SaveFileDialog();
|
||||
if (!String.IsNullOrWhiteSpace(currentFile))
|
||||
if (!string.IsNullOrWhiteSpace(currentFile))
|
||||
{
|
||||
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
||||
}
|
||||
|
@ -257,18 +257,20 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public static void FreezeAddress(IEnumerable<Watch> watches)
|
||||
{
|
||||
foreach (var watch in watches.Where(watch => !watch.IsSeparator))
|
||||
{
|
||||
Global.CheatList.Add(new Cheat(watch, watch.Value ?? 0));
|
||||
}
|
||||
Global.CheatList.AddRange(
|
||||
watches
|
||||
.Where(w => !w.IsSeparator)
|
||||
.Select(w => new Cheat(w, w.Value ?? 0)));
|
||||
|
||||
//foreach (var watch in watches.Where(watch => !watch.IsSeparator))
|
||||
//{
|
||||
// Global.CheatList.Add(new Cheat(watch, watch.Value ?? 0));
|
||||
//}
|
||||
}
|
||||
|
||||
public static void UnfreezeAddress(IEnumerable<Watch> watches)
|
||||
{
|
||||
foreach (var watch in watches.Where(watch => !watch.IsSeparator))
|
||||
{
|
||||
Global.CheatList.Remove(watch);
|
||||
}
|
||||
Global.CheatList.RemoveRange(watches.Where(watch => !watch.IsSeparator));
|
||||
}
|
||||
|
||||
public static void ViewInHexEditor(MemoryDomain domain, IEnumerable<int> addresses)
|
||||
|
@ -286,7 +288,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var column = new ColumnHeader
|
||||
{
|
||||
Name = columnName,
|
||||
Text = columnName.Replace("Column", String.Empty),
|
||||
Text = columnName.Replace("Column", string.Empty),
|
||||
Width = columnWidth,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue