More simplifying Movie Loadstate code

This commit is contained in:
adelikat 2013-12-04 03:16:35 +00:00
parent ec030ae05e
commit b70d03a93f
4 changed files with 19 additions and 24 deletions

View File

@ -115,13 +115,9 @@ namespace BizHawk.Client.Common
#region Dubious, should reconsider
LoadStateResult CheckTimeLines(TextReader reader, out string errorMessage); // No need to return a status, no reason to have hacky flags, no need to pass a textreader
bool CheckTimeLines(TextReader reader, out string errorMessage); //Can we avoid passing a text reader?
void ExtractInputLog(TextReader reader); //Is passing a textreader the only reasonable way to do this?
#endregion
}
}
// TODO: delete this and refactor code that uses it!
public enum LoadStateResult { Pass, TimeLineError, FutureEventError, NotInRecording, EmptyLog, MissingFrameNumber }

View File

@ -556,7 +556,7 @@ namespace BizHawk.Client.Common
}
}
public LoadStateResult CheckTimeLines(TextReader reader, out string errorMessage)
public bool CheckTimeLines(TextReader reader, out string errorMessage)
{
// This function will compare the movie data to the savestate movie data to see if they match
errorMessage = String.Empty;
@ -567,7 +567,7 @@ namespace BizHawk.Client.Common
var line = reader.ReadLine();
if (line == null)
{
return LoadStateResult.EmptyLog;
return false;
}
else if (line.Trim() == string.Empty)
{
@ -583,7 +583,7 @@ namespace BizHawk.Client.Common
catch
{
errorMessage = "Savestate Frame number failed to parse";
return LoadStateResult.MissingFrameNumber;
return false;
}
}
else if (line.Contains("Frame "))
@ -596,7 +596,7 @@ namespace BizHawk.Client.Common
catch
{
errorMessage = "Savestate Frame number failed to parse";
return LoadStateResult.MissingFrameNumber;
return false;
}
}
else if (line == "[Input]")
@ -622,7 +622,7 @@ namespace BizHawk.Client.Common
{
if (IsFinished)
{
return LoadStateResult.Pass;
return true;
}
else
{
@ -630,7 +630,7 @@ namespace BizHawk.Client.Common
+ log.Length
+ " which is greater than the current movie length of "
+ _log.Length;
return LoadStateResult.FutureEventError;
return false;
}
}
@ -641,7 +641,7 @@ namespace BizHawk.Client.Common
errorMessage = "The savestate input does not match the movie input at frame "
+ (i + 1)
+ ".";
return LoadStateResult.TimeLineError;
return false;
}
}
@ -650,11 +650,11 @@ namespace BizHawk.Client.Common
if (_mode == Moviemode.Play || _mode == Moviemode.Finished)
{
_mode = Moviemode.Finished;
return LoadStateResult.Pass;
return true;
}
else
{
return LoadStateResult.NotInRecording; // TODO: For now throw an error if recording, ideally what should happen is that the state gets loaded, and the movie set to movie finished, the movie at its current state is preserved and the state is loaded just fine. This should probably also only happen if checktimelines passes
return false;
}
}
else if (_mode == Moviemode.Finished)
@ -662,7 +662,7 @@ namespace BizHawk.Client.Common
_mode = Moviemode.Play;
}
return LoadStateResult.Pass;
return true;
}
#endregion

View File

@ -211,11 +211,10 @@ namespace BizHawk.Client.Common
if (ReadOnly)
{
var result = Movie.CheckTimeLines(reader, out ErrorMSG);
if (result == LoadStateResult.Pass)
if (result)
{
Movie.Save();
Movie.SwitchToPlay();
return true;
}
else
@ -227,7 +226,7 @@ namespace BizHawk.Client.Common
else
{
var result = Movie.CheckTimeLines(reader, out ErrorMSG);
if (result == LoadStateResult.Pass)
if (result)
{
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
@ -246,7 +245,7 @@ namespace BizHawk.Client.Common
if (ReadOnly)
{
var result = Movie.CheckTimeLines(reader, out ErrorMSG);
if (result == LoadStateResult.Pass)
if (result)
{
//Frame loop automatically handles the rewinding effect based on Global.Emulator.Frame so nothing else is needed here
return true;
@ -259,7 +258,7 @@ namespace BizHawk.Client.Common
else
{
var result = Movie.CheckTimeLines(reader, out ErrorMSG);
if (result == LoadStateResult.Pass)
if (result)
{
Movie.SwitchToRecord();
reader.BaseStream.Position = 0;
@ -279,7 +278,7 @@ namespace BizHawk.Client.Common
if (ReadOnly)
{
var result = Movie.CheckTimeLines(reader, errorMessage: out ErrorMSG);
if (result != LoadStateResult.Pass)
if (!result)
{
Output(ErrorMSG);
return false;
@ -296,7 +295,7 @@ namespace BizHawk.Client.Common
else
{
var result = Movie.CheckTimeLines(reader, out ErrorMSG);
if (result == LoadStateResult.Pass)
if (result)
{
Global.Emulator.ClearSaveRam();
Movie.StartNewRecording();

View File

@ -210,12 +210,12 @@ namespace BizHawk.Client.Common
throw new NotImplementedException();
}
public LoadStateResult CheckTimeLines(System.IO.TextReader reader, out string errorMessage)
public bool CheckTimeLines(TextReader reader, out string errorMessage)
{
throw new NotImplementedException();
}
public void ExtractInputLog(System.IO.TextReader reader)
public void ExtractInputLog(TextReader reader)
{
throw new NotImplementedException();
}