Implemented feature: Auto-adjust Input according to Lag;

Added option: Hide WasLag Frames
-Changed implementation of TasLagLog
-Removed single-line Marker functions from TAStudio.
This commit is contained in:
SuuperW 2015-03-10 17:11:29 +00:00
parent 9891e73313
commit 6013b9ed2b
9 changed files with 150 additions and 72 deletions

View File

@ -10,25 +10,24 @@ namespace BizHawk.Client.Common
public class TasLagLog
{
// TODO: Change this into a regular list.
private readonly SortedList<int, bool> LagLog = new SortedList<int, bool>();
private readonly List<bool> LagLog = new List<bool>();
private readonly SortedList<int, bool> RemovedFrames = new SortedList<int, bool>();
private readonly List<bool> WasLag = new List<bool>();
public bool? this[int frame]
{
get
{
if (LagLog.ContainsKey(frame))
if (frame < LagLog.Count)
{
return LagLog[frame];
if (frame < 0)
return null;
else
return LagLog[frame];
}
else if (frame == Global.Emulator.Frame)
else if (frame == Global.Emulator.Frame && frame == LagLog.Count)
{
if (frame == LagLog.Count)
{
LagLog[frame] = Global.Emulator.AsInputPollable().IsLagFrame; // Note: Side effects!
}
// LagLog[frame] = Global.Emulator.AsInputPollable().IsLagFrame; // Note: Side effects!
return Global.Emulator.AsInputPollable().IsLagFrame;
}
@ -39,74 +38,102 @@ namespace BizHawk.Client.Common
{
if (!value.HasValue)
{
LagLog.Remove(frame);
LagLog.RemoveAt(frame);
return;
}
else if (frame < 0)
{
return; // Nothing to do
}
else if (LagLog.ContainsKey(frame))
{
LagLog[frame] = value.Value;
}
if (frame == LagLog.Count)
LagLog.Add(value.Value);
else
{
LagLog.Add(frame, value.Value);
}
LagLog[frame] = value.Value;
if (frame == WasLag.Count)
WasLag.Add(value.Value);
else
WasLag[frame] = value.Value;
}
}
public void Clear()
{
for (int i = 0; i < LagLog.Count; i++)
{
RemovedFrames.Remove(LagLog.Keys[i]);
RemovedFrames.Add(i, LagLog[i]);
}
LagLog.Clear();
}
public void RemoveFrom(int frame)
{
for (int i = LagLog.Count - 1; i > frame; i--) // Reverse order because removing from a sorted list re-indexes the items after the removed item
{
RemovedFrames.Remove(LagLog.Keys[i]);
RemovedFrames.Add(LagLog.Keys[i], LagLog.Values[i]); // use .Keys[i] instead of [i] here because indizes might not be consistent with keys
LagLog.Remove(LagLog.Keys[i]);
}
if (LagLog.Count >= frame)
LagLog.RemoveRange(frame, LagLog.Count - frame);
}
public void RemoveHistoryAt(int frame)
{
WasLag.RemoveAt(frame);
}
public void InsertHistoryAt(int frame, bool isLag)
{ // LagLog was invalidated when the frame was inserted
LagLog.Insert(frame, isLag);
WasLag.Insert(frame, isLag);
}
public void Save(BinaryWriter bw)
{
bw.Write((byte)1); // New saving format.
bw.Write(LagLog.Count);
foreach (var kvp in LagLog)
bw.Write(WasLag.Count);
for (int i = 0; i < LagLog.Count; i++)
{
bw.Write(kvp.Key);
bw.Write(kvp.Value);
bw.Write(LagLog[i]);
bw.Write(WasLag[i]);
}
for (int i = LagLog.Count; i < WasLag.Count; i++)
bw.Write(WasLag[i]);
}
public void Load(BinaryReader br)
{
LagLog.Clear();
WasLag.Clear();
if (br.BaseStream.Length > 0)
{
int length = br.ReadInt32();
for (int i = 0; i < length; i++)
int formatVersion = br.ReadByte();
if (formatVersion == 0)
{
LagLog.Add(br.ReadInt32(), br.ReadBoolean());
int length = (br.ReadByte() << 8) | formatVersion; // The first byte should be a part of length.
length = (br.ReadInt16() << 16) | length;
for (int i = 0; i < length; i++)
{
br.ReadInt32();
LagLog.Add(br.ReadBoolean());
WasLag.Add(LagLog.Last());
}
}
else if (formatVersion == 1)
{
int length = br.ReadInt32();
int lenWas = br.ReadInt32();
for (int i = 0; i < length; i++)
{
LagLog.Add(br.ReadBoolean());
WasLag.Add(br.ReadBoolean());
}
for (int i = length; i < lenWas; i++)
WasLag.Add(br.ReadBoolean());
}
}
}
public bool? History(int frame)
{
if (RemovedFrames.ContainsKey(frame))
if (frame < WasLag.Count)
{
return RemovedFrames[frame];
if (frame < 0)
return null;
return WasLag[frame];
}
return null;

View File

@ -440,5 +440,16 @@ namespace BizHawk.Client.Common
ChangeLog.SetGeneralRedo();
}
#region "LagLog"
public void RemoveLagHistory(int frame)
{
LagLog.RemoveHistoryAt(frame);
}
public void InsertLagHistory(int frame, bool isLag)
{
LagLog.InsertHistoryAt(frame, isLag);
}
#endregion
}
}

View File

@ -38,6 +38,7 @@ namespace BizHawk.Client.EmuHawk
// Hiding lag frames (Mainly intended for < 60fps play.)
public int LagFramesToHide { get; set; }
public bool HideWasLagFrames { get; set; }
private int[] lagFrames = new int[100]; // Large enough value that it shouldn't ever need resizing.
private IntPtr RotatedFont;
@ -300,7 +301,7 @@ namespace BizHawk.Client.EmuHawk
/// <summary>
/// SuuperW: Check if a given frame is a lag frame
/// </summary>
public delegate bool QueryFrameLagHandler(int index);
public delegate bool QueryFrameLagHandler(int index, bool hideWasLag);
public delegate void CellChangeEventHandler(object sender, CellEventArgs e);
@ -501,6 +502,7 @@ namespace BizHawk.Client.EmuHawk
_columns = rollSettings.Columns;
HorizontalOrientation = rollSettings.HorizontalOrientation;
LagFramesToHide = rollSettings.LagFramesToHide;
HideWasLagFrames = rollSettings.HideWasLagFrames;
}
}
@ -513,7 +515,8 @@ namespace BizHawk.Client.EmuHawk
{
Columns = _columns,
HorizontalOrientation = HorizontalOrientation,
LagFramesToHide = LagFramesToHide
LagFramesToHide = LagFramesToHide,
HideWasLagFrames = HideWasLagFrames
};
}
}
@ -523,6 +526,7 @@ namespace BizHawk.Client.EmuHawk
public RollColumns Columns { get; set; }
public bool HorizontalOrientation { get; set; }
public int LagFramesToHide { get; set; }
public bool HideWasLagFrames { get; set; }
}
/// <summary>
@ -2100,7 +2104,7 @@ namespace BizHawk.Client.EmuHawk
// First one needs to check BACKWARDS for lag frame count.
SetLagFramesFirst();
int f = lagFrames[0];
if (QueryFrameLag(FirstVisibleRow + f))
if (QueryFrameLag(FirstVisibleRow + f, HideWasLagFrames))
showNext = true;
for (int i = 1; i <= VisibleRows; i++)
{
@ -2109,17 +2113,17 @@ namespace BizHawk.Client.EmuHawk
{
for (; lagFrames[i] < LagFramesToHide; lagFrames[i]++)
{
if (!QueryFrameLag(FirstVisibleRow + i + f))
if (!QueryFrameLag(FirstVisibleRow + i + f, HideWasLagFrames))
break;
f++;
}
}
else
{
if (!QueryFrameLag(FirstVisibleRow + i + f))
if (!QueryFrameLag(FirstVisibleRow + i + f, HideWasLagFrames))
showNext = false;
}
if (lagFrames[i] == LagFramesToHide && QueryFrameLag(FirstVisibleRow + i + f))
if (lagFrames[i] == LagFramesToHide && QueryFrameLag(FirstVisibleRow + i + f, HideWasLagFrames))
{
showNext = true;
}
@ -2138,14 +2142,14 @@ namespace BizHawk.Client.EmuHawk
do
{
count++;
} while (QueryFrameLag(FirstVisibleRow - count) && count <= LagFramesToHide);
} while (QueryFrameLag(FirstVisibleRow - count, HideWasLagFrames) && count <= LagFramesToHide);
count--;
// Count forward
int fCount = -1;
do
{
fCount++;
} while (QueryFrameLag(FirstVisibleRow + fCount) && count + fCount < LagFramesToHide);
} while (QueryFrameLag(FirstVisibleRow + fCount, HideWasLagFrames) && count + fCount < LagFramesToHide);
lagFrames[0] = fCount;
}
else

View File

@ -121,7 +121,7 @@ namespace BizHawk.Client.EmuHawk
private void RemoveBtn_Click(object sender, EventArgs e)
{
SelectedMarkers.ForEach(i => Tastudio.RemoveMarker(i));
SelectedMarkers.ForEach(i => Tastudio.CurrentTasMovie.Markers.Remove(i));
MarkerInputRoll.DeselectAll();
Tastudio.RefreshDialog();
MarkerView_SelectedIndexChanged(sender, e);

View File

@ -110,6 +110,8 @@ namespace BizHawk.Client.EmuHawk
this.HideLagFrames1 = new System.Windows.Forms.ToolStripMenuItem();
this.HideLagFrames2 = new System.Windows.Forms.ToolStripMenuItem();
this.HideLagFrames3 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator12 = new System.Windows.Forms.ToolStripSeparator();
this.hideWasLagFramesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ColumnsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator19 = new System.Windows.Forms.ToolStripSeparator();
this.HelpSubMenu = new System.Windows.Forms.ToolStripMenuItem();
@ -537,7 +539,7 @@ namespace BizHawk.Client.EmuHawk
//
// AutoadjustInputMenuItem
//
this.AutoadjustInputMenuItem.Enabled = false;
this.AutoadjustInputMenuItem.CheckOnClick = true;
this.AutoadjustInputMenuItem.Name = "AutoadjustInputMenuItem";
this.AutoadjustInputMenuItem.Size = new System.Drawing.Size(288, 22);
this.AutoadjustInputMenuItem.Text = "Auto-adjust Input according to Lag";
@ -766,7 +768,9 @@ namespace BizHawk.Client.EmuHawk
this.HideLagFrames0,
this.HideLagFrames1,
this.HideLagFrames2,
this.HideLagFrames3});
this.HideLagFrames3,
this.toolStripSeparator12,
this.hideWasLagFramesToolStripMenuItem});
this.HideLagFramesSubMenu.Name = "HideLagFramesSubMenu";
this.HideLagFramesSubMenu.Size = new System.Drawing.Size(162, 22);
this.HideLagFramesSubMenu.Text = "Hide Lag Frames";
@ -778,7 +782,7 @@ namespace BizHawk.Client.EmuHawk
this.HideLagFrames0.CheckOnClick = true;
this.HideLagFrames0.CheckState = System.Windows.Forms.CheckState.Checked;
this.HideLagFrames0.Name = "HideLagFrames0";
this.HideLagFrames0.Size = new System.Drawing.Size(131, 22);
this.HideLagFrames0.Size = new System.Drawing.Size(184, 22);
this.HideLagFrames0.Tag = 0;
this.HideLagFrames0.Text = "Don\'t Hide";
this.HideLagFrames0.Click += new System.EventHandler(this.HideLagFramesX_Click);
@ -787,7 +791,7 @@ namespace BizHawk.Client.EmuHawk
//
this.HideLagFrames1.CheckOnClick = true;
this.HideLagFrames1.Name = "HideLagFrames1";
this.HideLagFrames1.Size = new System.Drawing.Size(131, 22);
this.HideLagFrames1.Size = new System.Drawing.Size(184, 22);
this.HideLagFrames1.Tag = 1;
this.HideLagFrames1.Text = "1 (30 fps)";
this.HideLagFrames1.Click += new System.EventHandler(this.HideLagFramesX_Click);
@ -795,7 +799,7 @@ namespace BizHawk.Client.EmuHawk
// HideLagFrames2
//
this.HideLagFrames2.Name = "HideLagFrames2";
this.HideLagFrames2.Size = new System.Drawing.Size(131, 22);
this.HideLagFrames2.Size = new System.Drawing.Size(184, 22);
this.HideLagFrames2.Tag = 2;
this.HideLagFrames2.Text = "2 (20 fps)";
this.HideLagFrames2.Click += new System.EventHandler(this.HideLagFramesX_Click);
@ -804,11 +808,24 @@ namespace BizHawk.Client.EmuHawk
//
this.HideLagFrames3.CheckOnClick = true;
this.HideLagFrames3.Name = "HideLagFrames3";
this.HideLagFrames3.Size = new System.Drawing.Size(131, 22);
this.HideLagFrames3.Size = new System.Drawing.Size(184, 22);
this.HideLagFrames3.Tag = 3;
this.HideLagFrames3.Text = "3 (15fps)";
this.HideLagFrames3.Click += new System.EventHandler(this.HideLagFramesX_Click);
//
// toolStripSeparator12
//
this.toolStripSeparator12.Name = "toolStripSeparator12";
this.toolStripSeparator12.Size = new System.Drawing.Size(181, 6);
//
// hideWasLagFramesToolStripMenuItem
//
this.hideWasLagFramesToolStripMenuItem.CheckOnClick = true;
this.hideWasLagFramesToolStripMenuItem.Name = "hideWasLagFramesToolStripMenuItem";
this.hideWasLagFramesToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
this.hideWasLagFramesToolStripMenuItem.Text = "Hide WasLag Frames";
this.hideWasLagFramesToolStripMenuItem.Click += new System.EventHandler(this.hideWasLagFramesToolStripMenuItem_Click);
//
// ColumnsSubMenu
//
this.ColumnsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -820,7 +837,7 @@ namespace BizHawk.Client.EmuHawk
// toolStripSeparator19
//
this.toolStripSeparator19.Name = "toolStripSeparator19";
this.toolStripSeparator19.Size = new System.Drawing.Size(149, 6);
this.toolStripSeparator19.Size = new System.Drawing.Size(57, 6);
//
// HelpSubMenu
//
@ -1333,5 +1350,7 @@ namespace BizHawk.Client.EmuHawk
private System.Windows.Forms.ToolStripMenuItem customPatternToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator setpToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem setCustomsToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator12;
private System.Windows.Forms.ToolStripMenuItem hideWasLagFramesToolStripMenuItem;
}
}

View File

@ -30,6 +30,9 @@ namespace BizHawk.Client.EmuHawk
return;
}
if (AutoadjustInputMenuItem.Checked)
AutoAdjustInput();
if (TasPlaybackBox.FollowCursor)
{
SetVisibleIndex();

View File

@ -197,9 +197,10 @@ namespace BizHawk.Client.EmuHawk
}
// SuuperW: Used in InputRoll.cs to hide lag frames.
private bool TasView_QueryFrameLag(int index)
private bool TasView_QueryFrameLag(int index, bool hideWasLag)
{
return CurrentTasMovie[index].Lagged.HasValue && CurrentTasMovie[index].Lagged.Value;
TasMovieRecord lag = CurrentTasMovie[index];
return (lag.Lagged.HasValue && lag.Lagged.Value) || (hideWasLag && lag.WasLagged.HasValue && lag.WasLagged.Value);
}
#endregion

View File

@ -551,7 +551,7 @@ namespace BizHawk.Client.EmuHawk
IEnumerable<TasMovieMarker> markers = CurrentTasMovie.Markers.Where(m => TasView.SelectedRows.Contains(m.Frame));
foreach (TasMovieMarker m in markers)
{
RemoveMarker(m);
CurrentTasMovie.Markers.Remove(m);
}
RefreshDialog();
}
@ -750,6 +750,7 @@ namespace BizHawk.Client.EmuHawk
HideLagFrames1.Checked = TasView.LagFramesToHide == 1;
HideLagFrames2.Checked = TasView.LagFramesToHide == 2;
HideLagFrames3.Checked = TasView.LagFramesToHide == 3;
hideWasLagFramesToolStripMenuItem.Checked = TasView.HideWasLagFrames;
}
private void RotateMenuItem_Click(object sender, EventArgs e)
@ -768,6 +769,11 @@ namespace BizHawk.Client.EmuHawk
RefreshDialog();
}
private void hideWasLagFramesToolStripMenuItem_Click(object sender, EventArgs e)
{
TasView.HideWasLagFrames ^= true;
}
#endregion
#region Columns

View File

@ -473,7 +473,7 @@ namespace BizHawk.Client.EmuHawk
if (result == DialogResult.OK)
{
AddMarker(markerFrame, i.PromptText);
CurrentTasMovie.Markers.Add(new TasMovieMarker(markerFrame, i.PromptText));
MarkerControl.UpdateValues();
}
}
@ -493,7 +493,7 @@ namespace BizHawk.Client.EmuHawk
if (result == DialogResult.OK)
{
EditMarker(marker, i.PromptText);
marker.Message = i.PromptText;
MarkerControl.UpdateValues();
}
}
@ -747,19 +747,26 @@ namespace BizHawk.Client.EmuHawk
MarkerControl.RemoveMarker();
}
public void AddMarker(int markerFrame, string message)
private void AutoAdjustInput()
{
TasMovieMarker marker = new TasMovieMarker(markerFrame, message);
CurrentTasMovie.Markers.Add(marker);
}
public void RemoveMarker(TasMovieMarker marker)
{
CurrentTasMovie.Markers.Remove(marker);
}
public void EditMarker(TasMovieMarker marker, string message)
{
string old = marker.Message;
marker.Message = message;
TasMovieRecord lagLog = CurrentTasMovie[Emulator.Frame - 1]; // Minus one because get frame is +1;
bool isLag = Emulator.AsInputPollable().IsLagFrame;
if (lagLog.WasLagged.HasValue)
{
if (lagLog.WasLagged.Value && !isLag)
{ // Deleting this frame requires rewinding a frame.
CurrentTasMovie.RemoveFrame(Global.Emulator.Frame - 1);
CurrentTasMovie.RemoveLagHistory(Global.Emulator.Frame); // Set frame is not +1. [should change?]
GoToFrame(Emulator.Frame - 1);
}
else if (!lagLog.WasLagged.Value && isLag)
{ // (it shouldn't need to rewind, since the inserted input wasn't polled)
CurrentTasMovie.InsertInput(Global.Emulator.Frame - 1, CurrentTasMovie.GetInputLogEntry(Emulator.Frame - 2));
CurrentTasMovie.InsertLagHistory(Global.Emulator.Frame - 1, true);
}
}
}
}
}