From 6fce0bcad625af25f205bc3341fd31e4da2f4ad0 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 29 Jun 2014 00:57:33 +0000 Subject: [PATCH] remove Time from IMovie and instead implement the logic in PlatformFrameRates --- .../movie/PlatformFrameRates.cs | 35 ++++++++++++++++- BizHawk.Client.Common/movie/bk2/Bk2Movie.cs | 38 ------------------- BizHawk.Client.Common/movie/bkm/BkmMovie.cs | 38 ------------------- .../movie/interfaces/IMovie.cs | 5 --- BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 6 ++- 5 files changed, 38 insertions(+), 84 deletions(-) diff --git a/BizHawk.Client.Common/movie/PlatformFrameRates.cs b/BizHawk.Client.Common/movie/PlatformFrameRates.cs index 553f959618..7c59b119d6 100644 --- a/BizHawk.Client.Common/movie/PlatformFrameRates.cs +++ b/BizHawk.Client.Common/movie/PlatformFrameRates.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace BizHawk.Client.Common { @@ -56,5 +57,37 @@ namespace BizHawk.Client.Common return 60.0; } } + + public TimeSpan MovieTime(IMovie movie) + { + var dblseconds = GetSeconds(movie); + var seconds = (int)(dblseconds % 60); + var days = seconds / 86400; + var hours = seconds / 3600; + var minutes = (seconds / 60) % 60; + var milliseconds = (int)((dblseconds - seconds) * 1000); + return new TimeSpan(days, hours, minutes, seconds, milliseconds); + } + + private double Fps(IMovie movie) + { + var system = movie.HeaderEntries[HeaderKeys.PLATFORM]; + var pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL) && + movie.HeaderEntries[HeaderKeys.PAL] == "1"; + + return this[system, pal]; + } + + private double GetSeconds(IMovie movie) + { + double frames = movie.InputLogLength; + + if (frames < 1) + { + return 0; + } + + return frames / Fps(movie); + } } } diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs index 2c2e243aa7..65a9b51c70 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.cs @@ -60,32 +60,6 @@ namespace BizHawk.Client.Common } } - private double Fps - { - get - { - var system = Header[HeaderKeys.PLATFORM]; - var pal = Header.ContainsKey(HeaderKeys.PAL) && - Header[HeaderKeys.PAL] == "1"; - - return _frameRates[system, pal]; - } - } - - public TimeSpan Time - { - get - { - var dblseconds = GetSeconds(_log.Count); - var seconds = (int)(dblseconds % 60); - var days = seconds / 86400; - var hours = seconds / 3600; - var minutes = (seconds / 60) % 60; - var milliseconds = (int)((dblseconds - seconds) * 1000); - return new TimeSpan(days, hours, minutes, seconds, milliseconds); - } - } - public int InputLogLength { get { return _log.Count; } @@ -205,18 +179,6 @@ namespace BizHawk.Client.Common #endregion - private double GetSeconds(int frameCount) - { - double frames = frameCount; - - if (frames < 1) - { - return 0; - } - - return frames / Fps; - } - private void SetFrameAt(int frameNum, string frame) { if (_log.Count > frameNum) diff --git a/BizHawk.Client.Common/movie/bkm/BkmMovie.cs b/BizHawk.Client.Common/movie/bkm/BkmMovie.cs index 493914217b..03c0a44240 100644 --- a/BizHawk.Client.Common/movie/bkm/BkmMovie.cs +++ b/BizHawk.Client.Common/movie/bkm/BkmMovie.cs @@ -73,32 +73,6 @@ namespace BizHawk.Client.Common get { return _changes; } } - private double Fps - { - get - { - var system = Header[HeaderKeys.PLATFORM]; - var pal = Header.ContainsKey(HeaderKeys.PAL) && - Header[HeaderKeys.PAL] == "1"; - - return _frameRates[system, pal]; - } - } - - public TimeSpan Time - { - get - { - var dblseconds = GetSeconds(Loaded ? _log.Count : _preloadFramecount); - var seconds = (int)(dblseconds % 60); - var days = seconds / 86400; - var hours = seconds / 3600; - var minutes = (seconds / 60) % 60; - var milliseconds = (int)((dblseconds - seconds) * 1000); - return new TimeSpan(days, hours, minutes, seconds, milliseconds); - } - } - #endregion #region Public Log Editing @@ -221,18 +195,6 @@ namespace BizHawk.Client.Common #endregion - private double GetSeconds(int frameCount) - { - double frames = frameCount; - - if (frames < 1) - { - return 0; - } - - return frames / Fps; - } - private void SetFrameAt(int frameNum, string frame) { if (_log.Count > frameNum) diff --git a/BizHawk.Client.Common/movie/interfaces/IMovie.cs b/BizHawk.Client.Common/movie/interfaces/IMovie.cs index aac378e544..82fa8079cb 100644 --- a/BizHawk.Client.Common/movie/interfaces/IMovie.cs +++ b/BizHawk.Client.Common/movie/interfaces/IMovie.cs @@ -30,11 +30,6 @@ namespace BizHawk.Client.Common /// double FrameCount { get; } - /// - /// Gets the time calculation based on FrameCount and Fps - /// - TimeSpan Time { get; } - /// /// Gets the actual length of the input log, should only be used by code that iterates or needs a real length /// diff --git a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index 8c43d1ccf2..490b06a485 100644 --- a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -14,6 +14,8 @@ namespace BizHawk.Client.EmuHawk { public partial class PlayMovie : Form { + private readonly PlatformFrameRates PlatformFrameRates = new PlatformFrameRates(); + private List _movieList = new List(); private bool _sortReverse; private string _sortedCol; @@ -61,7 +63,7 @@ namespace BizHawk.Client.EmuHawk if (column == 3) // Time { - text = _movieList[index].Time.ToString(@"hh\:mm\:ss\.fff"); + text = PlatformFrameRates.MovieTime(_movieList[index]).ToString(@"hh\:mm\:ss\.fff"); } } @@ -319,7 +321,7 @@ namespace BizHawk.Client.EmuHawk .Append(_movieList[index].Filename).Append('\t') .Append(_movieList[index].SystemID).Append('\t') .Append(_movieList[index].GameName).Append('\t') - .Append(_movieList[index].Time.ToString(@"hh\:mm\:ss\.fff")) + .Append(PlatformFrameRates.MovieTime(_movieList[index]).ToString(@"hh\:mm\:ss\.fff")) .AppendLine(); Clipboard.SetDataObject(copyStr.ToString());