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();

View File

@ -407,7 +407,7 @@
//
this.OpenRomMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.OpenFile;
this.OpenRomMenuItem.Name = "OpenRomMenuItem";
this.OpenRomMenuItem.Size = new System.Drawing.Size(152, 22);
this.OpenRomMenuItem.Size = new System.Drawing.Size(140, 22);
this.OpenRomMenuItem.Text = "Open ROM";
this.OpenRomMenuItem.Click += new System.EventHandler(this.OpenRomMenuItem_Click);
//
@ -417,7 +417,7 @@
this.toolStripSeparator3});
this.RecentRomSubMenu.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Recent;
this.RecentRomSubMenu.Name = "RecentRomSubMenu";
this.RecentRomSubMenu.Size = new System.Drawing.Size(152, 22);
this.RecentRomSubMenu.Size = new System.Drawing.Size(140, 22);
this.RecentRomSubMenu.Text = "Recent ROM";
this.RecentRomSubMenu.DropDownOpened += new System.EventHandler(this.RecentRomMenuItem_DropDownOpened);
//
@ -430,14 +430,14 @@
//
this.CloseRomMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Close;
this.CloseRomMenuItem.Name = "CloseRomMenuItem";
this.CloseRomMenuItem.Size = new System.Drawing.Size(152, 22);
this.CloseRomMenuItem.Size = new System.Drawing.Size(140, 22);
this.CloseRomMenuItem.Text = "&Close ROM";
this.CloseRomMenuItem.Click += new System.EventHandler(this.CloseRomMenuItem_Click);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem1.Size = new System.Drawing.Size(137, 6);
//
// SaveStateSubMenu
//
@ -455,7 +455,7 @@
this.toolStripSeparator6,
this.SaveNamedStateMenuItem});
this.SaveStateSubMenu.Name = "SaveStateSubMenu";
this.SaveStateSubMenu.Size = new System.Drawing.Size(152, 22);
this.SaveStateSubMenu.Size = new System.Drawing.Size(140, 22);
this.SaveStateSubMenu.Text = "Save State";
this.SaveStateSubMenu.DropDownOpened += new System.EventHandler(this.SaveStateSubMenu_DropDownOpened);
//
@ -559,7 +559,7 @@
this.toolStripSeparator21,
this.AutoloadLastSlotMenuItem});
this.LoadStateSubMenu.Name = "LoadStateSubMenu";
this.LoadStateSubMenu.Size = new System.Drawing.Size(152, 22);
this.LoadStateSubMenu.Size = new System.Drawing.Size(140, 22);
this.LoadStateSubMenu.Text = "Load State";
this.LoadStateSubMenu.DropDownOpened += new System.EventHandler(this.LoadStateSubMenu_DropDownOpened);
//
@ -676,7 +676,7 @@
this.SaveToCurrentSlotMenuItem,
this.LoadCurrentSlotMenuItem});
this.SaveSlotSubMenu.Name = "SaveSlotSubMenu";
this.SaveSlotSubMenu.Size = new System.Drawing.Size(152, 22);
this.SaveSlotSubMenu.Size = new System.Drawing.Size(140, 22);
this.SaveSlotSubMenu.Text = "SaveSlot";
this.SaveSlotSubMenu.DropDownOpened += new System.EventHandler(this.SaveSlotSubMenu_DropDownOpened);
//
@ -788,7 +788,7 @@
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem2.Size = new System.Drawing.Size(137, 6);
//
// MovieSubMenu
//
@ -808,7 +808,7 @@
this.AutomaticallyBackupMoviesMenuItem,
this.FullMovieLoadstatesMenuItem});
this.MovieSubMenu.Name = "MovieSubMenu";
this.MovieSubMenu.Size = new System.Drawing.Size(152, 22);
this.MovieSubMenu.Size = new System.Drawing.Size(140, 22);
this.MovieSubMenu.Text = "Movie";
this.MovieSubMenu.DropDownOpened += new System.EventHandler(this.MovieSubMenu_DropDownOpened);
//
@ -838,7 +838,7 @@
// toolStripSeparator16
//
this.toolStripSeparator16.Name = "toolStripSeparator16";
this.toolStripSeparator16.Size = new System.Drawing.Size(149, 6);
this.toolStripSeparator16.Size = new System.Drawing.Size(57, 6);
//
// RecordMovieMenuItem
//
@ -930,7 +930,7 @@
this.toolStripSeparator19,
this.CaptureOSDMenuItem});
this.AVSubMenu.Name = "AVSubMenu";
this.AVSubMenu.Size = new System.Drawing.Size(152, 22);
this.AVSubMenu.Size = new System.Drawing.Size(140, 22);
this.AVSubMenu.Text = "AVI/WAV";
this.AVSubMenu.DropDownOpened += new System.EventHandler(this.AVSubMenu_DropDownOpened);
//
@ -971,7 +971,7 @@
this.toolStripSeparator20,
this.ScreenshotCaptureOSDMenuItem1});
this.ScreenshotSubMenu.Name = "ScreenshotSubMenu";
this.ScreenshotSubMenu.Size = new System.Drawing.Size(152, 22);
this.ScreenshotSubMenu.Size = new System.Drawing.Size(140, 22);
this.ScreenshotSubMenu.Text = "Screenshot";
this.ScreenshotSubMenu.DropDownOpening += new System.EventHandler(this.ScreenshotSubMenu_DropDownOpening);
//
@ -1013,13 +1013,13 @@
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(149, 6);
this.toolStripSeparator4.Size = new System.Drawing.Size(137, 6);
//
// ExitMenuItem
//
this.ExitMenuItem.Name = "ExitMenuItem";
this.ExitMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4)));
this.ExitMenuItem.Size = new System.Drawing.Size(152, 22);
this.ExitMenuItem.Size = new System.Drawing.Size(140, 22);
this.ExitMenuItem.Text = "Exit";
this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click);
//
@ -1866,6 +1866,7 @@
//
// TAStudioMenuItem
//
this.TAStudioMenuItem.Enabled = false;
this.TAStudioMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.TAStudio;
this.TAStudioMenuItem.Name = "TAStudioMenuItem";
this.TAStudioMenuItem.Size = new System.Drawing.Size(189, 22);

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