Some low-hanging fruit in the IMovie refactor

This commit is contained in:
adelikat 2013-11-23 18:18:58 +00:00
parent 1372fa258f
commit a7a28c000a
12 changed files with 45 additions and 51 deletions

View File

@ -11,16 +11,20 @@ namespace BizHawk.Client.Common
string Filename { get; set; } string Filename { get; set; }
bool IsCountingRerecords { get; set; } bool IsCountingRerecords { get; set; }
bool IsActive { get; } bool IsActive { get; }
bool IsPlaying { get; } bool IsPlaying { get; }
bool IsRecording { get; } bool IsRecording { get; }
bool IsFinished { get; } bool IsFinished { get; }
bool Changes { get; }
bool Loaded { get; }
bool LoadMovie(); bool Load();
void WriteBackup(); void Save();
void SaveAs();
void Stop(bool saveChanges = true);
#region Editing API #region Editing API
void ClearFrame(int frame); void ClearFrame(int frame);
void ModifyFrame(string record, int frame); void ModifyFrame(string record, int frame);
void AppendFrame(string record); void AppendFrame(string record);
@ -28,12 +32,10 @@ namespace BizHawk.Client.Common
void InsertBlankFrame(int frame); void InsertBlankFrame(int frame);
void DeleteFrame(int frame); void DeleteFrame(int frame);
void TruncateMovie(int frame); void TruncateMovie(int frame);
#endregion #endregion
#region Dubious, should reconsider #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 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 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 void CaptureState(); //Movie code should manage wheter it needs to capture a state
@ -46,14 +48,11 @@ namespace BizHawk.Client.Common
void Finish(); //Why isn't the movie in charge of this? 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 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 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 SwitchToRecord(); //Ditto
void SwitchToPlay(); //Dubious that it is needed void SwitchToPlay(); //Dubious that it is needed
void WriteMovie(); //Rename to Write()
bool FrameLagged(int frame); //SHould be a property of a Record object bool FrameLagged(int frame); //SHould be a property of a Record object
byte[] GetState(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 string GetInput(int frame); //Should be a property of a Record object
@ -65,7 +64,7 @@ namespace BizHawk.Client.Common
MovieLog LogDump { get; } //Don't expose this!!! MovieLog LogDump { get; } //Don't expose this!!!
SubtitleList Subtitles { get; } //Don't expose this!!! SubtitleList Subtitles { get; } //Don't expose this!!!
int StateFirstIndex { get; } int StateFirstIndex { get; } //What do these do?
int StateLastIndex { get; } int StateLastIndex { get; }
#endregion #endregion
} }

View File

@ -60,11 +60,6 @@ namespace BizHawk.Client.Common
get { return Header.GetHeaderLine(MovieHeader.PLATFORM); } get { return Header.GetHeaderLine(MovieHeader.PLATFORM); }
} }
public string Guid
{
get { return Header.GetHeaderLine(MovieHeader.GUID); }
}
public string GameName public string GameName
{ {
get { return Header.GetHeaderLine(MovieHeader.GAMENAME); } get { return Header.GetHeaderLine(MovieHeader.GAMENAME); }
@ -172,7 +167,7 @@ namespace BizHawk.Client.Common
get { return _mode == Moviemode.Finished; } get { return _mode == Moviemode.Finished; }
} }
public bool HasChanges public bool Changes
{ {
get { return _changes; } get { return _changes; }
} }
@ -186,7 +181,7 @@ namespace BizHawk.Client.Common
_mode = Moviemode.Record; _mode = Moviemode.Record;
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0) if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0)
{ {
WriteBackup(); SaveAs();
MakeBackup = false; MakeBackup = false;
} }
if (truncate) if (truncate)
@ -214,16 +209,16 @@ namespace BizHawk.Client.Common
public void SwitchToPlay() public void SwitchToPlay()
{ {
_mode = Moviemode.Play; _mode = Moviemode.Play;
WriteMovie(); Save();
} }
public void Stop(bool abortchanges = false) public void Stop(bool saveChanges = true)
{ {
if (!abortchanges) if (saveChanges)
{ {
if (_mode == Moviemode.Record || _changes) if (_mode == Moviemode.Record || _changes)
{ {
WriteMovie(); Save();
} }
} }
_changes = false; _changes = false;
@ -245,7 +240,7 @@ namespace BizHawk.Client.Common
#region Public File Handling #region Public File Handling
public void WriteMovie(string path) public void SaveAs(string path)
{ {
if (!Loaded) if (!Loaded)
{ {
@ -264,18 +259,18 @@ namespace BizHawk.Client.Common
} }
} }
public void WriteMovie() public void Save()
{ {
if (!Loaded || String.IsNullOrWhiteSpace(Filename)) if (!Loaded || String.IsNullOrWhiteSpace(Filename))
{ {
return; return;
} }
WriteMovie(Filename); SaveAs(Filename);
_changes = false; _changes = false;
} }
public void WriteBackup() public void SaveAs()
{ {
if (!Loaded || String.IsNullOrWhiteSpace(Filename)) if (!Loaded || String.IsNullOrWhiteSpace(Filename))
{ {
@ -355,7 +350,7 @@ namespace BizHawk.Client.Common
return true; return true;
} }
public bool LoadMovie() public bool Load()
{ {
var file = new FileInfo(Filename); var file = new FileInfo(Filename);
if (file.Exists == false) if (file.Exists == false)
@ -513,7 +508,7 @@ namespace BizHawk.Client.Common
{ {
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0) if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0)
{ {
WriteBackup(); SaveAs();
MakeBackup = false; MakeBackup = false;
} }
_log.Clear(); _log.Clear();

View File

@ -70,7 +70,7 @@ namespace BizHawk.Client.Common
); );
} }
public void StopMovie(bool abortchanges = false) public void StopMovie(bool saveChanges = true)
{ {
string message = "Movie "; string message = "Movie ";
if (Movie.IsRecording) if (Movie.IsRecording)
@ -86,8 +86,8 @@ namespace BizHawk.Client.Common
if (Movie.IsActive) if (Movie.IsActive)
{ {
Movie.Stop(abortchanges); Movie.Stop(saveChanges);
if (!abortchanges) if (saveChanges)
{ {
Output(Path.GetFileName(Movie.Filename) + " written to disk."); Output(Path.GetFileName(Movie.Filename) + " written to disk.");
} }
@ -218,7 +218,7 @@ namespace BizHawk.Client.Common
var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == LoadStateResult.Pass) if (result == LoadStateResult.Pass)
{ {
Movie.WriteMovie(); Movie.Save();
Movie.SwitchToPlay(); Movie.SwitchToPlay();
return true; return true;
@ -232,7 +232,7 @@ namespace BizHawk.Client.Common
var newresult = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: true, errorMessage: out ErrorMSG); var newresult = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == LoadStateResult.Pass) if (newresult == LoadStateResult.Pass)
{ {
Movie.WriteMovie(); Movie.Save();
Movie.SwitchToPlay(); Movie.SwitchToPlay();
return true; return true;
} }

View File

@ -226,7 +226,7 @@ namespace BizHawk.Client.EmuHawk
private void MovieSubMenu_DropDownOpened(object sender, EventArgs e) private void MovieSubMenu_DropDownOpened(object sender, EventArgs e)
{ {
FullMovieLoadstatesMenuItem.Enabled = !Global.MovieSession.MultiTrack.IsActive; FullMovieLoadstatesMenuItem.Enabled = !Global.MovieSession.MultiTrack.IsActive;
StopMovieWithoutSavingMenuItem.Enabled = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.HasChanges; StopMovieWithoutSavingMenuItem.Enabled = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.Changes;
StopMovieMenuItem.Enabled StopMovieMenuItem.Enabled
= PlayFromBeginningMenuItem.Enabled = PlayFromBeginningMenuItem.Enabled
= SaveMovieMenuItem.Enabled = SaveMovieMenuItem.Enabled
@ -436,7 +436,7 @@ namespace BizHawk.Client.EmuHawk
private void StopMovieWithoutSavingMenuItem_Click(object sender, EventArgs e) private void StopMovieWithoutSavingMenuItem_Click(object sender, EventArgs e)
{ {
StopMovie(true); StopMovie(saveChanges: false);
} }
private void BindSavestatesToMoviesMenuItem_Click(object sender, EventArgs e) private void BindSavestatesToMoviesMenuItem_Click(object sender, EventArgs e)
@ -1813,7 +1813,7 @@ namespace BizHawk.Client.EmuHawk
SaveMovieContextMenuItem.Visible = SaveMovieContextMenuItem.Visible =
Global.MovieSession.Movie.IsActive; Global.MovieSession.Movie.IsActive;
StopNoSaveContextMenuItem.Visible = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.HasChanges; StopNoSaveContextMenuItem.Visible = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.Changes;
AddSubtitleContextMenuItem.Visible = !(Global.Emulator is NullEmulator) && Global.MovieSession.Movie.IsActive && Global.ReadOnly; AddSubtitleContextMenuItem.Visible = !(Global.Emulator is NullEmulator) && Global.MovieSession.Movie.IsActive && Global.ReadOnly;
@ -1902,7 +1902,7 @@ namespace BizHawk.Client.EmuHawk
private void BackupMovieContextMenuItem_Click(object sender, EventArgs e) private void BackupMovieContextMenuItem_Click(object sender, EventArgs e)
{ {
GlobalWin.OSD.AddMessage("Backup movie saved."); GlobalWin.OSD.AddMessage("Backup movie saved.");
Global.MovieSession.Movie.WriteBackup(); Global.MovieSession.Movie.SaveAs();
} }
private void ViewSubtitlesContextMenuItem_Click(object sender, EventArgs e) private void ViewSubtitlesContextMenuItem_Click(object sender, EventArgs e)
@ -2214,7 +2214,7 @@ namespace BizHawk.Client.EmuHawk
//for instance, something which doesnt clobber movies you already may have had. //for instance, something which doesnt clobber movies you already may have had.
//i'm evenly torn between this, and a file in %TEMP%, but since we dont really have a way to clean up this tempfile, i choose this: //i'm evenly torn between this, and a file in %TEMP%, but since we dont really have a way to clean up this tempfile, i choose this:
movie.Filename += ".autoimported." + Global.Config.MovieExtension; movie.Filename += ".autoimported." + Global.Config.MovieExtension;
movie.WriteMovie(); movie.Save();
StartNewMovie(movie, false); StartNewMovie(movie, false);
} }
GlobalWin.OSD.AddMessage(warningMsg); GlobalWin.OSD.AddMessage(warningMsg);

View File

@ -17,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
//If a movie is already loaded, save it before starting a new movie //If a movie is already loaded, save it before starting a new movie
if (Global.MovieSession.Movie.IsActive) if (Global.MovieSession.Movie.IsActive)
{ {
Global.MovieSession.Movie.WriteMovie(); Global.MovieSession.Movie.Save();
} }
Global.MovieSession = new MovieSession Global.MovieSession = new MovieSession
@ -31,7 +31,7 @@ namespace BizHawk.Client.EmuHawk
if (!record) if (!record)
{ {
Global.MovieSession.Movie.LoadMovie(); Global.MovieSession.Movie.Load();
SetSyncDependentSettings(); SetSyncDependentSettings();
} }
@ -126,9 +126,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
public void StopMovie(bool abortchanges = false) public void StopMovie(bool saveChanges = true)
{ {
Global.MovieSession.StopMovie(); Global.MovieSession.StopMovie(saveChanges);
SetMainformMovieInfo(); SetMainformMovieInfo();
} }

View File

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

View File

@ -2381,7 +2381,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (Global.MovieSession.Movie.IsActive) if (Global.MovieSession.Movie.IsActive)
{ {
Global.MovieSession.Movie.WriteMovie(); Global.MovieSession.Movie.Save();
GlobalWin.OSD.AddMessage(Global.MovieSession.Movie.Filename + " saved."); GlobalWin.OSD.AddMessage(Global.MovieSession.Movie.Filename + " saved.");
} }
} }
@ -3794,7 +3794,7 @@ namespace BizHawk.Client.EmuHawk
Directory.CreateDirectory(d); Directory.CreateDirectory(d);
string outPath = Path.Combine(d, (Path.GetFileName(fn) + "." + Global.Config.MovieExtension)); string outPath = Path.Combine(d, (Path.GetFileName(fn) + "." + Global.Config.MovieExtension));
m.WriteMovie(outPath); m.SaveAs(outPath);
} }
public void FlagNeedsReboot() //Make private, config dialogs use it and it can be called after they close public void FlagNeedsReboot() //Make private, config dialogs use it and it can be called after they close

View File

@ -126,7 +126,7 @@ namespace BizHawk.Client.EmuHawk
); );
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
Global.MovieSession.Movie.WriteMovie(); Global.MovieSession.Movie.Save();
} }
} }
#endif #endif

View File

@ -47,7 +47,7 @@ namespace BizHawk.Client.EmuHawk
DataGridViewCell c = CommentGrid.Rows[x].Cells[0]; DataGridViewCell c = CommentGrid.Rows[x].Cells[0];
selectedMovie.Header.Comments.Add("comment " + c.Value); selectedMovie.Header.Comments.Add("comment " + c.Value);
} }
selectedMovie.WriteMovie(); selectedMovie.Save();
} }
Close(); Close();
} }

View File

@ -79,7 +79,7 @@ namespace BizHawk.Client.EmuHawk
s.Message = c.Value.ToString(); s.Message = c.Value.ToString();
selectedMovie.Subtitles.Add(s); selectedMovie.Subtitles.Add(s);
} }
selectedMovie.WriteMovie(); selectedMovie.Save();
} }
Close(); Close();
} }

View File

@ -93,7 +93,7 @@ namespace BizHawk.Client.EmuHawk
if (file.Extension.ToUpper() == "STATE") if (file.Extension.ToUpper() == "STATE")
{ {
Movie movie = new Movie(file.FullName); Movie movie = new Movie(file.FullName);
movie.LoadMovie(); //State files will have to load everything unfortunately movie.Load(); //State files will have to load everything unfortunately
if (movie.Frames == 0) if (movie.Frames == 0)
{ {
MessageBox.Show("No input log detected in this savestate, aborting", "Can not load file", MessageBoxButtons.OK, MessageBoxIcon.Hand); MessageBox.Show("No input log detected in this savestate, aborting", "Can not load file", MessageBoxButtons.OK, MessageBoxIcon.Hand);
@ -122,7 +122,7 @@ namespace BizHawk.Client.EmuHawk
if (x == 0) if (x == 0)
{ {
Movie movie = new Movie(file.CanonicalFullPath); Movie movie = new Movie(file.CanonicalFullPath);
movie.LoadMovie(); //State files will have to load everything unfortunately movie.Load(); //State files will have to load everything unfortunately
if (movie.Frames > 0) if (movie.Frames > 0)
{ {
_movieList.Add(movie); _movieList.Add(movie);

View File

@ -372,7 +372,7 @@ namespace BizHawk.Client.EmuHawk
private void saveProjectToolStripMenuItem_Click(object sender, EventArgs e) private void saveProjectToolStripMenuItem_Click(object sender, EventArgs e)
{ {
Global.MovieSession.Movie.WriteMovie(); Global.MovieSession.Movie.Save();
} }
private void saveProjectAsToolStripMenuItem_Click(object sender, EventArgs e) private void saveProjectAsToolStripMenuItem_Click(object sender, EventArgs e)
@ -382,7 +382,7 @@ namespace BizHawk.Client.EmuHawk
if ("" != fileName) if ("" != fileName)
{ {
Global.MovieSession.Movie.Filename = fileName; Global.MovieSession.Movie.Filename = fileName;
Global.MovieSession.Movie.WriteMovie(); Global.MovieSession.Movie.Save();
} }
} }