refactor watch objects, so that the base types have a previous value as opposed to the detailed types

This commit is contained in:
adelikat 2013-09-15 16:01:16 +00:00
parent 3fa153f4cd
commit a2d60ff2c8
4 changed files with 84 additions and 37 deletions

View File

@ -69,10 +69,7 @@ namespace BizHawk.MultiClient
text = Searches[index].ValueString;
break;
case PREV:
if (Searches[index] is IWatchDetails)
{
text = (Searches[index] as IWatchDetails).PreviousStr;
}
text = Searches[index].PreviousStr;
break;
case CHANGES:
if (Searches[index] is IWatchDetails)

View File

@ -288,10 +288,7 @@ namespace BizHawk.MultiClient
text = Watches[index].ValueString;
break;
case PREV:
if (Watches[index] is IWatchDetails)
{
text = (Watches[index] as IWatchDetails).PreviousStr;
}
text = Watches[index].PreviousStr;
break;
case CHANGES:
if (Watches[index] is IWatchDetails)
@ -711,7 +708,7 @@ namespace BizHawk.MultiClient
case VALUE:
return Watches[index].ValueString;
case PREV:
return (Watches[index] as IWatchDetails).PreviousStr;
return Watches[index].PreviousStr;
case CHANGES:
return (Watches[index] as IWatchDetails).ChangeCount.ToString();
case DIFF:

View File

@ -44,6 +44,10 @@ namespace BizHawk.MultiClient
public abstract int? Value { get; }
public abstract string ValueString { get; }
public abstract WatchSize Size { get; }
public abstract int? Previous { get; }
public abstract string PreviousStr { get; }
public abstract void ResetPrevious();
public abstract bool Poke(string value);
@ -298,13 +302,8 @@ namespace BizHawk.MultiClient
{
int ChangeCount { get; }
void ClearChangeCount();
int? Previous { get; }
string PreviousStr { get; }
void ResetPrevious();
string Diff { get; }
string Notes { get; set; }
void Update();
}
@ -325,6 +324,11 @@ namespace BizHawk.MultiClient
get { return null; }
}
public override int? Previous
{
get { return null; }
}
public override string AddressString
{
get { return String.Empty; }
@ -335,6 +339,11 @@ namespace BizHawk.MultiClient
get { return String.Empty; }
}
public override string PreviousStr
{
get { return String.Empty; }
}
public override string ToString()
{
return "----";
@ -364,14 +373,22 @@ namespace BizHawk.MultiClient
{
return false;
}
public override void ResetPrevious()
{
return;
}
}
public class ByteWatch : Watch
{
protected byte _previous;
public ByteWatch(MemoryDomain domain, int address)
{
_address = address;
_domain = domain;
_previous = GetByte();
}
public override int? Address
@ -389,6 +406,21 @@ namespace BizHawk.MultiClient
get { return FormatValue(GetByte()); }
}
public override int? Previous
{
get { return _previous; }
}
public override string PreviousStr
{
get { return FormatValue(_previous); }
}
public override void ResetPrevious()
{
_previous = GetByte();
}
public override string ToString()
{
return AddressString + ": " + ValueString;
@ -490,16 +522,15 @@ namespace BizHawk.MultiClient
}
}
public class DetailedByteWatch : ByteWatch, IWatchDetails
public sealed class DetailedByteWatch : ByteWatch, IWatchDetails
{
private byte _value;
private byte _previous;
public DetailedByteWatch(MemoryDomain domain, int address)
: base(domain, address)
{
Notes = String.Empty;
_previous = _value = GetByte();
_value = GetByte();
}
public override string ToString()
@ -510,10 +541,6 @@ namespace BizHawk.MultiClient
public int ChangeCount { get; private set; }
public void ClearChangeCount() { ChangeCount = 0; }
public int? Previous { get { return _previous; } }
public string PreviousStr { get { return FormatValue(_previous); } }
public void ResetPrevious() { _previous = _value; }
public string Diff
{
get
@ -565,10 +592,13 @@ namespace BizHawk.MultiClient
public class WordWatch : Watch
{
protected ushort _previous;
public WordWatch(MemoryDomain domain, int address)
{
_domain = domain;
_address = address;
_previous = GetWord();
}
public override int? Value
@ -576,6 +606,21 @@ namespace BizHawk.MultiClient
get { return GetWord(); }
}
public override int? Previous
{
get { return _previous; }
}
public override string PreviousStr
{
get { return FormatValue(_previous); }
}
public override void ResetPrevious()
{
_previous = GetWord();
}
public override WatchSize Size
{
get { return WatchSize.Word; }
@ -688,16 +733,15 @@ namespace BizHawk.MultiClient
}
}
public class DetailedWordWatch : WordWatch, IWatchDetails
public sealed class DetailedWordWatch : WordWatch, IWatchDetails
{
private ushort _value;
private ushort _previous;
public DetailedWordWatch(MemoryDomain domain, int address)
: base(domain, address)
{
Notes = String.Empty;
_previous = _value = GetWord();
_value = GetWord();
}
public override string ToString()
@ -708,10 +752,6 @@ namespace BizHawk.MultiClient
public int ChangeCount { get; private set; }
public void ClearChangeCount() { ChangeCount = 0; }
public int? Previous { get { return _previous; } }
public string PreviousStr { get { return FormatValue(_previous); } }
public void ResetPrevious() { _previous = _value; }
public string Diff
{
get { return FormatValue((ushort)(_previous - _value)); }
@ -751,10 +791,13 @@ namespace BizHawk.MultiClient
public class DWordWatch : Watch
{
protected uint _previous;
public DWordWatch(MemoryDomain domain, int address)
{
_domain = domain;
_address = address;
_previous = GetDWord();
}
public override int? Value
@ -762,6 +805,21 @@ namespace BizHawk.MultiClient
get { return (int)GetDWord(); }
}
public override int? Previous
{
get { return (int)_previous; }
}
public override string PreviousStr
{
get { return FormatValue(_previous); }
}
public override void ResetPrevious()
{
_previous = GetWord();
}
public override WatchSize Size
{
get { return WatchSize.DWord; }
@ -876,16 +934,15 @@ namespace BizHawk.MultiClient
}
}
public class DetailedDWordWatch : DWordWatch, IWatchDetails
public sealed class DetailedDWordWatch : DWordWatch, IWatchDetails
{
private uint _value;
private uint _previous;
public DetailedDWordWatch(MemoryDomain domain, int address)
: base(domain, address)
{
Notes = String.Empty;
_previous = _value = GetDWord();
_value = GetDWord();
}
public override string ToString()
@ -895,10 +952,6 @@ namespace BizHawk.MultiClient
public int ChangeCount { get; private set; }
public void ClearChangeCount() { ChangeCount = 0; }
public int? Previous { get { return (int)_previous; } }
public string PreviousStr { get { return FormatValue(_previous); } }
public void ResetPrevious() { _previous = _value; }
public string Diff
{
get { return FormatValue(_previous - _value); }

View File

@ -117,7 +117,7 @@ namespace BizHawk.MultiClient
if (reverse)
{
_watchList = _watchList
.OrderByDescending(x => (x as IWatchDetails).PreviousStr)
.OrderByDescending(x => x.PreviousStr)
.ThenBy(x => x.Address ?? 0)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
@ -126,7 +126,7 @@ namespace BizHawk.MultiClient
else
{
_watchList = _watchList
.OrderBy(x => (x as IWatchDetails).PreviousStr)
.OrderBy(x => x.PreviousStr)
.ThenBy(x => x.Address ?? 0)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)