-Useful refactoring!
--prevList, undoPrevList, and redoPrevList removed. All of the definitions for previous are now stored in separate data items. ---Should yield small speed increases. ---Makes it easier to port these definitions to Ram Watch eventually. ---Auto-aligns data, making it impossible for issues, such as the original values not aligning with the correct values because the prevList wasn't recreated, impossible. ---Makes it possible for the field to automatically update when the definition is changed (Implemented). --Value/PrevToString() now use the same code. --Reduces redundancy. ---This was a problem as PrevToString wasn't taking into account the data type, whereas Value was. This is now fixed. -Watch now stores the data for the "last change" previous definition. Now I just have to set up the option in the GUI.
This commit is contained in:
parent
eefb41f0b3
commit
3b54bd268a
|
@ -22,11 +22,8 @@ namespace BizHawk.MultiClient
|
|||
string systemID = "NULL";
|
||||
List<Watch> searchList = new List<Watch>();
|
||||
List<Watch> undoList = new List<Watch>();
|
||||
List<Watch> undoPrevList = new List<Watch>();
|
||||
List<Watch> weededList = new List<Watch>(); //When addresses are weeded out, the new list goes here, before going into searchList
|
||||
List<Watch> prevList = new List<Watch>();
|
||||
List<Watch> redoList = new List<Watch>();
|
||||
List<Watch> redoPrevList = new List<Watch>();
|
||||
private bool IsAWeededList = false; //For deciding whether the weeded list is relevant (0 size could mean all were removed in a legit preview
|
||||
List<ToolStripMenuItem> domainMenuItems = new List<ToolStripMenuItem>();
|
||||
MemoryDomain Domain = new MemoryDomain("NULL", 1, Endian.Little, addr => 0, (a, v) => { });
|
||||
|
@ -401,6 +398,8 @@ namespace BizHawk.MultiClient
|
|||
searchList[x].signed = GetDataType();
|
||||
searchList[x].PeekAddress(Domain);
|
||||
searchList[x].prev = searchList[x].value;
|
||||
searchList[x].original = searchList[x].value;
|
||||
searchList[x].lastsearch = searchList[x].value;
|
||||
if (includeMisalignedToolStripMenuItem.Checked)
|
||||
count++;
|
||||
else
|
||||
|
@ -422,7 +421,6 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
if (Global.Config.AlwaysExcludeRamWatch)
|
||||
ExcludeRamWatchList();
|
||||
MakePreviousList();
|
||||
SetSpecificValueBoxMaxLength();
|
||||
MessageLabel.Text = "New search started";
|
||||
sortReverse = false;
|
||||
|
@ -430,14 +428,6 @@ namespace BizHawk.MultiClient
|
|||
DisplaySearchList();
|
||||
}
|
||||
|
||||
private void MakePreviousList()
|
||||
{
|
||||
prevList = new List<Watch>();
|
||||
|
||||
for (int x = 0; x < searchList.Count; x++)
|
||||
prevList.Add(new Watch(searchList[x]));
|
||||
}
|
||||
|
||||
private void DisplaySearchList()
|
||||
{
|
||||
SearchListView.ItemCount = searchList.Count;
|
||||
|
@ -524,11 +514,8 @@ namespace BizHawk.MultiClient
|
|||
private void SaveUndo()
|
||||
{
|
||||
undoList.Clear();
|
||||
undoPrevList.Clear();
|
||||
for (int x = 0; x < searchList.Count; x++)
|
||||
undoList.Add(new Watch(searchList[x]));
|
||||
for (int x = 0; x < prevList.Count; x++)
|
||||
undoPrevList.Add(new Watch(prevList[x]));
|
||||
UndotoolStripButton.Enabled = true;
|
||||
}
|
||||
|
||||
|
@ -538,9 +525,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
MessageLabel.Text = MakeAddressString(undoList.Count - searchList.Count) + " restored";
|
||||
redoList = new List<Watch>(searchList);
|
||||
redoPrevList = new List<Watch>(prevList);
|
||||
searchList = new List<Watch>(undoList);
|
||||
prevList = new List<Watch>(undoPrevList);
|
||||
ClearUndo();
|
||||
RedotoolStripButton2.Enabled = true;
|
||||
DisplaySearchList();
|
||||
|
@ -552,14 +537,12 @@ namespace BizHawk.MultiClient
|
|||
private void ClearUndo()
|
||||
{
|
||||
undoList.Clear();
|
||||
undoPrevList.Clear();
|
||||
UndotoolStripButton.Enabled = false;
|
||||
}
|
||||
|
||||
private void ClearRedo()
|
||||
{
|
||||
redoList.Clear();
|
||||
redoPrevList.Clear();
|
||||
RedotoolStripButton2.Enabled = false;
|
||||
}
|
||||
|
||||
|
@ -569,9 +552,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
MessageLabel.Text = MakeAddressString(searchList.Count - redoList.Count) + " removed";
|
||||
undoList = new List<Watch>(searchList);
|
||||
undoPrevList = new List<Watch>(prevList);
|
||||
searchList = new List<Watch>(redoList);
|
||||
prevList = new List<Watch>(redoPrevList);
|
||||
ClearRedo();
|
||||
UndotoolStripButton.Enabled = true;
|
||||
DisplaySearchList();
|
||||
|
@ -620,10 +601,19 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
if (column == 2)
|
||||
{
|
||||
if (Global.Config.RamSearchPreviousAs == 2) //If prev frame
|
||||
text = searchList[index].PrevToString();
|
||||
else
|
||||
text = prevList[index].ValueToString();
|
||||
switch (Global.Config.RamSearchPreviousAs)
|
||||
{
|
||||
case 0:
|
||||
text = searchList[index].LastSearchToString();
|
||||
break;
|
||||
case 1:
|
||||
text = searchList[index].OriginalToString();
|
||||
break;
|
||||
default:
|
||||
case 2:
|
||||
text = searchList[index].PrevToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (column == 3)
|
||||
{
|
||||
|
@ -675,7 +665,7 @@ namespace BizHawk.MultiClient
|
|||
SaveUndo();
|
||||
MessageLabel.Text = MakeAddressString(searchList.Count - weededList.Count) + " removed";
|
||||
ReplaceSearchListWithWeedOutList();
|
||||
if (Global.Config.RamSearchPreviousAs != 1) MakePreviousList(); //1 = Original value
|
||||
UpdateLastSearch();
|
||||
DisplaySearchList();
|
||||
}
|
||||
else
|
||||
|
@ -745,14 +735,15 @@ namespace BizHawk.MultiClient
|
|||
|
||||
private int GetPreviousValue(int pos)
|
||||
{
|
||||
if (Global.Config.RamSearchPreviousAs == 2) //If Previous frame
|
||||
return searchList[pos].prev;
|
||||
else
|
||||
switch (Global.Config.RamSearchPreviousAs)
|
||||
{
|
||||
if (pos < prevList.Count)
|
||||
return prevList[pos].value;
|
||||
else
|
||||
return 0;
|
||||
case 0:
|
||||
return searchList[pos].lastsearch;
|
||||
case 1:
|
||||
return searchList[pos].original;
|
||||
default:
|
||||
case 2:
|
||||
return searchList[pos].prev;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1089,18 +1080,11 @@ namespace BizHawk.MultiClient
|
|||
searchList[x].signed = s;
|
||||
for (int x = 0; x < undoList.Count; x++)
|
||||
undoList[x].signed = s;
|
||||
for (int x = 0; x < undoPrevList.Count; x++)
|
||||
undoPrevList[x].signed = s;
|
||||
for (int x = 0; x < weededList.Count; x++)
|
||||
weededList[x].signed = s;
|
||||
for (int x = 0; x < prevList.Count; x++)
|
||||
prevList[x].signed = s;
|
||||
for (int x = 0; x < redoList.Count; x++)
|
||||
redoList[x].signed = s;
|
||||
for (int x = 0; x < redoPrevList.Count; x++)
|
||||
redoPrevList[x].signed = s;
|
||||
SetSpecificValueBoxMaxLength();
|
||||
MessageLabel.Text = "Data type converted";
|
||||
DisplaySearchList();
|
||||
}
|
||||
|
||||
|
@ -1506,16 +1490,19 @@ namespace BizHawk.MultiClient
|
|||
private void sinceLastSearchToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Global.Config.RamSearchPreviousAs = 0;
|
||||
DisplaySearchList();
|
||||
}
|
||||
|
||||
private void sinceLastFrameToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Global.Config.RamSearchPreviousAs = 2;
|
||||
DisplaySearchList();
|
||||
}
|
||||
|
||||
private void originalValueToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Global.Config.RamSearchPreviousAs = 1;
|
||||
DisplaySearchList();
|
||||
}
|
||||
|
||||
private void definePreviousValueToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
|
@ -1643,7 +1630,7 @@ namespace BizHawk.MultiClient
|
|||
SaveUndo();
|
||||
MessageLabel.Text = MakeAddressString(searchList.Count - weededList.Count) + " removed";
|
||||
ReplaceSearchListWithWeedOutList();
|
||||
if (Global.Config.RamSearchPreviousAs != 1) MakePreviousList(); //1 = Original value
|
||||
UpdateLastSearch();
|
||||
DisplaySearchList();
|
||||
}
|
||||
|
||||
|
@ -1691,13 +1678,20 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
for (int x = 0; x < searchList.Count; x++)
|
||||
{
|
||||
prevList[x].value = searchList[x].value;
|
||||
searchList[x].lastsearch = searchList[x].value;
|
||||
searchList[x].original = searchList[x].value;
|
||||
searchList[x].prev = searchList[x].value;
|
||||
}
|
||||
DisplaySearchList();
|
||||
DoPreview();
|
||||
}
|
||||
|
||||
private void UpdateLastSearch()
|
||||
{
|
||||
for (int x = 0; x < searchList.Count; x++)
|
||||
searchList[x].lastsearch = searchList[x].value;
|
||||
}
|
||||
|
||||
private void SetCurrToPrevtoolStripButton2_Click(object sender, EventArgs e)
|
||||
{
|
||||
CopyValueToPrev();
|
||||
|
@ -2009,10 +2003,17 @@ namespace BizHawk.MultiClient
|
|||
string columnName = SearchListView.Columns[columnToOrder].Text;
|
||||
if (sortedCol.CompareTo(columnName) != 0)
|
||||
sortReverse = false;
|
||||
if (columnName == "Prev" && Global.Config.RamSearchPreviousAs != 2)
|
||||
prevList.Sort((x, y) => x.CompareTo(y, columnName) * (sortReverse ? -1 : 1));
|
||||
else
|
||||
searchList.Sort((x, y) => x.CompareTo(y, columnName) * (sortReverse ? -1 : 1));
|
||||
string previous = "Last Frame";
|
||||
switch (Global.Config.RamSearchPreviousAs)
|
||||
{
|
||||
case 0:
|
||||
previous = "Last Search";
|
||||
break;
|
||||
case 1:
|
||||
previous = "Original";
|
||||
break;
|
||||
}
|
||||
searchList.Sort((x, y) => x.CompareTo(y, columnName, previous) * (sortReverse ? -1 : 1));
|
||||
sortedCol = columnName;
|
||||
sortReverse = !(sortReverse);
|
||||
SearchListView.Refresh();
|
||||
|
|
|
@ -1318,7 +1318,7 @@ namespace BizHawk.MultiClient
|
|||
string columnName = WatchListView.Columns[columnToOrder].Text;
|
||||
if (sortedCol.CompareTo(columnName) != 0)
|
||||
sortReverse = false;
|
||||
watchList.Sort((x, y) => x.CompareTo(y, columnName) * (sortReverse ? -1 : 1));
|
||||
watchList.Sort((x, y) => x.CompareTo(y, columnName, "Last Frame") * (sortReverse ? -1 : 1));
|
||||
sortedCol = columnName;
|
||||
sortReverse = !(sortReverse);
|
||||
WatchListView.Refresh();
|
||||
|
|
|
@ -23,6 +23,9 @@ namespace BizHawk.MultiClient
|
|||
notes = "";
|
||||
changecount = 0;
|
||||
prev = 0;
|
||||
original = 0;
|
||||
lastchange = 0;
|
||||
lastsearch = 0;
|
||||
}
|
||||
|
||||
public Watch(Watch w)
|
||||
|
@ -35,6 +38,9 @@ namespace BizHawk.MultiClient
|
|||
notes = w.notes;
|
||||
changecount = w.changecount;
|
||||
prev = w.prev;
|
||||
original = w.original;
|
||||
lastchange = w.lastchange;
|
||||
lastsearch = w.lastsearch;
|
||||
}
|
||||
|
||||
public Watch(int Address, int Value, atype Type, asigned Signed, bool BigEndian, string Notes)
|
||||
|
@ -47,10 +53,16 @@ namespace BizHawk.MultiClient
|
|||
notes = Notes;
|
||||
changecount = 0;
|
||||
prev = 0;
|
||||
original = value;
|
||||
lastchange = 0;
|
||||
lastsearch = value;
|
||||
}
|
||||
public int address { get; set; }
|
||||
public int value { get; set; } //Current value
|
||||
public int prev { get; set; }
|
||||
public int original { get; set; }
|
||||
public int lastchange { get; set; }
|
||||
public int lastsearch { get; set; }
|
||||
public atype type { get; set; } //Address type (byte, word, dword, etc
|
||||
public asigned signed { get; set; } //Signed/Unsigned?
|
||||
public bool bigendian { get; set; }
|
||||
|
@ -177,7 +189,10 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
|
||||
if (value != prev)
|
||||
{
|
||||
lastchange = prev;
|
||||
changecount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void PokeByte(MemoryDomain domain)
|
||||
|
@ -243,82 +258,79 @@ namespace BizHawk.MultiClient
|
|||
|
||||
StringBuilder str = new StringBuilder(notes);
|
||||
str.Append(": ");
|
||||
str.Append(ValueToString());
|
||||
str.Append(ValToString(value));
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
public string ValToString(int val)
|
||||
{
|
||||
if (type == atype.SEPARATOR)
|
||||
return "";
|
||||
else
|
||||
{
|
||||
switch (signed)
|
||||
{
|
||||
case asigned.HEX:
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case atype.BYTE:
|
||||
return String.Format("{0:X2}", val);
|
||||
case atype.WORD:
|
||||
return String.Format("{0:X4}", val);
|
||||
case atype.DWORD:
|
||||
return String.Format("{0:X8}", val);
|
||||
}
|
||||
case asigned.SIGNED:
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case atype.BYTE:
|
||||
return ((sbyte)val).ToString();
|
||||
case atype.WORD:
|
||||
return ((short)val).ToString();
|
||||
case atype.DWORD:
|
||||
return ((int)val).ToString();
|
||||
}
|
||||
default:
|
||||
case asigned.UNSIGNED:
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case atype.BYTE:
|
||||
return ((byte)val).ToString();
|
||||
case atype.WORD:
|
||||
return ((ushort)val).ToString();
|
||||
case atype.DWORD:
|
||||
return ((uint)val).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ValueToString()
|
||||
{
|
||||
if (type == atype.SEPARATOR)
|
||||
return "";
|
||||
else
|
||||
{
|
||||
switch (signed)
|
||||
{
|
||||
case asigned.HEX:
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case atype.BYTE:
|
||||
return String.Format("{0:X2}", value);
|
||||
case atype.WORD:
|
||||
return String.Format("{0:X4}", value);
|
||||
case atype.DWORD:
|
||||
return String.Format("{0:X8}", value);
|
||||
}
|
||||
case asigned.SIGNED:
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case atype.BYTE:
|
||||
return ((sbyte)value).ToString();
|
||||
case atype.WORD:
|
||||
return ((short)value).ToString();
|
||||
case atype.DWORD:
|
||||
return ((int)value).ToString();
|
||||
}
|
||||
default:
|
||||
case asigned.UNSIGNED:
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case atype.BYTE:
|
||||
return ((byte)value).ToString();
|
||||
case atype.WORD:
|
||||
return ((ushort)value).ToString();
|
||||
case atype.DWORD:
|
||||
return ((uint)value).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ValToString(value);
|
||||
}
|
||||
|
||||
public string PrevToString()
|
||||
{
|
||||
if (type == atype.SEPARATOR)
|
||||
return "";
|
||||
else
|
||||
{
|
||||
switch (signed)
|
||||
{
|
||||
case asigned.HEX:
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
case atype.BYTE:
|
||||
return String.Format("{0:X2}", prev);
|
||||
case atype.WORD:
|
||||
return String.Format("{0:X4}", prev);
|
||||
case atype.DWORD:
|
||||
return String.Format("{0:X8}", prev);
|
||||
}
|
||||
case asigned.SIGNED:
|
||||
return ((sbyte)prev).ToString();
|
||||
default:
|
||||
case asigned.UNSIGNED:
|
||||
return prev.ToString();
|
||||
}
|
||||
}
|
||||
return ValToString(prev);
|
||||
}
|
||||
|
||||
public string OriginalToString()
|
||||
{
|
||||
return ValToString(original);
|
||||
}
|
||||
|
||||
public string LastChangeToString()
|
||||
{
|
||||
return ValToString(lastchange);
|
||||
}
|
||||
|
||||
public string LastSearchToString()
|
||||
{
|
||||
return ValToString(lastsearch);
|
||||
}
|
||||
|
||||
private int CompareAddress(Watch Other)
|
||||
|
@ -351,6 +363,36 @@ namespace BizHawk.MultiClient
|
|||
return 0;
|
||||
}
|
||||
|
||||
private int CompareOriginal(Watch Other)
|
||||
{
|
||||
if (this.original < Other.original)
|
||||
return -1;
|
||||
else if (this.original > Other.original)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int CompareLastChange(Watch Other)
|
||||
{
|
||||
if (this.lastchange < Other.lastchange)
|
||||
return -1;
|
||||
else if (this.lastchange > Other.lastchange)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int CompareLastSearch(Watch Other)
|
||||
{
|
||||
if (this.lastsearch < Other.lastsearch)
|
||||
return -1;
|
||||
else if (this.lastsearch > Other.lastsearch)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int CompareChanges(Watch Other)
|
||||
{
|
||||
if (this.changecount < Other.changecount)
|
||||
|
@ -373,7 +415,7 @@ namespace BizHawk.MultiClient
|
|||
return this.notes.CompareTo(Other.notes);
|
||||
}
|
||||
|
||||
public int CompareTo(Watch Other, string parameter)
|
||||
public int CompareTo(Watch Other, string parameter, string previous)
|
||||
{
|
||||
int compare = 0;
|
||||
if (parameter == "Address")
|
||||
|
@ -387,7 +429,19 @@ namespace BizHawk.MultiClient
|
|||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
switch (previous)
|
||||
{
|
||||
case "Last Search":
|
||||
compare = CompareLastSearch(Other);
|
||||
break;
|
||||
case "Original":
|
||||
compare = CompareOriginal(Other);
|
||||
break;
|
||||
case "Last Frame":
|
||||
default:
|
||||
compare = ComparePrev(Other);
|
||||
break;
|
||||
}
|
||||
if (compare == 0)
|
||||
compare = CompareNotes(Other);
|
||||
}
|
||||
|
@ -406,7 +460,19 @@ namespace BizHawk.MultiClient
|
|||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
switch (previous)
|
||||
{
|
||||
case "Last Search":
|
||||
compare = CompareLastSearch(Other);
|
||||
break;
|
||||
case "Original":
|
||||
compare = CompareOriginal(Other);
|
||||
break;
|
||||
case "Last Frame":
|
||||
default:
|
||||
compare = ComparePrev(Other);
|
||||
break;
|
||||
}
|
||||
if (compare == 0)
|
||||
compare = CompareNotes(Other);
|
||||
}
|
||||
|
@ -416,7 +482,19 @@ namespace BizHawk.MultiClient
|
|||
|
||||
else if (parameter == "Prev")
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
switch (previous)
|
||||
{
|
||||
case "Last Search":
|
||||
compare = CompareLastSearch(Other);
|
||||
break;
|
||||
case "Original":
|
||||
compare = CompareOriginal(Other);
|
||||
break;
|
||||
case "Last Frame":
|
||||
default:
|
||||
compare = ComparePrev(Other);
|
||||
break;
|
||||
}
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = CompareAddress(Other);
|
||||
|
@ -444,7 +522,19 @@ namespace BizHawk.MultiClient
|
|||
compare = CompareValue(Other);
|
||||
if (compare == 0)
|
||||
{
|
||||
compare = ComparePrev(Other);
|
||||
switch (previous)
|
||||
{
|
||||
case "Last Search":
|
||||
compare = CompareLastSearch(Other);
|
||||
break;
|
||||
case "Original":
|
||||
compare = CompareOriginal(Other);
|
||||
break;
|
||||
case "Last Frame":
|
||||
default:
|
||||
compare = ComparePrev(Other);
|
||||
break;
|
||||
}
|
||||
if (compare == 0)
|
||||
compare = CompareNotes(Other);
|
||||
}
|
||||
|
@ -465,7 +555,19 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
compare = CompareChanges(Other);
|
||||
if (compare == 0)
|
||||
compare = ComparePrev(Other);
|
||||
switch (previous)
|
||||
{
|
||||
case "Last Search":
|
||||
compare = CompareLastSearch(Other);
|
||||
break;
|
||||
case "Original":
|
||||
compare = CompareOriginal(Other);
|
||||
break;
|
||||
case "Last Frame":
|
||||
default:
|
||||
compare = ComparePrev(Other);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue