Refactor use of Movie Frame count - also fix play movie to show infinite movie's frame count as "Infinity"

This commit is contained in:
adelikat 2013-11-30 03:10:05 +00:00
parent 3eb3b41199
commit e686e595b9
10 changed files with 65 additions and 69 deletions

View File

@ -71,16 +71,9 @@ namespace BizHawk.Client.Common
return Global.MovieSession.Movie.IsActive;
}
public static int movie_length()
public static double movie_length()
{
if (Global.MovieSession.Movie.Frames.HasValue)
{
return Global.MovieSession.Movie.Frames.Value;
}
else
{
return -1;
}
return Global.MovieSession.Movie.FrameCount;
}
public static string movie_mode()

View File

@ -21,7 +21,15 @@ namespace BizHawk.Client.Common
#region Properties
double FrameCount { get; }
/// <summary>
/// Actual length of the input log, should only be used by code that iterates or needs a real length
/// </summary>
int InputLogLength { get; }
ulong Rerecords { get; set; }
IMovieHeader Header { get; }
#endregion
@ -90,8 +98,6 @@ namespace BizHawk.Client.Common
LoadStateResult CheckTimeLines(TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage); // No need to return a status, no reason to have hacky flags, no need to pass a textreader
string GetTime(bool preLoad); // Rename to simply: Time, and make it a Timespan
void GetInputLog(TextReader reader, bool isMultitracking); // how about the movie know if it is multi-tracking rather than having to pass it in
int? Frames { get; } // Nullable is a hack, also why does calling code need to know the number of frames, can that be minimized?
int RawFrames { get; } // Hacky to need two different frame properties
string GetInput(int frame); // Should be a property of a Record object

View File

@ -61,25 +61,23 @@ namespace BizHawk.Client.Common
get { return Header[HeaderKeys.GAMENAME]; }
}
public int RawFrames
public int InputLogLength
{
get { return Loaded ? _log.Length : _preloadFramecount; }
}
public int? Frames
public double FrameCount
{
get
{
if (Loaded)
if (_loopOffset.HasValue)
{
if (_loopOffset.HasValue)
{
return null;
}
else
{
return _log.Length;
}
return double.PositiveInfinity;
}
else if (Loaded)
{
return _log.Length;
}
else
{
@ -281,12 +279,22 @@ namespace BizHawk.Client.Common
string line;
while ((line = sr.ReadLine()) != null)
{
if (String.IsNullOrWhiteSpace(line) || Header.ParseLineFromFile(line))
if (line.Contains("LoopOffset"))
{
try
{
_loopOffset = int.Parse(line.Split(new[] { ' ' }, 2)[1]);
}
catch (Exception)
{
continue;
}
}
else if (String.IsNullOrWhiteSpace(line) || Header.ParseLineFromFile(line))
{
continue;
}
if (line.StartsWith("|"))
else if (line.StartsWith("|"))
{
var frames = sr.ReadToEnd();
var length = line.Length;

View File

@ -168,7 +168,7 @@ namespace BizHawk.Client.Common
case '1':
break;
case '2':
if (m.Frames != 0)
if (m.FrameCount != 0)
{
warningMsg = "hard reset";
}

View File

@ -128,7 +128,7 @@ namespace BizHawk.Client.Common
else if (Movie.IsFinished)
{
if (Global.Emulator.Frame < Movie.Frames) //This scenario can happen from rewinding (suddenly we are back in the movie, so hook back up to the movie
if (Global.Emulator.Frame < Movie.FrameCount) //This scenario can happen from rewinding (suddenly we are back in the movie, so hook back up to the movie
{
Movie.SwitchToPlay();
LatchInputFromLog();

View File

@ -347,34 +347,23 @@ namespace BizHawk.Client.EmuHawk
{
if (Global.MovieSession.Movie.IsFinished)
{
StringBuilder s = new StringBuilder();
s.Append(Global.Emulator.Frame);
s.Append('/');
if (Global.MovieSession.Movie.Frames.HasValue)
{
s.Append(Global.MovieSession.Movie.Frames);
}
else
{
s.Append("infinity");
}
s.Append(" (Finished)");
return s.ToString();
var sb = new StringBuilder();
sb
.Append(Global.Emulator.Frame)
.Append('/')
.Append(Global.MovieSession.Movie.FrameCount)
.Append(" (Finished)");
return sb.ToString();
}
else if (Global.MovieSession.Movie.IsPlaying)
{
StringBuilder s = new StringBuilder();
s.Append(Global.Emulator.Frame);
s.Append('/');
if (Global.MovieSession.Movie.Frames.HasValue)
{
s.Append(Global.MovieSession.Movie.Frames);
}
else
{
s.Append("infinity");
}
return s.ToString();
var sb = new StringBuilder();
sb
.Append(Global.Emulator.Frame)
.Append('/')
.Append(Global.MovieSession.Movie.FrameCount);
return sb.ToString();
}
else if (Global.MovieSession.Movie.IsRecording)
{

View File

@ -603,7 +603,7 @@ namespace BizHawk.Client.EmuHawk
{
for (int i = 0; i < frames; i++)
{
if (RewindBuf.Count == 0 || (Global.MovieSession.Movie.Loaded && Global.MovieSession.Movie.Frames == 0))
if (RewindBuf.Count == 0 || (Global.MovieSession.Movie.Loaded && Global.MovieSession.Movie.FrameCount == 0))
return;
if (LastState.Length < 0x10000)

View File

@ -213,7 +213,7 @@ namespace BizHawk.Client.EmuHawk
// if user is dumping and didnt supply dump length, make it as long as the loaded movie
if (_autoDumpLength == 0)
{
_autoDumpLength = movie.RawFrames;
_autoDumpLength = movie.InputLogLength;
}
StartNewMovie(movie, false);
Global.Config.RecentMovies.Add(cmdMovie);

View File

@ -88,7 +88,7 @@ namespace BizHawk.Client.EmuHawk
{
var movie = new Movie(file.FullName);
movie.Load(); //State files will have to load everything unfortunately
if (movie.Frames == 0)
if (movie.FrameCount == 0)
{
MessageBox.Show("No input log detected in this savestate, aborting", "Can not load file", MessageBoxButtons.OK,
MessageBoxIcon.Hand);
@ -117,7 +117,7 @@ namespace BizHawk.Client.EmuHawk
{
var movie = new Movie(file.CanonicalFullPath);
movie.Load(); //State files will have to load everything unfortunately
if (movie.Frames > 0)
if (movie.FrameCount > 0)
{
_movieList.Add(movie);
_sortReverse = false;
@ -376,7 +376,7 @@ namespace BizHawk.Client.EmuHawk
DetailsView.Items.Add(FpsItem);
var FramesItem = new ListViewItem("Frames");
FramesItem.SubItems.Add(_movieList[firstIndex].RawFrames.ToString());
FramesItem.SubItems.Add(_movieList[firstIndex].FrameCount.ToString());
DetailsView.Items.Add(FramesItem);
CommentsBtn.Enabled = _movieList[firstIndex].Header.Comments.Any();
@ -448,7 +448,7 @@ namespace BizHawk.Client.EmuHawk
.OrderByDescending(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)
.ThenBy(x => x.RawFrames)
.ThenBy(x => x.FrameCount)
.ToList();
}
else
@ -457,7 +457,7 @@ namespace BizHawk.Client.EmuHawk
.OrderBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)
.ThenBy(x => x.RawFrames)
.ThenBy(x => x.FrameCount)
.ToList();
}
break;
@ -468,7 +468,7 @@ namespace BizHawk.Client.EmuHawk
.OrderByDescending(x => x.SysID)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.GameName)
.ThenBy(x => x.RawFrames)
.ThenBy(x => x.FrameCount)
.ToList();
}
else
@ -477,7 +477,7 @@ namespace BizHawk.Client.EmuHawk
.OrderBy(x => x.SysID)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.GameName)
.ThenBy(x => x.RawFrames)
.ThenBy(x => x.FrameCount)
.ToList();
}
break;
@ -488,7 +488,7 @@ namespace BizHawk.Client.EmuHawk
.OrderByDescending(x => x.GameName)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.RawFrames)
.ThenBy(x => x.FrameCount)
.ToList();
}
else
@ -497,7 +497,7 @@ namespace BizHawk.Client.EmuHawk
.OrderBy(x => x.GameName)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.RawFrames)
.ThenBy(x => x.FrameCount)
.ToList();
}
break;
@ -505,16 +505,16 @@ namespace BizHawk.Client.EmuHawk
if (_sortReverse)
{
_movieList = _movieList
.OrderByDescending(x => x.RawFrames)
.OrderByDescending(x => x.FrameCount)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)
.ThenBy(x => x.FrameCount)
.ToList();
}
else
{
_movieList = _movieList
.OrderBy(x => x.RawFrames)
.OrderBy(x => x.FrameCount)
.ThenBy(x => Path.GetFileName(x.Filename))
.ThenBy(x => x.SysID)
.ThenBy(x => x.GameName)

View File

@ -125,7 +125,7 @@ namespace BizHawk.Client.EmuHawk
text = "";
//If this is just for an actual frame and not just the list view cursor at the end
if (Global.MovieSession.Movie.Frames != index)
if (Global.MovieSession.Movie.FrameCount != index)
{
if (column == 0)
text = String.Format("{0:#,##0}", index);
@ -136,7 +136,7 @@ namespace BizHawk.Client.EmuHawk
private void DisplayList()
{
TASView.ItemCount = Global.MovieSession.Movie.RawFrames;
TASView.ItemCount = Global.MovieSession.Movie.InputLogLength;
//if (Global.MovieSession.Movie.Frames == Global.Emulator.Frame && Global.MovieSession.Movie.StateLastIndex == Global.Emulator.Frame - 1)
//{
// //If we're at the end of the movie add one to show the cursor as a blank frame
@ -253,7 +253,7 @@ namespace BizHawk.Client.EmuHawk
if (Global.MovieSession.Movie.IsFinished || !Global.MovieSession.Movie.IsActive)
{
GlobalWin.MainForm.Rewind(1);
if (Global.Emulator.Frame <= Global.MovieSession.Movie.Frames)
if (Global.Emulator.Frame <= Global.MovieSession.Movie.FrameCount)
{
Global.MovieSession.Movie.SwitchToPlay();
}