From b7d553cb4ee32bc79ddbe47cb7bd472cc0bb5cf2 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 3 Dec 2013 18:08:45 +0000 Subject: [PATCH] Move the readonly flag from Global to MovieSession --- BizHawk.Client.Common/Global.cs | 1 - .../lua/EmuLuaLibrary.Movie.cs | 4 +- BizHawk.Client.Common/movie/IMovie.cs | 3 +- BizHawk.Client.Common/movie/Movie.cs | 12 ++-- BizHawk.Client.Common/movie/MovieSession.cs | 47 +++++++-------- BizHawk.Client.Common/movie/TasMovie.cs | 59 +++++++++---------- BizHawk.Client.EmuHawk/MainForm.Events.cs | 8 +-- BizHawk.Client.EmuHawk/MainForm.Movie.cs | 8 ++- BizHawk.Client.EmuHawk/MainForm.cs | 8 +-- .../movie/EditCommentsForm.cs | 4 +- BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 2 +- 11 files changed, 77 insertions(+), 79 deletions(-) diff --git a/BizHawk.Client.Common/Global.cs b/BizHawk.Client.Common/Global.cs index 5b045766be..658997bfe3 100644 --- a/BizHawk.Client.Common/Global.cs +++ b/BizHawk.Client.Common/Global.cs @@ -20,7 +20,6 @@ namespace BizHawk.Client.Common /// public static MultitrackRewiringControllerAdapter MultitrackRewiringControllerAdapter = new MultitrackRewiringControllerAdapter(); public static MovieSession MovieSession = new MovieSession(); - public static bool ReadOnly = true; //Global Movie Read only setting /// /// whether throttling is force-disabled by use of fast forward diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs index faf3ab2265..b199c69905 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Movie.cs @@ -58,7 +58,7 @@ namespace BizHawk.Client.Common public static bool movie_getreadonly() { - return Global.ReadOnly; + return Global.MovieSession.ReadOnly; } public static bool movie_getrerecordcounting() @@ -103,7 +103,7 @@ namespace BizHawk.Client.Common public static void movie_setreadonly(object lua_input) { - Global.ReadOnly = (lua_input.ToString().ToUpper() == "TRUE" + Global.MovieSession.ReadOnly = (lua_input.ToString().ToUpper() == "TRUE" || lua_input.ToString() == "1"); } diff --git a/BizHawk.Client.Common/movie/IMovie.cs b/BizHawk.Client.Common/movie/IMovie.cs index 5f79959aad..9a8104c1e3 100644 --- a/BizHawk.Client.Common/movie/IMovie.cs +++ b/BizHawk.Client.Common/movie/IMovie.cs @@ -116,7 +116,8 @@ namespace BizHawk.Client.Common #region Dubious, should reconsider 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 - void ExtractInputLog(TextReader reader, bool isMultitracking); // how about the movie know if it is multi-tracking rather than having to pass it in + + void ExtractInputLog(TextReader reader); //Is passing a textreader the only reasonable way to do this? #endregion } diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index df6401d6e3..e622d483cd 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -407,12 +407,12 @@ namespace BizHawk.Client.Common return sb.ToString(); } - public void ExtractInputLog(TextReader reader, bool isMultitracking) + public void ExtractInputLog(TextReader reader) { int? stateFrame = null; // We are in record mode so replace the movie log with the one from the savestate - if (!isMultitracking) + if (!Global.MovieSession.MultiTrack.IsActive) { if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0) { @@ -816,7 +816,7 @@ namespace BizHawk.Client.Common var pal = Header.ContainsKey(HeaderKeys.PAL) && Header[HeaderKeys.PAL] == "1"; - return frames / FrameRates[system, pal]; + return frames / _frameRates[system, pal]; } public double Fps @@ -827,16 +827,12 @@ namespace BizHawk.Client.Common var pal = Header.ContainsKey(HeaderKeys.PAL) && Header[HeaderKeys.PAL] == "1"; - return FrameRates[system, pal]; + return _frameRates[system, pal]; } } #endregion private readonly PlatformFrameRates _frameRates = new PlatformFrameRates(); - public PlatformFrameRates FrameRates - { - get { return _frameRates; } - } } } \ No newline at end of file diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index 2f12631d60..34e420274f 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -13,6 +13,8 @@ namespace BizHawk.Client.Common public Action MessageCallback; //Not Required public Func AskYesNoCallback; //Not Required + public bool ReadOnly = true; + private void Output(string message) { if (MessageCallback != null) @@ -69,9 +71,7 @@ namespace BizHawk.Client.Common // Attempting to get a frame past the end of a movie changes the mode to finished if (!Movie.IsFinished) { - MovieControllerAdapter.SetControllersAsMnemonic( - Movie.GetInput(Global.Emulator.Frame) - ); + MovieControllerAdapter.SetControllersAsMnemonic(input); } } @@ -97,7 +97,7 @@ namespace BizHawk.Client.Common Output(Path.GetFileName(Movie.Filename) + " written to disk."); } Output(message); - Global.ReadOnly = true; + ReadOnly = true; } } @@ -115,7 +115,7 @@ namespace BizHawk.Client.Common if (Movie.IsPlaying) { Movie.ClearFrame(Global.Emulator.Frame); - Output("Scrubbed input at frame " + Global.Emulator.Frame.ToString()); + Output("Scrubbed input at frame " + Global.Emulator.Frame); } } @@ -179,8 +179,9 @@ namespace BizHawk.Client.Common { LatchInputFromPlayer(Global.MovieInputSourceAdapter); } - //the movie session makes sure that the correct input has been read and merged to its MovieControllerAdapter; - //this has been wired to Global.MovieOutputHardpoint in RewireInputChain + + // the movie session makes sure that the correct input has been read and merged to its MovieControllerAdapter; + // this has been wired to Global.MovieOutputHardpoint in RewireInputChain var mg = new MnemonicsGenerator(); mg.SetSource(Global.MovieOutputHardpoint); Movie.RecordFrame(Global.Emulator.Frame, mg); @@ -191,7 +192,7 @@ namespace BizHawk.Client.Common { using (var sr = new StreamReader(path)) { - return Global.MovieSession.HandleMovieLoadState(sr); + return HandleMovieLoadState(sr); } } @@ -207,7 +208,7 @@ namespace BizHawk.Client.Common else if (Movie.IsRecording) { - if (Global.ReadOnly) + if (ReadOnly) { var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); if (result == LoadStateResult.Pass) @@ -255,7 +256,7 @@ namespace BizHawk.Client.Common { reader.BaseStream.Position = 0; reader.DiscardBufferedData(); - Movie.ExtractInputLog(reader, MultiTrack.IsActive); + Movie.ExtractInputLog(reader); } else { @@ -268,7 +269,7 @@ namespace BizHawk.Client.Common { reader.BaseStream.Position = 0; reader.DiscardBufferedData(); - Movie.ExtractInputLog(reader, MultiTrack.IsActive); + Movie.ExtractInputLog(reader); return true; } else @@ -293,9 +294,9 @@ namespace BizHawk.Client.Common else if (Movie.IsPlaying && !Movie.IsFinished) { - if (Global.ReadOnly) + if (ReadOnly) { - var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); + var result = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); if (result == LoadStateResult.Pass) { //Frame loop automatically handles the rewinding effect based on Global.Emulator.Frame so nothing else is needed here @@ -307,7 +308,7 @@ namespace BizHawk.Client.Common { if (HandleGuidError()) { - var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG); + var newresult = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG); if (newresult == LoadStateResult.Pass) { return true; @@ -332,13 +333,13 @@ namespace BizHawk.Client.Common } else { - var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); + var result = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); if (result == LoadStateResult.Pass) { Movie.SwitchToRecord(); reader.BaseStream.Position = 0; reader.DiscardBufferedData(); - Movie.ExtractInputLog(reader, MultiTrack.IsActive); + Movie.ExtractInputLog(reader); return true; } else @@ -347,13 +348,13 @@ namespace BizHawk.Client.Common { if (HandleGuidError()) { - var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG); + var newresult = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG); if (newresult == LoadStateResult.Pass) { Movie.SwitchToRecord(); reader.BaseStream.Position = 0; reader.DiscardBufferedData(); - Movie.ExtractInputLog(reader, MultiTrack.IsActive); + Movie.ExtractInputLog(reader); return true; } else @@ -377,7 +378,7 @@ namespace BizHawk.Client.Common } else if (Movie.IsFinished) { - if (Global.ReadOnly) + if (ReadOnly) { var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); if (result != LoadStateResult.Pass) @@ -420,14 +421,14 @@ namespace BizHawk.Client.Common } else { - var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); + var result = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG); if (result == LoadStateResult.Pass) { Global.Emulator.ClearSaveRam(); Movie.StartNewRecording(); reader.BaseStream.Position = 0; reader.DiscardBufferedData(); - Movie.ExtractInputLog(reader, MultiTrack.IsActive); + Movie.ExtractInputLog(reader); return true; } else @@ -436,14 +437,14 @@ namespace BizHawk.Client.Common { if (HandleGuidError()) { - var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG); + var newresult = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG); if (newresult == LoadStateResult.Pass) { Global.Emulator.ClearSaveRam(); Movie.StartNewRecording(); reader.BaseStream.Position = 0; reader.DiscardBufferedData(); - Movie.ExtractInputLog(reader, MultiTrack.IsActive); + Movie.ExtractInputLog(reader); return true; } else diff --git a/BizHawk.Client.Common/movie/TasMovie.cs b/BizHawk.Client.Common/movie/TasMovie.cs index 6b1b12ee7f..f35beb5d6b 100644 --- a/BizHawk.Client.Common/movie/TasMovie.cs +++ b/BizHawk.Client.Common/movie/TasMovie.cs @@ -65,7 +65,6 @@ namespace BizHawk.Client.Common { get { - return new TimeSpan(); double dblseconds = GetSeconds(_records.Count); int seconds = (int)(dblseconds % 60); int days = seconds / 86400; @@ -139,34 +138,6 @@ namespace BizHawk.Client.Common _records.Truncate(frame); } - // TODO: - - public void StartNewRecording() - { - SwitchToRecord(); - if (Global.Config.EnableBackupMovies && true/*TODO*/ && _records.Any()) - { - // TODO - } - } - - public bool Load() - { - throw new NotImplementedException(); - } - - public void Save() - { - Changes = false; - throw new NotImplementedException(); - } - - public void SaveAs() - { - Changes = false; - throw new NotImplementedException(); - } - public void ClearFrame(int frame) { if (frame < _records.Count) @@ -211,12 +182,40 @@ namespace BizHawk.Client.Common } } + // TODO: + + public void StartNewRecording() + { + SwitchToRecord(); + if (Global.Config.EnableBackupMovies && true/*TODO*/ && _records.Any()) + { + // TODO + } + } + + public bool Load() + { + throw new NotImplementedException(); + } + + public void Save() + { + Changes = false; + throw new NotImplementedException(); + } + + public void SaveAs() + { + Changes = false; + throw new NotImplementedException(); + } + public LoadStateResult CheckTimeLines(System.IO.TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage) { throw new NotImplementedException(); } - public void ExtractInputLog(System.IO.TextReader reader, bool isMultitracking) + public void ExtractInputLog(System.IO.TextReader reader) { throw new NotImplementedException(); } diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 4da6a39007..8e909eb026 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -232,7 +232,7 @@ namespace BizHawk.Client.EmuHawk = SaveMovieMenuItem.Enabled = Global.MovieSession.Movie.IsActive; - ReadonlyMenuItem.Checked = Global.ReadOnly; + ReadonlyMenuItem.Checked = Global.MovieSession.ReadOnly; BindSavestatesToMoviesMenuItem.Checked = Global.Config.BindSavestatesToMovies; AutomaticallyBackupMoviesMenuItem.Checked = Global.Config.EnableBackupMovies; FullMovieLoadstatesMenuItem.Checked = Global.Config.VBAStyleMovieLoadState; @@ -1760,7 +1760,7 @@ namespace BizHawk.Client.EmuHawk 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.MovieSession.ReadOnly; ConfigContextMenuItem.Visible = _inFullscreen; @@ -1773,7 +1773,7 @@ namespace BizHawk.Client.EmuHawk if (Global.MovieSession.Movie.IsActive) { - if (Global.ReadOnly) + if (Global.MovieSession.ReadOnly) { ViewSubtitlesContextMenuItem.Text = "View Subtitles"; ViewCommentsContextMenuItem.Text = "View Comments"; @@ -1847,7 +1847,7 @@ namespace BizHawk.Client.EmuHawk { if (Global.MovieSession.Movie.IsActive) { - var form = new EditSubtitlesForm { ReadOnly = Global.ReadOnly }; + var form = new EditSubtitlesForm { ReadOnly = Global.MovieSession.ReadOnly }; form.GetMovie(Global.MovieSession.Movie); form.ShowDialog(); } diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index 5305e33c36..d000671890 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -43,16 +43,17 @@ namespace BizHawk.Client.EmuHawk LoadStateFile(Global.MovieSession.Movie.Filename, Path.GetFileName(Global.MovieSession.Movie.Filename)); Global.Emulator.ResetCounters(); } + if (record) { - Global.Emulator.ClearSaveRam(); Global.MovieSession.Movie.StartNewRecording(); - Global.ReadOnly = false; + Global.MovieSession.ReadOnly = false; } else { Global.MovieSession.Movie.StartNewPlayback(); } + SetMainformMovieInfo(); GlobalWin.Tools.Restart(); GlobalWin.Tools.Restart(); @@ -117,10 +118,11 @@ namespace BizHawk.Client.EmuHawk LoadStateFile(Global.MovieSession.Movie.Filename, Path.GetFileName(Global.MovieSession.Movie.Filename)); Global.Emulator.ResetCounters(); } + Global.MovieSession.Movie.StartNewPlayback(); SetMainformMovieInfo(); GlobalWin.OSD.AddMessage("Replaying movie file in read-only mode"); - Global.ReadOnly = true; + Global.MovieSession.ReadOnly = true; } } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 4c652138fd..ecb6186c43 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -209,7 +209,7 @@ namespace BizHawk.Client.EmuHawk else { var movie = new Movie(cmdMovie); - Global.ReadOnly = true; + Global.MovieSession.ReadOnly = true; // if user is dumping and didnt supply dump length, make it as long as the loaded movie if (_autoDumpLength == 0) { @@ -1548,7 +1548,7 @@ namespace BizHawk.Client.EmuHawk } else { - Global.ReadOnly = true; + Global.MovieSession.ReadOnly = true; StartNewMovie(movie, false); } } @@ -2074,8 +2074,8 @@ namespace BizHawk.Client.EmuHawk { if (Global.MovieSession.Movie.IsActive) { - Global.ReadOnly ^= true; - if (Global.ReadOnly) + Global.MovieSession.ReadOnly ^= true; + if (Global.MovieSession.ReadOnly) { GlobalWin.OSD.AddMessage("Movie read-only mode"); } diff --git a/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs b/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs index 7b5bd8e8f3..8a9e0c2fbc 100644 --- a/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs +++ b/BizHawk.Client.EmuHawk/movie/EditCommentsForm.cs @@ -16,7 +16,7 @@ namespace BizHawk.Client.EmuHawk private void EditCommentsForm_Load(object sender, EventArgs e) { - if (Global.ReadOnly) + if (Global.MovieSession.ReadOnly) { CommentGrid.Columns[0].ReadOnly = true; Text = "View Comments"; @@ -36,7 +36,7 @@ namespace BizHawk.Client.EmuHawk private void OK_Click(object sender, EventArgs e) { - if (!Global.ReadOnly) + if (!Global.MovieSession.ReadOnly) { _selectedMovie.Header.Comments.Clear(); for (int i = 0; i < CommentGrid.Rows.Count - 1; i++) diff --git a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index 441c0e968a..845bdefb39 100644 --- a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -63,7 +63,7 @@ namespace BizHawk.Client.EmuHawk private void OK_Click(object sender, EventArgs e) { - Global.ReadOnly = ReadOnlyCheckBox.Checked; + Global.MovieSession.ReadOnly = ReadOnlyCheckBox.Checked; Run(); Close(); }