diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index 7131491f16..2a8ba6a6c1 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -22,7 +22,8 @@ namespace BizHawk.Client.Common // TasMovie LagLog, - Greenzone + Greenzone, + Markers } public class BinaryStateFileNames @@ -56,6 +57,7 @@ namespace BizHawk.Client.Common // TasMovie LumpNames[BinaryStateLump.LagLog] = "LagLog"; LumpNames[BinaryStateLump.Greenzone] = "GreenZone"; + LumpNames[BinaryStateLump.Markers] = "Markers"; } public static string Get(BinaryStateLump lump) diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index baa23ea0c7..edc89cfac2 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -169,6 +169,7 @@ + diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 4c9e4e372a..20d6fa683a 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -8,7 +8,6 @@ namespace BizHawk.Client.Common { public partial class TasMovie { - // TODO: all these public override void RecordFrame(int frame, Emulation.Common.IController source) { base.RecordFrame(frame, source); @@ -30,6 +29,7 @@ namespace BizHawk.Client.Common LagLog.RemoveRange(frame + 2, LagLog.Count - frame - 1); StateManager.Invalidate(frame + 1); + // TODO: Markers? What does taseditor do? } public override void PokeFrame(int frame, Emulation.Common.IController source) diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index e98ad09b11..fc9da039ae 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -29,6 +29,7 @@ namespace BizHawk.Client.Common bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog())); bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => bw.Write(LagLog.ToByteArray())); + bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString())); if (StartsFromSavestate) { @@ -129,6 +130,18 @@ namespace BizHawk.Client.Common LagLog = bytes.ToBools().ToList(); }); + bl.GetLump(BinaryStateLump.Markers, true, delegate(TextReader tr) + { + string line; + while ((line = tr.ReadLine()) != null) + { + if (!string.IsNullOrWhiteSpace(line)) + { + Markers.Add(new TasMovieMarker(line)); + } + } + }); + if (StartsFromSavestate) { bl.GetCoreState( diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 222eac8ba6..ea9a4b754a 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -13,6 +13,7 @@ namespace BizHawk.Client.Common { private List LagLog = new List(); private readonly TasStateManager StateManager = new TasStateManager(); + private readonly TasMovieMarkerList Markers = new TasMovieMarkerList(); public TasMovie(string path) : base(path) { } @@ -46,7 +47,18 @@ namespace BizHawk.Client.Common { LagLog.Clear(); StateManager.Clear(); + Markers.Clear(); base.StartNewRecording(); } + + public void Marker(int frame, string message) + { + Markers.Add(frame, message); + } + + public void DeleteMarker(int frame) + { + Markers.Remove(frame); + } } } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs new file mode 100644 index 0000000000..b6349fa379 --- /dev/null +++ b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs @@ -0,0 +1,164 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Client.Common +{ + /// + /// Represents a TasMovie Marker + /// A marker is a tagged frame with a message + /// + public class TasMovieMarker + { + private int _frame; + + public TasMovieMarker(int frame, string message = "") + { + _frame = frame; + Message = message; + } + + /// + /// Parses a Marker from a line of text + /// + public TasMovieMarker(string line) + { + var split = line.Split('\t'); + _frame = int.Parse(split[0]); + Message = split[1]; + } + + public virtual int Frame + { + get { return _frame; } + } + + public virtual string Message { get; set; } + + public override string ToString() + { + return Frame.ToString() + '\t' + Message; + } + + public override int GetHashCode() + { + return this.Frame.GetHashCode(); + } + + public override bool Equals(object obj) + { + if (obj == null) + { + return false; + } + else if (obj is TasMovieMarker) + { + return this.Frame == (obj as TasMovieMarker).Frame; + } + else + { + return false; + } + } + + public static bool operator ==(TasMovieMarker a, TasMovieMarker b) + { + return a.Frame == b.Frame; + } + + public static bool operator !=(TasMovieMarker a, TasMovieMarker b) + { + return a.Frame != b.Frame; + } + + public static bool operator ==(TasMovieMarker marker, int frame) + { + return marker.Frame == frame; + } + + public static bool operator !=(TasMovieMarker marker, int frame) + { + return marker.Frame != frame; + } + } + + /// + /// Specialized Marker that represents the currently emulated frame + /// Frame always points to Global.Emulator.Frame, and setting it isn't possible + /// + public class CurrentFrameMarker : TasMovieMarker + { + public CurrentFrameMarker() + : base(0) + { + + } + + public override int Frame + { + get { return Global.Emulator.Frame; } + } + + public override string Message + { + get { return string.Empty; } + set { return; } + } + } + + public class TasMovieMarkerList : List + { + private readonly CurrentFrameMarker _current; + public TasMovieMarkerList() + : base() + { + _current = new CurrentFrameMarker(); + } + + public CurrentFrameMarker CurrentFrame + { + get + { + return _current; + } + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + foreach (var marker in this) + { + sb.AppendLine(marker.ToString()); + } + + return sb.ToString(); + } + + public new void Add(TasMovieMarker item) + { + var existingItem = this.FirstOrDefault(m => m.Frame == item.Frame); + if (existingItem != null) + { + existingItem.Message = item.Message; + } + else + { + base.Add(item); + } + } + + public void Add(int frame, string message) + { + Add(new TasMovieMarker(frame, message)); + } + + public void Remove(int frame) + { + var existingItem = this.FirstOrDefault(m => m.Frame == frame); + if (existingItem != null) + { + this.Remove(existingItem); + } + } + } +} diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 2d1b6393a2..c632505dfa 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -843,7 +843,6 @@ TAStudio.cs Form - UserControl diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/Marker.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/Marker.cs deleted file mode 100644 index a4a39e360b..0000000000 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/Marker.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using BizHawk.Client.Common; - -namespace BizHawk.Client.EmuHawk -{ - /// - /// Represents a TasMovie Marker - /// A marker is a tagged frame with a message - /// - public class Marker - { - private int _frame; - - public Marker(int frame, string message = "") - { - _frame = frame; - Message = message; - } - - public virtual int Frame - { - get { return _frame; } - } - - public virtual string Message { get; set; } - - public override string ToString() - { - return Frame.ToString() + '\t' + Message; - } - - public override int GetHashCode() - { - return this.Frame.GetHashCode(); - } - - public override bool Equals(object obj) - { - if (obj == null) - { - return false; - } - else if (obj is Marker) - { - return this.Frame == (obj as Marker).Frame; - } - else - { - return false; - } - } - - public static bool operator ==(Marker a, Marker b) - { - return a.Frame == b.Frame; - } - - public static bool operator !=(Marker a, Marker b) - { - return a.Frame != b.Frame; - } - - public static bool operator ==(Marker marker, int frame) - { - return marker.Frame == frame; - } - - public static bool operator !=(Marker marker, int frame) - { - return marker.Frame != frame; - } - } - - /// - /// Specialized Marker that represents the currently emulated frame - /// Frame always points to Global.Emulator.Frame, and setting it isn't possible - /// - public class CurrentFrameMarker : Marker - { - public CurrentFrameMarker() - : base(0) - { - - } - - public override int Frame - { - get { return Global.Emulator.Frame; } - } - - public override string Message - { - get { return String.Empty; } - set { return; } - } - } - - public class MarkerList : List - { - private readonly CurrentFrameMarker _current; - public MarkerList() - : base() - { - _current = new CurrentFrameMarker(); - } - - public CurrentFrameMarker CurrentFrame - { - get - { - return _current; - } - } - } -} diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs index 6916935b41..bf624e1a2b 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs @@ -7,26 +7,17 @@ using System.Linq; using System.Text; using System.Windows.Forms; +using BizHawk.Client.Common; + namespace BizHawk.Client.EmuHawk { public partial class MarkerControl : UserControl { - private Marker _marker = new Marker(0); - private int _markerIndex = 0; - public MarkerControl() { InitializeComponent(); } - public void SetMarker(Marker marker, int index) - { - _marker = marker; - _markerIndex = index; - MarkerLabel.Text = "Marker " + _markerIndex; - MarkerBox.Text = _marker.Message; - } - private void MarkerControl_Load(object sender, EventArgs e) { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index cf9c20d527..06043e6fb4 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -16,7 +16,7 @@ namespace BizHawk.Client.EmuHawk private const string MarkerColumnName = "MarkerColumn"; private const string FrameColumnName = "FrameColumn"; - private readonly MarkerList _markers = new MarkerList(); + private readonly TasMovieMarkerList _markers = new TasMovieMarkerList(); private readonly List _tasClipboard = new List(); private int _defaultWidth;