Start an IMovie interface as a first step towards a major movie object refactor. Also disable TAStudio, in preparation for a complete rewrite. Disabling is necessary because a lot of movie functionality will be ripped out that will render the tool useless for now.

This commit is contained in:
adelikat 2013-11-23 17:26:33 +00:00
parent d88b4a3066
commit 1372fa258f
9 changed files with 2803 additions and 2727 deletions

View File

@ -120,6 +120,7 @@
<Compile Include="lua\LuaFunctionList.cs" />
<Compile Include="lua\LuaLibraryBase.cs" />
<Compile Include="lua\NamedLuaFunction.cs" />
<Compile Include="movie\IMovie.cs" />
<Compile Include="movie\InputAdapters.cs" />
<Compile Include="movie\Movie.cs" />
<Compile Include="movie\MovieHeader.cs" />

View File

@ -0,0 +1,75 @@
using System.IO;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public interface IMovie
{
int Rerecords { get; set; }
string Filename { get; set; }
bool IsCountingRerecords { get; set; }
bool IsActive { get; }
bool IsPlaying { get; }
bool IsRecording { get; }
bool IsFinished { get; }
bool LoadMovie();
void WriteBackup();
#region Editing API
void ClearFrame(int frame);
void ModifyFrame(string record, int frame);
void AppendFrame(string record);
void InsertFrame(string record, int frame);
void InsertBlankFrame(int frame);
void DeleteFrame(int frame);
void TruncateMovie(int frame);
#endregion
#region Dubious, should reconsider
bool Loaded { get; } //Who needs to know it is loaded or not? The movie should decide what to do based on being loaded or not
bool IsText { get; } //remove until needed Make a get set, consider an Enum of FileTypeMode or something,
bool HasChanges { get; } //Rename to changes
void CommitFrame(int frameNum, IController source); //why pass in frameNum? Calling api
void PokeFrame(int frameNum, string input); //Why does this exist as something different than Commit Frame?
void CaptureState(); //Movie code should manage wheter it needs to capture a state
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 DateTime
void DumpLogIntoSavestateText(TextWriter writer); //Why pass a Textwriter, just make a string property that is the inputlog as text
void LoadLogFromSavestateText(TextReader reader, bool isMultitracking); //Pass in the text? do we need to care if it is multitracking, and can't hte movie already know that?
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
void Finish(); //Why isn't the movie in charge of this?
void StartRecording(bool truncate = true); //Why do we need to truncate or not truncate? Why isn't the object in charge of this decision?
void Stop(bool abortchanges = false); //Refactor to have a bool saveChanges instead
void StartPlayback(); //Poorly named for what it does, SetToPlay() perhaps? Also, this seems like too much power to give the calling code
void SwitchToRecord(); //Ditto
void SwitchToPlay(); //Dubious that it is needed
void WriteMovie(); //Rename to Write()
bool FrameLagged(int frame); //SHould be a property of a Record object
byte[] GetState(int frame); //Should be a property of a Record object
string GetInput(int frame); //Should be a property of a Record object
byte[] InitState { get; } //Should be a record object?
bool StartsFromSavestate { get; set; } //Why is this settable!!!
MovieHeader Header { get; } //Don't expose this!!!
MovieLog LogDump { get; } //Don't expose this!!!
SubtitleList Subtitles { get; } //Don't expose this!!!
int StateFirstIndex { get; }
int StateLastIndex { get; }
#endregion
}
}
//TODO: delete this and refactor code that uses it!
public enum LoadStateResult { Pass, GuidMismatch, TimeLineError, FutureEventError, NotInRecording, EmptyLog, MissingFrameNumber }

View File

@ -7,7 +7,7 @@ using System.Collections.Generic;
namespace BizHawk.Client.Common
{
public class Movie
public class Movie : IMovie
{
#region Constructors
@ -22,6 +22,7 @@ namespace BizHawk.Client.Common
public Movie()
{
Header = new MovieHeader();
Subtitles = new SubtitleList();
Filename = String.Empty;
_preloadFramecount = 0;
StartsFromSavestate = false;
@ -34,8 +35,8 @@ namespace BizHawk.Client.Common
#endregion
#region Properties
public MovieHeader Header;
public SubtitleList Subtitles = new SubtitleList();
public MovieHeader Header { get; private set; }
public SubtitleList Subtitles { get; private set; }
public bool MakeBackup { get; set; }
public string Filename { get; set; }
@ -641,8 +642,6 @@ namespace BizHawk.Client.Common
return time;
}
public enum LoadStateResult { Pass, GuidMismatch, TimeLineError, FutureEventError, NotInRecording, EmptyLog, MissingFrameNumber }
public LoadStateResult CheckTimeLines(TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage)
{
//This function will compare the movie data to the savestate movie data to see if they match

View File

@ -8,7 +8,7 @@ namespace BizHawk.Client.Common
public class MovieSession
{
public MultitrackRecording MultiTrack = new MultitrackRecording();
public Movie Movie;
public IMovie Movie;
public MovieControllerAdapter MovieControllerAdapter = new MovieControllerAdapter();
public bool EditorMode { get; set; }
public Action<string> MessageCallback; //Not Required
@ -216,7 +216,7 @@ namespace BizHawk.Client.Common
if (Global.ReadOnly)
{
var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == Movie.LoadStateResult.Pass)
if (result == LoadStateResult.Pass)
{
Movie.WriteMovie();
Movie.SwitchToPlay();
@ -225,12 +225,12 @@ namespace BizHawk.Client.Common
}
else
{
if (result == Movie.LoadStateResult.GuidMismatch)
if (result == LoadStateResult.GuidMismatch)
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == Movie.LoadStateResult.Pass)
if (newresult == LoadStateResult.Pass)
{
Movie.WriteMovie();
Movie.SwitchToPlay();
@ -257,7 +257,7 @@ namespace BizHawk.Client.Common
else
{
var result = Movie.CheckTimeLines(reader, onlyGuid: true, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == Movie.LoadStateResult.Pass)
if (result == LoadStateResult.Pass)
{
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
@ -265,12 +265,12 @@ namespace BizHawk.Client.Common
}
else
{
if (result == Movie.LoadStateResult.GuidMismatch)
if (result == LoadStateResult.GuidMismatch)
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == Movie.LoadStateResult.Pass)
if (newresult == LoadStateResult.Pass)
{
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
@ -302,19 +302,19 @@ namespace BizHawk.Client.Common
if (Global.ReadOnly)
{
var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == Movie.LoadStateResult.Pass)
if (result == LoadStateResult.Pass)
{
//Frame loop automatically handles the rewinding effect based on Global.Emulator.Frame so nothing else is needed here
return true;
}
else
{
if (result == Movie.LoadStateResult.GuidMismatch)
if (result == LoadStateResult.GuidMismatch)
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == Movie.LoadStateResult.Pass)
if (newresult == LoadStateResult.Pass)
{
return true;
}
@ -339,7 +339,7 @@ namespace BizHawk.Client.Common
else
{
var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == Movie.LoadStateResult.Pass)
if (result == LoadStateResult.Pass)
{
Movie.SwitchToRecord();
reader.BaseStream.Position = 0;
@ -349,12 +349,12 @@ namespace BizHawk.Client.Common
}
else
{
if (result == Movie.LoadStateResult.GuidMismatch)
if (result == LoadStateResult.GuidMismatch)
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == Movie.LoadStateResult.Pass)
if (newresult == LoadStateResult.Pass)
{
Movie.SwitchToRecord();
reader.BaseStream.Position = 0;
@ -386,14 +386,14 @@ namespace BizHawk.Client.Common
if (Global.ReadOnly)
{
var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result != Movie.LoadStateResult.Pass)
if (result != LoadStateResult.Pass)
{
if (result == Movie.LoadStateResult.GuidMismatch)
if (result == LoadStateResult.GuidMismatch)
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: true, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == Movie.LoadStateResult.Pass)
if (newresult == LoadStateResult.Pass)
{
Movie.SwitchToPlay();
return true;
@ -427,7 +427,7 @@ namespace BizHawk.Client.Common
else
{
var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == Movie.LoadStateResult.Pass)
if (result == LoadStateResult.Pass)
{
Global.Emulator.ClearSaveRam();
Movie.StartRecording();
@ -438,12 +438,12 @@ namespace BizHawk.Client.Common
}
else
{
if (result == Movie.LoadStateResult.GuidMismatch)
if (result == LoadStateResult.GuidMismatch)
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == Movie.LoadStateResult.Pass)
if (newresult == LoadStateResult.Pass)
{
Global.Emulator.ClearSaveRam();
Movie.StartRecording();

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ namespace BizHawk.Client.EmuHawk
{
public partial class EditCommentsForm : Form
{
private Movie selectedMovie;
private IMovie selectedMovie;
public EditCommentsForm()
{
@ -52,7 +52,7 @@ namespace BizHawk.Client.EmuHawk
Close();
}
public void GetMovie(Movie m)
public void GetMovie(IMovie m)
{
selectedMovie = m;
if (m.Header.Comments.Count == 0) return;

View File

@ -10,7 +10,7 @@ namespace BizHawk.Client.EmuHawk
public partial class EditSubtitlesForm : Form
{
public bool ReadOnly;
private Movie selectedMovie;
private IMovie selectedMovie;
public EditSubtitlesForm()
{
@ -84,7 +84,7 @@ namespace BizHawk.Client.EmuHawk
Close();
}
public void GetMovie(Movie m)
public void GetMovie(IMovie m)
{
selectedMovie = m;
SubtitleList subs = new SubtitleList();

View File

@ -20,7 +20,7 @@ namespace BizHawk.Client.EmuHawk
components.Dispose();
}
Global.MovieSession.Movie.StateCapturing = false; //TODO: This doesn't go here, extend this method in the .cs file
//Global.MovieSession.Movie.StateCapturing = false; //TODO: This doesn't go here, extend this method in the .cs file
base.Dispose(disposing);
}

View File

@ -161,7 +161,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.OSD.AddMessage("TAStudio engaged");
if (Global.MovieSession.Movie.IsActive)
{
Global.MovieSession.Movie.StateCapturing = true;
//Global.MovieSession.Movie.StateCapturing = true;
ReadOnlyCheckBox.Checked = Global.ReadOnly;
}
else