From ce3bb25409ef8f9044e84ffcc6af13def72d0d1c Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Sun, 31 Jul 2011 01:15:14 +0000 Subject: [PATCH] Movie object cleanup, movie savestate handling cleanup, save GUID into movie savestates --- BizHawk.MultiClient/MainForm.Movie.cs | 93 ++++++++++++++++++++++++ BizHawk.MultiClient/MainForm.cs | 91 ----------------------- BizHawk.MultiClient/PlayMovie.cs | 2 +- BizHawk.MultiClient/movie/Movie.cs | 16 +++- BizHawk.MultiClient/movie/MovieHeader.cs | 12 +++ 5 files changed, 118 insertions(+), 96 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.Movie.cs b/BizHawk.MultiClient/MainForm.Movie.cs index acec9df071..36b58dbd6c 100644 --- a/BizHawk.MultiClient/MainForm.Movie.cs +++ b/BizHawk.MultiClient/MainForm.Movie.cs @@ -109,5 +109,98 @@ namespace BizHawk.MultiClient SetMainformMovieInfo(); } } + + private void HandleMovieLoadState(StreamReader reader) + { + //Note, some of the situations in these IF's may be identical and could be combined but I intentionally separated it out for clarity + if (UserMovie.Mode == MOVIEMODE.RECORD) + { + + if (ReadOnly) + { + + int x = UserMovie.CheckTimeLines(reader); + //if (x >= 0) + // MessageBox.Show("Savestate input log does not match the movie at frame " + (x+1).ToString() + "!", "Timeline error", MessageBoxButtons.OK); //TODO: replace with a not annoying message once savestate logic is running smoothly + //else + { + UserMovie.WriteMovie(); + UserMovie.StartPlayback(); + SetMainformMovieInfo(); + Global.MovieMode = true; + } + } + else + { + Global.MovieMode = false; + UserMovie.LoadLogFromSavestateText(reader); + } + } + else if (UserMovie.Mode == MOVIEMODE.PLAY) + { + if (ReadOnly) + { + int x = UserMovie.CheckTimeLines(reader); + //if (x >= 0) + // MessageBox.Show("Savestate input log does not match the movie at frame " + (x+1).ToString() + "!", "Timeline error", MessageBoxButtons.OK); //TODO: replace with a not annoying message once savestate logic is running smoothly + } + else + { + //QUESTIONABLE - control whether the movie gets truncated here? + UserMovie.StartNewRecording(!Global.MovieSession.MultiTrack.IsActive); + SetMainformMovieInfo(); + Global.MovieMode = false; + UserMovie.LoadLogFromSavestateText(reader); + } + } + else if (UserMovie.Mode == MOVIEMODE.FINISHED) + { + //TODO: have the input log kick in upon movie finished mode and stop upon movie resume + if (ReadOnly) + { + if (Global.Emulator.Frame > UserMovie.Length()) + { + Global.MovieMode = false; + //Post movie savestate + //There is no movie data to load, and the movie will stay in movie finished mode + //So do nothing + } + else + { + int x = UserMovie.CheckTimeLines(reader); + UserMovie.StartPlayback(); + SetMainformMovieInfo(); + Global.MovieMode = true; + //if (x >= 0) + // MessageBox.Show("Savestate input log does not match the movie at frame " + (x+1).ToString() + "!", "Timeline error", MessageBoxButtons.OK); //TODO: replace with a not annoying message once savestate logic is running smoothly + } + } + else + { + if (Global.Emulator.Frame > UserMovie.Length()) + { + Global.MovieMode = false; + //Post movie savestate + //There is no movie data to load, and the movie will stay in movie finished mode + //So do nothing + } + else + { + UserMovie.StartNewRecording(); + Global.MovieMode = false; + SetMainformMovieInfo(); + UserMovie.LoadLogFromSavestateText(reader); + } + } + } + } + + private void HandleMovieSaveState(StreamWriter writer) + { + if (UserMovie.Mode != MOVIEMODE.INACTIVE) + { + UserMovie.DumpLogIntoSavestateText(writer); + } + } } } diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 2c2743526d..1483aedf4b 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1557,14 +1557,6 @@ namespace BizHawk.MultiClient MakeScreenshot(String.Format(Global.Game.ScreenshotPrefix + ".{0:yyyy-MM-dd HH.mm.ss}.png", DateTime.Now)); } - private void HandleMovieSaveState(StreamWriter writer) - { - if (UserMovie.Mode != MOVIEMODE.INACTIVE) - { - UserMovie.DumpLogIntoSavestateText(writer); - } - } - private void SaveState(string name) { string path = Global.Game.SaveStatePrefix + "." + name + ".State"; @@ -1604,89 +1596,6 @@ namespace BizHawk.MultiClient UpdateStatusSlots(); } - private void HandleMovieLoadState(StreamReader reader) - { - //Note, some of the situations in these IF's may be identical and could be combined but I intentionally separated it out for clarity - if (UserMovie.Mode == MOVIEMODE.RECORD) - { - if (ReadOnly) - { - int x = UserMovie.CheckTimeLines(reader); - //if (x >= 0) - // MessageBox.Show("Savestate input log does not match the movie at frame " + (x+1).ToString() + "!", "Timeline error", MessageBoxButtons.OK); //TODO: replace with a not annoying message once savestate logic is running smoothly - //else - { - UserMovie.WriteMovie(); - UserMovie.StartPlayback(); - SetMainformMovieInfo(); - Global.MovieMode = true; - } - } - else - { - Global.MovieMode = false; - UserMovie.LoadLogFromSavestateText(reader); - } - } - else if (UserMovie.Mode == MOVIEMODE.PLAY) - { - if (ReadOnly) - { - int x = UserMovie.CheckTimeLines(reader); - //if (x >= 0) - // MessageBox.Show("Savestate input log does not match the movie at frame " + (x+1).ToString() + "!", "Timeline error", MessageBoxButtons.OK); //TODO: replace with a not annoying message once savestate logic is running smoothly - } - else - { - //QUESTIONABLE - control whether the movie gets truncated here? - UserMovie.StartNewRecording(!Global.MovieSession.MultiTrack.IsActive); - SetMainformMovieInfo(); - Global.MovieMode = false; - UserMovie.LoadLogFromSavestateText(reader); - } - } - else if (UserMovie.Mode == MOVIEMODE.FINISHED) - { - //TODO: have the input log kick in upon movie finished mode and stop upon movie resume - if (ReadOnly) - { - if (Global.Emulator.Frame > UserMovie.Length()) - { - Global.MovieMode = false; - //Post movie savestate - //There is no movie data to load, and the movie will stay in movie finished mode - //So do nothing - } - else - { - int x = UserMovie.CheckTimeLines(reader); - UserMovie.StartPlayback(); - SetMainformMovieInfo(); - Global.MovieMode = true; - //if (x >= 0) - // MessageBox.Show("Savestate input log does not match the movie at frame " + (x+1).ToString() + "!", "Timeline error", MessageBoxButtons.OK); //TODO: replace with a not annoying message once savestate logic is running smoothly - } - } - else - { - if (Global.Emulator.Frame > UserMovie.Length()) - { - Global.MovieMode = false; - //Post movie savestate - //There is no movie data to load, and the movie will stay in movie finished mode - //So do nothing - } - else - { - UserMovie.StartNewRecording(); - Global.MovieMode = false; - SetMainformMovieInfo(); - UserMovie.LoadLogFromSavestateText(reader); - } - } - } - } - private void LoadStateFile(string path, string name) { var reader = new StreamReader(path); diff --git a/BizHawk.MultiClient/PlayMovie.cs b/BizHawk.MultiClient/PlayMovie.cs index eff16e0984..7234918d1b 100644 --- a/BizHawk.MultiClient/PlayMovie.cs +++ b/BizHawk.MultiClient/PlayMovie.cs @@ -32,7 +32,7 @@ namespace BizHawk.MultiClient if (column == 0) //File text = Path.GetFileName(MovieList[index].Filename); if (column == 1) //System - text = MovieList[index].GetSysID(); + text = MovieList[index].SysID(); if (column == 2) //Game text = MovieList[index].GetGameName(); if (column == 3) //Time diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs index 92b267849a..738a44b569 100644 --- a/BizHawk.MultiClient/movie/Movie.cs +++ b/BizHawk.MultiClient/movie/Movie.cs @@ -35,7 +35,8 @@ namespace BizHawk.MultiClient IsText = true; Frames = 0; StartsFromSavestate = false; - Loaded = false; + if (filename.Length > 0) + Loaded = true; } public Movie() @@ -48,11 +49,16 @@ namespace BizHawk.MultiClient Loaded = false; } - public string GetSysID() + public string SysID() { return Header.GetHeaderLine(MovieHeader.PLATFORM); } + public string GUID() + { + return Header.GetHeaderLine(MovieHeader.GUID); + } + public string GetGameName() { return Header.GetHeaderLine(MovieHeader.GAMENAME); @@ -310,6 +316,8 @@ namespace BizHawk.MultiClient public void DumpLogIntoSavestateText(TextWriter writer) { writer.WriteLine("[Input]"); + string s = MovieHeader.GUID + " " + Header.GetHeaderLine(MovieHeader.GUID); + writer.WriteLine(s); for (int x = 0; x < Log.Length(); x++) writer.WriteLine(Log.GetFrame(x)); writer.WriteLine("[/Input]"); @@ -571,8 +579,8 @@ namespace BizHawk.MultiClient private int CompareSysID(Movie Other) { - string otherSysID = Other.GetSysID(); - string thisSysID = this.GetSysID(); + string otherSysID = Other.SysID(); + string thisSysID = this.SysID(); if (thisSysID == null && otherSysID == null) return 0; diff --git a/BizHawk.MultiClient/movie/MovieHeader.cs b/BizHawk.MultiClient/movie/MovieHeader.cs index 7e988135a6..67cb5604d3 100644 --- a/BizHawk.MultiClient/movie/MovieHeader.cs +++ b/BizHawk.MultiClient/movie/MovieHeader.cs @@ -184,5 +184,17 @@ namespace BizHawk.MultiClient return true; } + public void ReadHeader(StreamReader reader) + { + using (reader) + { + string str = ""; + while ((str = reader.ReadLine()) != null) + { + AddHeaderFromLine(str); + } + reader.Close(); + } + } } }