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:
adelikat 2014-03-01 16:30:06 +00:00
parent 827e2c44f8
commit 97bf870b74
4 changed files with 159 additions and 27 deletions

View File

@ -160,38 +160,41 @@ namespace BizHawk.Client.Common
} }
} }
public void Enable() public void Enable(bool handleChange = true)
{ {
if (!IsSeparator) if (!IsSeparator)
{ {
var wasEnabled = _enabled; var wasEnabled = _enabled;
_enabled = true; _enabled = true;
if (!wasEnabled) if (!wasEnabled && handleChange)
{ {
Changes(); Changes();
} }
} }
} }
public void Disable() public void Disable(bool handleChange = true)
{ {
if (!IsSeparator) if (!IsSeparator)
{ {
var wasEnabled = _enabled; var wasEnabled = _enabled;
_enabled = false; _enabled = false;
if (wasEnabled) if (wasEnabled && handleChange)
{ {
Changes(); Changes();
} }
} }
} }
public void Toggle() public void Toggle(bool handleChange = true)
{ {
if (!IsSeparator) if (!IsSeparator)
{ {
_enabled ^= true; _enabled ^= true;
Changes(); if (handleChange)
{
Changes();
}
} }
} }
@ -276,5 +279,59 @@ namespace BizHawk.Client.Common
Changed(this); 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);
}
} }
} }

View File

@ -129,6 +129,12 @@ namespace BizHawk.Client.Common
Changes = true; Changes = true;
} }
public void AddRange(IEnumerable<Cheat> cheats)
{
_cheatList.AddRange(cheats);
Changes = true;
}
public void Insert(int index, Cheat c) public void Insert(int index, Cheat c)
{ {
c.Changed += CheatChanged; c.Changed += CheatChanged;
@ -156,10 +162,10 @@ namespace BizHawk.Client.Common
return false; 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); var cheat = _cheatList.FirstOrDefault(c => c == watch);
if (cheat != null) if (cheat != (Cheat)null)
{ {
_cheatList.Remove(cheat); _cheatList.Remove(cheat);
Changes = true; Changes = true;
@ -171,7 +177,7 @@ namespace BizHawk.Client.Common
public bool Contains(Cheat cheat) 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) public void CopyTo(Cheat[] array, int arrayIndex)
@ -189,6 +195,17 @@ namespace BizHawk.Client.Common
Changes = true; 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() public void Clear()
{ {
_cheatList.Clear(); _cheatList.Clear();
@ -197,12 +214,14 @@ namespace BizHawk.Client.Common
public void DisableAll() public void DisableAll()
{ {
_cheatList.ForEach(x => x.Disable()); _cheatList.ForEach(c => c.Disable(false));
Changes = true;
} }
public void EnableAll() public void EnableAll()
{ {
_cheatList.ForEach(x => x.Enable()); _cheatList.ForEach(c => c.Enable(false));
Changes = true;
} }
public bool IsActive(MemoryDomain domain, int address) public bool IsActive(MemoryDomain domain, int address)

View File

@ -255,6 +255,60 @@ namespace BizHawk.Client.Common
public abstract string Diff { get; } public abstract string Diff { get; }
public abstract void Update(); 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 public sealed class SeparatorWatch : Watch

View File

@ -14,7 +14,7 @@ namespace BizHawk.Client.EmuHawk
public static FileInfo GetTasProjFileFromUser(string currentFile) public static FileInfo GetTasProjFileFromUser(string currentFile)
{ {
var ofd = new OpenFileDialog(); var ofd = new OpenFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile)) if (!string.IsNullOrWhiteSpace(currentFile))
{ {
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile); ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
} }
@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk
public static FileInfo GetTasProjSaveFileFromUser(string currentFile) public static FileInfo GetTasProjSaveFileFromUser(string currentFile)
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile)) if (!string.IsNullOrWhiteSpace(currentFile))
{ {
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile); sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
sfd.InitialDirectory = Path.GetDirectoryName(currentFile); sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
@ -65,7 +65,7 @@ namespace BizHawk.Client.EmuHawk
public static FileInfo GetWatchFileFromUser(string currentFile) public static FileInfo GetWatchFileFromUser(string currentFile)
{ {
var ofd = new OpenFileDialog(); var ofd = new OpenFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile)) if (!string.IsNullOrWhiteSpace(currentFile))
{ {
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile); ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
} }
@ -86,7 +86,7 @@ namespace BizHawk.Client.EmuHawk
public static FileInfo GetWatchSaveFileFromUser(string currentFile) public static FileInfo GetWatchSaveFileFromUser(string currentFile)
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile)) if (!string.IsNullOrWhiteSpace(currentFile))
{ {
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile); sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
sfd.InitialDirectory = Path.GetDirectoryName(currentFile); sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
@ -116,7 +116,7 @@ namespace BizHawk.Client.EmuHawk
public static FileInfo GetCheatFileFromUser(string currentFile) public static FileInfo GetCheatFileFromUser(string currentFile)
{ {
var ofd = new OpenFileDialog(); var ofd = new OpenFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile)) if (!string.IsNullOrWhiteSpace(currentFile))
{ {
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile); ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
} }
@ -137,7 +137,7 @@ namespace BizHawk.Client.EmuHawk
public static FileInfo GetCheatSaveFileFromUser(string currentFile) public static FileInfo GetCheatSaveFileFromUser(string currentFile)
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile)) if (!string.IsNullOrWhiteSpace(currentFile))
{ {
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile); sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
} }
@ -257,18 +257,20 @@ namespace BizHawk.Client.EmuHawk
public static void FreezeAddress(IEnumerable<Watch> watches) public static void FreezeAddress(IEnumerable<Watch> watches)
{ {
foreach (var watch in watches.Where(watch => !watch.IsSeparator)) Global.CheatList.AddRange(
{ watches
Global.CheatList.Add(new Cheat(watch, watch.Value ?? 0)); .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) public static void UnfreezeAddress(IEnumerable<Watch> watches)
{ {
foreach (var watch in watches.Where(watch => !watch.IsSeparator)) Global.CheatList.RemoveRange(watches.Where(watch => !watch.IsSeparator));
{
Global.CheatList.Remove(watch);
}
} }
public static void ViewInHexEditor(MemoryDomain domain, IEnumerable<int> addresses) public static void ViewInHexEditor(MemoryDomain domain, IEnumerable<int> addresses)
@ -286,7 +288,7 @@ namespace BizHawk.Client.EmuHawk
var column = new ColumnHeader var column = new ColumnHeader
{ {
Name = columnName, Name = columnName,
Text = columnName.Replace("Column", String.Empty), Text = columnName.Replace("Column", string.Empty),
Width = columnWidth, Width = columnWidth,
}; };