diff --git a/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs b/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs index 3a121a0624..ac5e698a7e 100644 --- a/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs +++ b/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs @@ -731,7 +731,7 @@ namespace BizHawk.MultiClient var Watches = new List(); foreach (var address in addresses) { - Watch w = Watch.GenerateWatch(Domain, address, (Watch.WatchSize)DataSize, false); + Watch w = Watch.GenerateWatch(Domain, address, (Watch.WatchSize)DataSize); w.Type = Watch.DisplayType.Hex; Watches.Add(w); diff --git a/BizHawk.MultiClient/tools/Watch/RamSearch.cs b/BizHawk.MultiClient/tools/Watch/RamSearch.cs index 8252dc5bd5..0644bff254 100644 --- a/BizHawk.MultiClient/tools/Watch/RamSearch.cs +++ b/BizHawk.MultiClient/tools/Watch/RamSearch.cs @@ -132,16 +132,10 @@ namespace BizHawk.MultiClient text = Searches[index].PreviousStr; break; case CHANGES: - if (Searches[index] is IWatchDetails) - { - text = (Searches[index] as IWatchDetails).ChangeCount.ToString(); - } + text = Searches[index].ChangeCount.ToString(); break; case DIFF: - if (Searches[index] is IWatchDetails) - { - text = (Searches[index] as IWatchDetails).Diff; - } + text = Searches[index].Diff; break; } } @@ -492,7 +486,7 @@ namespace BizHawk.MultiClient } WatchList watches = new WatchList(Settings.Domain); - watches.Load(file.FullName, false, append); + watches.Load(file.FullName, append); List addresses = watches.Where(x => !x.IsSeparator).Select(x => x.Address.Value).ToList(); if (truncate) @@ -613,9 +607,9 @@ namespace BizHawk.MultiClient case PREV: return Searches[index].PreviousStr; case CHANGES: - return (Searches[index] as IWatchDetails).ChangeCount.ToString(); + return Searches[index].ChangeCount.ToString(); case DIFF: - return (Searches[index] as IWatchDetails).Diff; + return Searches[index].Diff; } } diff --git a/BizHawk.MultiClient/tools/Watch/RamWatch.cs b/BizHawk.MultiClient/tools/Watch/RamWatch.cs index 4c472d0102..45bb219bab 100644 --- a/BizHawk.MultiClient/tools/Watch/RamWatch.cs +++ b/BizHawk.MultiClient/tools/Watch/RamWatch.cs @@ -124,7 +124,7 @@ namespace BizHawk.MultiClient if (result) { - Watches.Load(file.FullName, true, append); + Watches.Load(file.FullName, append); DisplayWatches(); UpdateMessageLabel(); UpdateWatchCount(); @@ -298,25 +298,19 @@ namespace BizHawk.MultiClient text = Watches[index].PreviousStr; break; case CHANGES: - if (Watches[index] is IWatchDetails) + if (!Watches[index].IsSeparator) { - text = (Watches[index] as IWatchDetails).ChangeCount.ToString(); + text = Watches[index].ChangeCount.ToString(); } break; case DIFF: - if (Watches[index] is IWatchDetails) - { - text = (Watches[index] as IWatchDetails).Diff; - } + text = Watches[index].Diff; break; case DOMAIN: text = Watches[index].Domain.Name; break; case NOTES: - if (Watches[index] is IWatchDetails) - { - text = (Watches[index] as IWatchDetails).Notes; - } + text = Watches[index].Notes; break; } } @@ -365,7 +359,7 @@ namespace BizHawk.MultiClient if (ask_result) { - bool load_result = Watches.Load(path, details: true, append: false); + bool load_result = Watches.Load(path, append: false); if (!load_result) { Global.Config.RecentWatches.HandleLoadError(path); @@ -717,13 +711,13 @@ namespace BizHawk.MultiClient case PREV: return Watches[index].PreviousStr; case CHANGES: - return (Watches[index] as IWatchDetails).ChangeCount.ToString(); + return Watches[index].ChangeCount.ToString(); case DIFF: - return (Watches[index] as IWatchDetails).Diff; + return Watches[index].Diff; case DOMAIN: return Watches[index].Domain.Name; case NOTES: - return (Watches[index] as IWatchDetails).Notes; + return Watches[index].Notes; } } @@ -788,7 +782,7 @@ namespace BizHawk.MultiClient string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); if (Path.GetExtension(filePaths[0]) == (".wch")) { - Watches.Load(filePaths[0], true, false); + Watches.Load(filePaths[0], append:false); DisplayWatches(); } } diff --git a/BizHawk.MultiClient/tools/Watch/Watch.cs b/BizHawk.MultiClient/tools/Watch/Watch.cs index 35da1661df..2ba3abe113 100644 --- a/BizHawk.MultiClient/tools/Watch/Watch.cs +++ b/BizHawk.MultiClient/tools/Watch/Watch.cs @@ -40,6 +40,8 @@ namespace BizHawk.MultiClient protected MemoryDomain _domain; protected DisplayType _type; protected bool _bigEndian; + protected int _changecount; + protected string _notes = String.Empty; public abstract int? Value { get; } public abstract string ValueString { get; } @@ -193,7 +195,12 @@ namespace BizHawk.MultiClient _domain.PokeDWord(_address, val, _bigEndian ? Endian.Big : Endian.Little); } - public static Watch GenerateWatch(MemoryDomain domain, int address, WatchSize size, bool details) + public void ClearChangeCount() { _changecount = 0; } + + public string Notes { get { return _notes; } set { _notes = value; } } + + //TODO: delete me + public static Watch GenerateWatch(MemoryDomain domain, int address, WatchSize size) { switch (size) { @@ -201,32 +208,11 @@ namespace BizHawk.MultiClient case WatchSize.Separator: return new SeparatorWatch(); case WatchSize.Byte: - if (details) - { - return new DetailedByteWatch(domain, address); - } - else - { - return new ByteWatch(domain, address); - } + return new ByteWatch(domain, address); case WatchSize.Word: - if (details) - { - return new DetailedWordWatch(domain, address); - } - else - { - return new WordWatch(domain, address); - } + return new WordWatch(domain, address); case WatchSize.DWord: - if (details) - { - return new DetailedDWordWatch(domain, address); - } - else - { - return new DWordWatch(domain, address); - } + return new DWordWatch(domain, address); } } @@ -238,11 +224,11 @@ namespace BizHawk.MultiClient case WatchSize.Separator: return new SeparatorWatch(); case WatchSize.Byte: - return new DetailedByteWatch(domain, address, type, bigendian, (byte)prev, changecount); + return new ByteWatch(domain, address, type, bigendian, (byte)prev, changecount); case WatchSize.Word: - return new DetailedWordWatch(domain, address, type, bigendian, (ushort)prev, changecount); + return new WordWatch(domain, address, type, bigendian, (ushort)prev, changecount); case WatchSize.DWord: - return new DetailedDWordWatch(domain, address, type, bigendian, (uint)prev, changecount); + return new DWordWatch(domain, address, type, bigendian, (uint)prev, changecount); } } @@ -261,18 +247,15 @@ namespace BizHawk.MultiClient return DWordWatch.ValidTypes; } } + + public int ChangeCount { get { return _changecount; } } + + public abstract string Diff { get; } + + public abstract void Update(); } - public interface IWatchDetails - { - int ChangeCount { get; } - void ClearChangeCount(); - string Diff { get; } - string Notes { get; set; } - void Update(); - } - - public class SeparatorWatch : Watch + public sealed class SeparatorWatch : Watch { public static SeparatorWatch Instance { @@ -343,17 +326,32 @@ namespace BizHawk.MultiClient { return; } + + public override string Diff { get { return String.Empty; } } + + public override void Update() { return; } } - public class ByteWatch : Watch + public sealed class ByteWatch : Watch { - protected byte _previous; + private byte _previous; + private byte _value; public ByteWatch(MemoryDomain domain, int address) { _address = address; _domain = domain; - _previous = GetByte(); + _value = _previous = GetByte(); + Notes = String.Empty; + } + + public ByteWatch(MemoryDomain domain, int address, DisplayType type, bool bigEndian, byte prev, int changeCount) + : this(domain, address) + { + _previous = prev; + _changecount = changeCount; + _type = type; + _bigEndian = bigEndian; } public override int? Address @@ -388,7 +386,7 @@ namespace BizHawk.MultiClient public override string ToString() { - return AddressString + ": " + ValueString; + return Notes + ": " + ValueString; } public override bool IsSeparator @@ -412,7 +410,7 @@ namespace BizHawk.MultiClient } } - protected string FormatValue(byte val) + private string FormatValue(byte val) { switch (Type) { @@ -485,37 +483,8 @@ namespace BizHawk.MultiClient return false; } } - } - public sealed class DetailedByteWatch : ByteWatch, IWatchDetails - { - private byte _value; - - public DetailedByteWatch(MemoryDomain domain, int address) - : base(domain, address) - { - Notes = String.Empty; - _value = GetByte(); - } - - public DetailedByteWatch(MemoryDomain domain, int address, DisplayType type, bool bigEndian, byte prev, int changeCount) - : this(domain, address) - { - _previous = prev; - ChangeCount = changeCount; - _type = type; - _bigEndian = bigEndian; - } - - public override string ToString() - { - return Notes + ": " + ValueString; - } - - public int ChangeCount { get; private set; } - public void ClearChangeCount() { ChangeCount = 0; } - - public string Diff + public override string Diff { get { @@ -533,23 +502,19 @@ namespace BizHawk.MultiClient } } - public string Notes { get; set; } - - public void Update() + public override void Update() { switch (Global.Config.RamWatchDefinePrevious) { - case PreviousType.LastSearch: //TODO case PreviousType.Original: - /*Do Nothing*/ - break; + return; case PreviousType.LastChange: var temp = _value; _value = GetByte(); if (_value != temp) { _previous = _value; - ChangeCount++; + _changecount++; } break; case PreviousType.LastFrame: @@ -557,22 +522,33 @@ namespace BizHawk.MultiClient _value = GetByte(); if (_value != Previous) { - ChangeCount++; + _changecount++; } break; } } } - public class WordWatch : Watch + public sealed class WordWatch : Watch { - protected ushort _previous; + private ushort _previous; + private ushort _value; public WordWatch(MemoryDomain domain, int address) { _domain = domain; _address = address; - _previous = GetWord(); + _value = _previous = GetWord(); + Notes = String.Empty; + } + + public WordWatch(MemoryDomain domain, int address, DisplayType type, bool bigEndian, ushort prev, int changeCount) + : this(domain, address) + { + _previous = prev; + _changecount = changeCount; + _type = type; + _bigEndian = bigEndian; } public override int? Value @@ -618,10 +594,10 @@ namespace BizHawk.MultiClient public override string ToString() { - return AddressString + ": " + ValueString; + return Notes + ": " + ValueString; } - protected string FormatValue(ushort val) + private string FormatValue(ushort val) { switch (Type) { @@ -704,51 +680,18 @@ namespace BizHawk.MultiClient return false; } } - } - public sealed class DetailedWordWatch : WordWatch, IWatchDetails - { - private ushort _value; - - public DetailedWordWatch(MemoryDomain domain, int address) - : base(domain, address) - { - Notes = String.Empty; - _value = GetWord(); - } - - public DetailedWordWatch(MemoryDomain domain, int address, DisplayType type, bool bigEndian, ushort prev, int changeCount) - : this(domain, address) - { - _previous = prev; - ChangeCount = changeCount; - _type = type; - _bigEndian = bigEndian; - } - - public override string ToString() - { - return Notes + ": " + ValueString; - } - - public int ChangeCount { get; private set; } - public void ClearChangeCount() { ChangeCount = 0; } - - public string Diff + public override string Diff { get { return FormatValue((ushort)(_previous - _value)); } } - public string Notes { get; set; } - - public void Update() + public override void Update() { switch (Global.Config.RamWatchDefinePrevious) { - case PreviousType.LastSearch: //TODO case PreviousType.Original: - /*Do Nothing*/ - break; + return; case PreviousType.LastChange: var temp = _value; _value = GetWord(); @@ -756,7 +699,7 @@ namespace BizHawk.MultiClient if (_value != temp) { _previous = temp; - ChangeCount++; + _changecount++; } break; case PreviousType.LastFrame: @@ -764,22 +707,33 @@ namespace BizHawk.MultiClient _value = GetWord(); if (_value != Previous) { - ChangeCount++; + _changecount++; } break; } } } - public class DWordWatch : Watch + public sealed class DWordWatch : Watch { - protected uint _previous; + private uint _value; + private uint _previous; public DWordWatch(MemoryDomain domain, int address) { _domain = domain; _address = address; - _previous = GetDWord(); + _value = _previous = GetDWord(); + Notes = String.Empty; + } + + public DWordWatch(MemoryDomain domain, int address, DisplayType type, bool bigEndian, uint prev, int changeCount) + : this(domain, address) + { + _previous = prev; + _changecount = changeCount; + _type = type; + _bigEndian = bigEndian; } public override int? Value @@ -825,10 +779,10 @@ namespace BizHawk.MultiClient public override string ToString() { - return AddressString + ": " + ValueString; + return Notes + ": " + ValueString; } - protected string FormatValue(uint val) + private string FormatValue(uint val) { switch (Type) { @@ -912,57 +866,25 @@ namespace BizHawk.MultiClient return false; } } - } - public sealed class DetailedDWordWatch : DWordWatch, IWatchDetails - { - private uint _value; - - public DetailedDWordWatch(MemoryDomain domain, int address) - : base(domain, address) - { - Notes = String.Empty; - _value = GetDWord(); - } - - public DetailedDWordWatch(MemoryDomain domain, int address, DisplayType type, bool bigEndian, uint prev, int changeCount) - : this(domain, address) - { - _previous = prev; - ChangeCount = changeCount; - _type = type; - _bigEndian = bigEndian; - } - - public override string ToString() - { - return Notes + ": " + ValueString; - } - public int ChangeCount { get; private set; } - public void ClearChangeCount() { ChangeCount = 0; } - - public string Diff + public override string Diff { get { return FormatValue(_previous - _value); } } - public string Notes { get; set; } - - public void Update() + public override void Update() { switch (Global.Config.RamWatchDefinePrevious) { - case PreviousType.LastSearch: //TODO case PreviousType.Original: - /*Do Nothing*/ - break; + return; case PreviousType.LastChange: var temp = _value; _value = GetDWord(); if (_value != temp) { _previous = _value; - ChangeCount++; + _changecount++; } break; case PreviousType.LastFrame: @@ -970,7 +892,7 @@ namespace BizHawk.MultiClient _value = GetDWord(); if (_value != Previous) { - ChangeCount++; + _changecount++; } break; } diff --git a/BizHawk.MultiClient/tools/Watch/WatchEditor.cs b/BizHawk.MultiClient/tools/Watch/WatchEditor.cs index 632256689f..b0024d46a0 100644 --- a/BizHawk.MultiClient/tools/Watch/WatchEditor.cs +++ b/BizHawk.MultiClient/tools/Watch/WatchEditor.cs @@ -76,7 +76,7 @@ namespace BizHawk.MultiClient } else { - NotesBox.Text = (_watchList[0] as IWatchDetails).Notes; + NotesBox.Text = _watchList[0].Notes; AddressBox.Text = _watchList[0].AddressString; } @@ -224,7 +224,7 @@ namespace BizHawk.MultiClient switch (SizeDropDown.SelectedIndex) { case 0: - _watchList.Add(new DetailedByteWatch(domain, address) + _watchList.Add(new ByteWatch(domain, address) { Notes = notes, Type = type, @@ -233,7 +233,7 @@ namespace BizHawk.MultiClient ); break; case 1: - _watchList.Add(new DetailedWordWatch(domain, address) + _watchList.Add(new WordWatch(domain, address) { Notes = notes, Type = type, @@ -242,7 +242,7 @@ namespace BizHawk.MultiClient ); break; case 2: - _watchList.Add(new DetailedDWordWatch(domain, address) + _watchList.Add(new DWordWatch(domain, address) { Notes = notes, Type = type, @@ -261,9 +261,9 @@ namespace BizHawk.MultiClient _watchList.Clear(); foreach (var watch in tempWatchList) { - var newWatch = Watch.GenerateWatch(watch.Domain, watch.Address.Value, watch.Size, details: true); + var newWatch = Watch.GenerateWatch(watch.Domain, watch.Address.Value, watch.Size); newWatch.Type = watch.Type; - (newWatch as IWatchDetails).Notes = (watch as IWatchDetails).Notes; + newWatch.Notes = watch.Notes; _watchList.Add(watch); } DoEdit(); @@ -277,7 +277,7 @@ namespace BizHawk.MultiClient { if (_watchList.Count == 1) { - (_watchList[0] as IWatchDetails).Notes = NotesBox.Text; + _watchList[0].Notes = NotesBox.Text; } if (_changedSize) @@ -297,13 +297,13 @@ namespace BizHawk.MultiClient size = Watch.WatchSize.DWord; break; } - string tempNotes = (_watchList[i] as IWatchDetails).Notes; + string tempNotes = _watchList[i].Notes; _watchList[i] = Watch.GenerateWatch( _watchList[i].Domain, _watchList.Count == 1 ? AddressBox.ToInt() : _watchList[i].Address.Value, - size, - details: true); - (_watchList[i] as IWatchDetails).Notes = tempNotes; + size + ); + _watchList[i].Notes = tempNotes; } } if (_changedDisplayType) diff --git a/BizHawk.MultiClient/tools/Watch/WatchList.cs b/BizHawk.MultiClient/tools/Watch/WatchList.cs index f4d2fa189b..4b373683cd 100644 --- a/BizHawk.MultiClient/tools/Watch/WatchList.cs +++ b/BizHawk.MultiClient/tools/Watch/WatchList.cs @@ -137,7 +137,7 @@ namespace BizHawk.MultiClient if (reverse) { _watchList = _watchList - .OrderByDescending(x => (x as IWatchDetails).Diff) + .OrderByDescending(x => x.Diff) .ThenBy(x => x.Address ?? 0) .ThenBy(x => x.Size) .ThenBy(x => x.Type) @@ -146,7 +146,7 @@ namespace BizHawk.MultiClient else { _watchList = _watchList - .OrderBy(x => (x as IWatchDetails).Diff) + .OrderBy(x => x.Diff) .ThenBy(x => x.Address ?? 0) .ThenBy(x => x.Size) .ThenBy(x => x.Type) @@ -157,7 +157,7 @@ namespace BizHawk.MultiClient if (reverse) { _watchList = _watchList - .OrderByDescending(x => (x as IWatchDetails).ChangeCount) + .OrderByDescending(x => x.ChangeCount) .ThenBy(x => x.Address ?? 0) .ThenBy(x => x.Size) .ThenBy(x => x.Type) @@ -166,7 +166,7 @@ namespace BizHawk.MultiClient else { _watchList = _watchList - .OrderBy(x => (x as IWatchDetails).ChangeCount) + .OrderBy(x => x.ChangeCount) .ThenBy(x => x.Address ?? 0) .ThenBy(x => x.Size) .ThenBy(x => x.Type) @@ -199,7 +199,7 @@ namespace BizHawk.MultiClient if (reverse) { _watchList = _watchList - .OrderByDescending(x => (x as IWatchDetails).Notes) + .OrderByDescending(x => x.Notes) .ThenBy(x => x.Address ?? 0) .ThenBy(x => x.Size) .ThenBy(x => x.Type) @@ -208,7 +208,7 @@ namespace BizHawk.MultiClient else { _watchList = _watchList - .OrderBy(x => (x as IWatchDetails).Notes) + .OrderBy(x => x.Notes) .ThenBy(x => x.Address ?? 0) .ThenBy(x => x.Size) .ThenBy(x => x.Type) @@ -244,8 +244,7 @@ namespace BizHawk.MultiClient public void UpdateValues() { - var detailedWatches = _watchList.OfType().ToList(); - foreach (var watch in detailedWatches) + foreach (var watch in _watchList) { watch.Update(); } @@ -276,8 +275,7 @@ namespace BizHawk.MultiClient public void ClearChangeCounts() { - var detailedWatches = _watchList.OfType().ToList(); - foreach (var watch in detailedWatches) + foreach (var watch in _watchList) { watch.ClearChangeCount(); } @@ -308,9 +306,9 @@ namespace BizHawk.MultiClient return result; } - public bool Load(string path, bool details, bool append) + public bool Load(string path, bool append) { - bool result = LoadFile(path, details, append); + bool result = LoadFile(path, append); if (result) { @@ -332,7 +330,7 @@ namespace BizHawk.MultiClient { if (!String.IsNullOrWhiteSpace(CurrentFileName)) { - LoadFile(CurrentFileName, true, false); + LoadFile(CurrentFileName, append:false); Changes = false; } } @@ -359,7 +357,7 @@ namespace BizHawk.MultiClient .Append(w.TypeAsChar).Append('\t') .Append(w.BigEndian ? '1' : '0').Append('\t') .Append(w.Domain.Name).Append('\t') - .Append(w is IWatchDetails ? (w as IWatchDetails).Notes : String.Empty) + .Append(w.Notes) .AppendLine(); } @@ -383,7 +381,7 @@ namespace BizHawk.MultiClient } } - private bool LoadFile(string path, bool details, bool append) + private bool LoadFile(string path, bool append) { string domain = ""; var file = new FileInfo(path); @@ -500,13 +498,10 @@ namespace BizHawk.MultiClient startIndex = line.IndexOf('\t') + 1; string notes = line.Substring(startIndex, line.Length - startIndex); - Watch w = Watch.GenerateWatch(memDomain, addr, size, details); + Watch w = Watch.GenerateWatch(memDomain, addr, size); w.BigEndian = bigEndian; w.Type = type; - if (w is IWatchDetails) - { - (w as IWatchDetails).Notes = notes; - } + w.Notes = notes; _watchList.Add(w); _domain = Global.Emulator.MemoryDomains[GetDomainPos(domain)];