Branch states on RAM should work. (Disk states will break things.)
This commit is contained in:
parent
4eec497174
commit
4ce346661b
|
@ -77,11 +77,20 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
|
|
||||||
public TasLagLog TasLagLog { get { return LagLog; } }
|
public TasLagLog TasLagLog { get { return LagLog; } }
|
||||||
public TasBranchCollection TasBranches { get { return Branches; } }
|
|
||||||
public List<string> InputLog { get { return _log; } }
|
public List<string> InputLog { get { return _log; } }
|
||||||
public TasMovieMarkerList Markers { get; set; }
|
public TasMovieMarkerList Markers { get; set; }
|
||||||
public bool BindMarkersToInput { get; set; }
|
public bool BindMarkersToInput { get; set; }
|
||||||
public bool UseInputCache { get; set; }
|
public bool UseInputCache { get; set; }
|
||||||
|
public TasBranch GetBranch(int id) { return Branches[id]; }
|
||||||
|
public int BranchCount { get { return Branches.Count; } }
|
||||||
|
public int BranchIndex(int frame)
|
||||||
|
{
|
||||||
|
TasBranch branch = Branches.Where(b => b.Frame == frame)
|
||||||
|
.OrderByDescending(b => b.TimeStamp).FirstOrDefault();
|
||||||
|
if (branch == null)
|
||||||
|
return -1;
|
||||||
|
return Branches.IndexOf(branch);
|
||||||
|
}
|
||||||
|
|
||||||
public override string PreferredExtension
|
public override string PreferredExtension
|
||||||
{
|
{
|
||||||
|
@ -467,10 +476,11 @@ namespace BizHawk.Client.Common
|
||||||
_changes = true;
|
_changes = true;
|
||||||
LagLog.FromLagLog(branch.LagLog);
|
LagLog.FromLagLog(branch.LagLog);
|
||||||
|
|
||||||
if (divergentPoint.HasValue)
|
//if (divergentPoint.HasValue)
|
||||||
StateManager.Invalidate(divergentPoint.Value);
|
// StateManager.Invalidate(divergentPoint.Value);
|
||||||
else
|
//else
|
||||||
StateManager.Invalidate(branch.InputLog.Count);
|
// StateManager.Invalidate(branch.InputLog.Count);
|
||||||
|
StateManager.LoadBranch(Branches.IndexOf(branch));
|
||||||
|
|
||||||
StateManager.SetState(branch.Frame, branch.CoreData);
|
StateManager.SetState(branch.Frame, branch.CoreData);
|
||||||
|
|
||||||
|
@ -496,5 +506,35 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddBranch(TasBranch branch)
|
||||||
|
{
|
||||||
|
Branches.Add(branch);
|
||||||
|
TasStateManager.AddBranch();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveBranch(TasBranch branch)
|
||||||
|
{
|
||||||
|
TasStateManager.RemoveBranch(Branches.IndexOf(branch));
|
||||||
|
Branches.Remove(branch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateBranch(TasBranch old, TasBranch newBranch)
|
||||||
|
{
|
||||||
|
int index = Branches.IndexOf(old);
|
||||||
|
Branches[index] = newBranch;
|
||||||
|
TasStateManager.UpdateBranch(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SwapBranches(int b1, int b2)
|
||||||
|
{
|
||||||
|
TasBranch branch = Branches[b1];
|
||||||
|
|
||||||
|
if (b2 >= Branches.Count)
|
||||||
|
b2 = Branches.Count - 1;
|
||||||
|
|
||||||
|
Branches.Remove(branch);
|
||||||
|
Branches.Insert(b2, branch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
private Guid guid = Guid.NewGuid();
|
private Guid guid = Guid.NewGuid();
|
||||||
private SortedList<int, byte[]> States = new SortedList<int, byte[]>();
|
private SortedList<int, byte[]> States = new SortedList<int, byte[]>();
|
||||||
|
private SortedList<int, SortedList<int, byte[]>> BranchStates = new SortedList<int, SortedList<int, byte[]>>();
|
||||||
|
private int branches = 0;
|
||||||
private string statePath
|
private string statePath
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -570,5 +572,79 @@ namespace BizHawk.Client.Common
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region "Branches"
|
||||||
|
|
||||||
|
public void AddBranch()
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<int, byte[]> kvp in States)
|
||||||
|
{
|
||||||
|
if (!BranchStates.ContainsKey(kvp.Key))
|
||||||
|
BranchStates.Add(kvp.Key, new SortedList<int, byte[]>());
|
||||||
|
SortedList<int, byte[]> stateList = BranchStates[kvp.Key];
|
||||||
|
if (stateList == null)
|
||||||
|
{
|
||||||
|
stateList = new SortedList<int, byte[]>();
|
||||||
|
BranchStates[kvp.Key] = stateList;
|
||||||
|
}
|
||||||
|
stateList.Add(branches, kvp.Value);
|
||||||
|
}
|
||||||
|
branches++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveBranch(int index)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<int, SortedList<int, byte[]>> kvp in BranchStates)
|
||||||
|
{
|
||||||
|
SortedList<int, byte[]> stateList = kvp.Value;
|
||||||
|
if (stateList == null)
|
||||||
|
continue;
|
||||||
|
stateList.Remove(index);
|
||||||
|
if (stateList.Count == 0)
|
||||||
|
BranchStates[kvp.Key] = null;
|
||||||
|
}
|
||||||
|
branches--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateBranch(int index)
|
||||||
|
{
|
||||||
|
// RemoveBranch
|
||||||
|
foreach (KeyValuePair<int, SortedList<int, byte[]>> kvp in BranchStates)
|
||||||
|
{
|
||||||
|
SortedList<int, byte[]> stateList = kvp.Value;
|
||||||
|
if (stateList == null)
|
||||||
|
continue;
|
||||||
|
stateList.Remove(index);
|
||||||
|
if (stateList.Count == 0)
|
||||||
|
BranchStates[kvp.Key] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddBranch
|
||||||
|
foreach (KeyValuePair<int, byte[]> kvp in States)
|
||||||
|
{
|
||||||
|
SortedList<int, byte[]> stateList = BranchStates[kvp.Key];
|
||||||
|
if (stateList == null)
|
||||||
|
{
|
||||||
|
stateList = new SortedList<int, byte[]>();
|
||||||
|
BranchStates[kvp.Key] = stateList;
|
||||||
|
}
|
||||||
|
stateList.Add(index, kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadBranch(int index)
|
||||||
|
{
|
||||||
|
Invalidate(0); // Not a good way of doing it?
|
||||||
|
foreach (KeyValuePair<int, SortedList<int, byte[]>> kvp in BranchStates)
|
||||||
|
{
|
||||||
|
if (kvp.Key == 0 && States.ContainsKey(0))
|
||||||
|
continue; // TODO: It might be a better idea to just not put state 0 in BranchStates.
|
||||||
|
|
||||||
|
if (kvp.Value.ContainsKey(index))
|
||||||
|
SetState(kvp.Key, kvp.Value[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private readonly PlatformFrameRates FrameRates = new PlatformFrameRates();
|
private readonly PlatformFrameRates FrameRates = new PlatformFrameRates();
|
||||||
public TAStudio Tastudio { get; set; }
|
public TAStudio Tastudio { get; set; }
|
||||||
|
private TasMovie Movie { get { return Tastudio.CurrentTasMovie; } }
|
||||||
|
|
||||||
public TasBranchCollection Branches
|
private TasBranch GetBranch(int id)
|
||||||
{
|
{
|
||||||
get { return Tastudio.CurrentTasMovie.TasBranches; }
|
return Tastudio.CurrentTasMovie.GetBranch(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BookmarksBranchesBox()
|
public BookmarksBranchesBox()
|
||||||
|
@ -63,7 +64,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (BranchView.AnyRowsSelected)
|
if (BranchView.AnyRowsSelected)
|
||||||
{
|
{
|
||||||
return Branches[BranchView.SelectedRows.First()];
|
return GetBranch(BranchView.SelectedRows.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -76,7 +77,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
text = string.Empty;
|
text = string.Empty;
|
||||||
|
|
||||||
if (index >= Tastudio.CurrentTasMovie.TasBranches.Count)
|
if (index >= Movie.BranchCount)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -87,10 +88,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
text = index.ToString();
|
text = index.ToString();
|
||||||
break;
|
break;
|
||||||
case FrameColumnName:
|
case FrameColumnName:
|
||||||
text = Branches[index].Frame.ToString();
|
text = GetBranch(index).Frame.ToString();
|
||||||
break;
|
break;
|
||||||
case TimeColumnName:
|
case TimeColumnName:
|
||||||
text = Branches[index].TimeStamp.ToString(@"hh\:mm\:ss\.ff");
|
text = GetBranch(index).TimeStamp.ToString(@"hh\:mm\:ss\.ff");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,14 +148,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (SelectedBranch != null)
|
if (SelectedBranch != null)
|
||||||
{
|
{
|
||||||
int index = Branches.IndexOf(SelectedBranch);
|
int index = BranchView.SelectedRows.First();
|
||||||
if (index == CurrentBranch)
|
if (index == CurrentBranch)
|
||||||
{
|
{
|
||||||
CurrentBranch = -1;
|
CurrentBranch = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Branches.Remove(SelectedBranch);
|
Movie.RemoveBranch(SelectedBranch);
|
||||||
BranchView.RowCount = Branches.Count;
|
BranchView.RowCount = Movie.BranchCount;
|
||||||
|
|
||||||
if (index == BranchView.SelectedRows.FirstOrDefault())
|
if (index == BranchView.SelectedRows.FirstOrDefault())
|
||||||
{
|
{
|
||||||
|
@ -179,15 +180,15 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void UpdateValues()
|
public void UpdateValues()
|
||||||
{
|
{
|
||||||
BranchView.RowCount = Branches.Count;
|
BranchView.RowCount = Movie.BranchCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Branch()
|
public void Branch()
|
||||||
{
|
{
|
||||||
TasBranch branch = CreateBranch();
|
TasBranch branch = CreateBranch();
|
||||||
Branches.Add(branch);
|
Movie.AddBranch(branch);
|
||||||
BranchView.RowCount = Branches.Count;
|
BranchView.RowCount = Movie.BranchCount;
|
||||||
CurrentBranch = Branches.IndexOf(branch);
|
CurrentBranch = Movie.BranchCount - 1;
|
||||||
BranchView.Refresh();
|
BranchView.Refresh();
|
||||||
Tastudio.RefreshDialog();
|
Tastudio.RefreshDialog();
|
||||||
}
|
}
|
||||||
|
@ -209,11 +210,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void BranchView_CellHovered(object sender, InputRoll.CellEventArgs e)
|
private void BranchView_CellHovered(object sender, InputRoll.CellEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.NewCell != null && e.NewCell.RowIndex.HasValue && e.NewCell.Column != null && e.NewCell.RowIndex < Branches.Count)
|
if (e.NewCell != null && e.NewCell.RowIndex.HasValue && e.NewCell.Column != null && e.NewCell.RowIndex < Movie.BranchCount)
|
||||||
{
|
{
|
||||||
if (e.NewCell.Column.Name == BranchNumberColumnName)
|
if (e.NewCell.Column.Name == BranchNumberColumnName)
|
||||||
{
|
{
|
||||||
ScreenShotPopUp(Branches[e.NewCell.RowIndex.Value], e.NewCell.RowIndex.Value);
|
ScreenShotPopUp(GetBranch(e.NewCell.RowIndex.Value), e.NewCell.RowIndex.Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -268,18 +269,13 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if (SelectedBranch != null)
|
if (SelectedBranch != null)
|
||||||
{
|
{
|
||||||
UpdateBranch(SelectedBranch);
|
UpdateBranch(SelectedBranch);
|
||||||
|
CurrentBranch = BranchView.SelectedRows.First();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateBranch(TasBranch branch)
|
private void UpdateBranch(TasBranch branch)
|
||||||
{
|
{
|
||||||
var index = Branches.IndexOf(branch);
|
Movie.UpdateBranch(branch, CreateBranch());
|
||||||
|
|
||||||
var newbranch = CreateBranch();
|
|
||||||
Branches.Insert(index, newbranch);
|
|
||||||
|
|
||||||
Branches.Remove(branch);
|
|
||||||
CurrentBranch = index;
|
|
||||||
BranchView.Refresh();
|
BranchView.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,17 +301,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e)
|
private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Branches.Count)
|
if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Movie.BranchCount)
|
||||||
{
|
{
|
||||||
var branch = Branches[e.OldCell.RowIndex.Value];
|
Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value);
|
||||||
int originalIndex = Branches.IndexOf(branch);
|
|
||||||
int newIndex = e.NewCell.RowIndex.Value;
|
|
||||||
|
|
||||||
if (newIndex >= Branches.Count)
|
|
||||||
newIndex = Branches.Count - 1;
|
|
||||||
|
|
||||||
Branches.Remove(branch);
|
|
||||||
Branches.Insert(newIndex, branch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,13 +198,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
if (columnName == CursorColumnName)
|
if (columnName == CursorColumnName)
|
||||||
{
|
{
|
||||||
var branch = CurrentTasMovie.TasBranches
|
int branchIndex = CurrentTasMovie.BranchIndex(index);
|
||||||
.Where(b => b.Frame == index)
|
if (branchIndex != -1)
|
||||||
.OrderByDescending(b => b.TimeStamp)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (branch != null)
|
|
||||||
{
|
{
|
||||||
text = CurrentTasMovie.TasBranches.IndexOf(branch).ToString();
|
text = branchIndex.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (columnName == FrameColumnName)
|
else if (columnName == FrameColumnName)
|
||||||
|
|
Loading…
Reference in New Issue