From edacc9b8c8a78c9fbd37079305d670737f62378f Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 14 Jun 2014 18:52:00 +0000 Subject: [PATCH] BK2 - support loop offset --- BizHawk.Client.Common/movie/HeaderKeys.cs | 1 + .../movie/bk2/Bk2Movie.HeaderApi.cs | 26 +++++++++++++++++++ .../movie/bk2/Bk2Movie.IO.cs | 1 - BizHawk.Client.Common/movie/bk2/Bk2Movie.cs | 7 +++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/BizHawk.Client.Common/movie/HeaderKeys.cs b/BizHawk.Client.Common/movie/HeaderKeys.cs index a6f42f73aa..e854a2ffd2 100644 --- a/BizHawk.Client.Common/movie/HeaderKeys.cs +++ b/BizHawk.Client.Common/movie/HeaderKeys.cs @@ -18,6 +18,7 @@ namespace BizHawk.Client.Common public const string PAL = "PAL"; public const string BOARDNAME = "BoardName"; public const string SYNCSETTINGS = "SyncSettings"; + public const string LOOPOFFSET = "LoopOffset"; // Core Setting public const string CORE = "Core"; diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.HeaderApi.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.HeaderApi.cs index 92cd49c37f..53c556a868 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.HeaderApi.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.HeaderApi.cs @@ -160,6 +160,32 @@ namespace BizHawk.Client.Common set { Header[HeaderKeys.FIRMWARESHA1] = value; } } + private int? LoopOffset + { + get + { + var offsetStr = Header[HeaderKeys.LOOPOFFSET]; + if (!string.IsNullOrWhiteSpace(offsetStr)) + { + return int.Parse(offsetStr); + } + + return null; + } + + set + { + if (value.HasValue) + { + Header[HeaderKeys.LOOPOFFSET] = value.ToString(); + } + else + { + Header.Remove(HeaderKeys.LOOPOFFSET); + } + } + } + private string CommentsString() { StringBuilder sb = new StringBuilder(); diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index df9d9c8789..b41b0d0f25 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -160,7 +160,6 @@ namespace BizHawk.Client.Common bs.PutLump(BinaryStateLump.Input, (tw) => tw.WriteLine(RawInputLog())); - if (StartsFromSavestate) { bs.PutLump(BinaryStateLump.CorestateText, (tw) => tw.WriteLine(SavestateBinaryBase64Blob)); diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index 3dfb738220..02fa2ce2a1 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -14,7 +14,6 @@ namespace BizHawk.Client.Common // Movies 2.0 TODO: save and load loopOffset, put in header object private readonly PlatformFrameRates _frameRates = new PlatformFrameRates(); private bool _makeBackup = true; - private int? _loopOffset; public Bk2Movie(string filename, bool startsFromSavestate = false) : this(startsFromSavestate) @@ -45,7 +44,7 @@ namespace BizHawk.Client.Common { get { - if (_loopOffset.HasValue) + if (LoopOffset.HasValue) { return double.PositiveInfinity; } @@ -125,7 +124,7 @@ namespace BizHawk.Client.Common int getframe; - if (_loopOffset.HasValue) + if (LoopOffset.HasValue) { if (frame < _log.Length) { @@ -133,7 +132,7 @@ namespace BizHawk.Client.Common } else { - getframe = ((frame - _loopOffset.Value) % (_log.Length - _loopOffset.Value)) + _loopOffset.Value; + getframe = ((frame - LoopOffset.Value) % (_log.Length - LoopOffset.Value)) + LoopOffset.Value; } } else