From 64f32983f604102934bd10d398c31dbf310418b4 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 25 Nov 2019 08:37:11 -0600 Subject: [PATCH] misc movie code cleanups --- BizHawk.Client.Common/SavestateManager.cs | 152 ++++++++---------- BizHawk.Client.Common/movie/MovieSession.cs | 22 +-- BizHawk.Client.EmuHawk/MainForm.Movie.cs | 7 +- .../tools/TAStudio/GreenzoneSettings.cs | 2 +- .../tools/TAStudio/MarkerControl.cs | 15 +- .../tools/TAStudio/PlaybackBox.cs | 39 +---- .../tools/TAStudio/ScreenshotForm.cs | 10 +- BizHawk.sln.DotSettings | 3 + 8 files changed, 97 insertions(+), 153 deletions(-) diff --git a/BizHawk.Client.Common/SavestateManager.cs b/BizHawk.Client.Common/SavestateManager.cs index 9b4051be49..dd9b505f51 100644 --- a/BizHawk.Client.Common/SavestateManager.cs +++ b/BizHawk.Client.Common/SavestateManager.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using BizHawk.Common; -using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common.IEmulatorExtensions; namespace BizHawk.Client.Common @@ -16,86 +15,84 @@ namespace BizHawk.Client.Common // the old method of text savestate save is now gone. // a text savestate is just like a binary savestate, but with a different core lump - using (var bs = new BinaryStateSaver(filename)) + using var bs = new BinaryStateSaver(filename); + if (Global.Config.SaveStateType == Config.SaveStateTypeE.Text + || (Global.Config.SaveStateType == Config.SaveStateTypeE.Default && !core.BinarySaveStatesPreferred)) { - if (Global.Config.SaveStateType == Config.SaveStateTypeE.Text || - (Global.Config.SaveStateType == Config.SaveStateTypeE.Default && !core.BinarySaveStatesPreferred)) + // text savestate format + using (new SimpleTime("Save Core")) { - // text savestate format - using (new SimpleTime("Save Core")) - { - bs.PutLump(BinaryStateLump.CorestateText, (tw) => core.SaveStateText(tw)); - } + bs.PutLump(BinaryStateLump.CorestateText, tw => core.SaveStateText(tw)); + } + } + else + { + // binary core lump format + using (new SimpleTime("Save Core")) + { + bs.PutLump(BinaryStateLump.Corestate, bw => core.SaveStateBinary(bw)); + } + } + + if (Global.Config.SaveScreenshotWithStates && Global.Emulator.HasVideoProvider()) + { + var vp = Global.Emulator.AsVideoProvider(); + var buff = vp.GetVideoBuffer(); + if (buff.Length == 1) + { + // is a hacky opengl texture ID. can't handle this now! + // need to discuss options + // 1. cores must be able to provide a pixels VideoProvider in addition to a texture ID, on command (not very hard overall but interface changing and work per core) + // 2. SavestateManager must be setup with a mechanism for resolving texture IDs (even less work, but sloppy) + // There are additional problems with AVWriting. They depend on VideoProvider providing pixels. } else { - // binary core lump format - using (new SimpleTime("Save Core")) + int outWidth = vp.BufferWidth; + int outHeight = vp.BufferHeight; + + // if buffer is too big, scale down screenshot + if (!Global.Config.NoLowResLargeScreenshotWithStates && buff.Length >= Global.Config.BigScreenshotSize) { - bs.PutLump(BinaryStateLump.Corestate, bw => core.SaveStateBinary(bw)); + outWidth /= 2; + outHeight /= 2; + } + + using (new SimpleTime("Save Framebuffer")) + { + bs.PutLump(BinaryStateLump.Framebuffer, s => QuickBmpFile.Save(Global.Emulator.AsVideoProvider(), s, outWidth, outHeight)); } } + } - if (Global.Config.SaveScreenshotWithStates && Global.Emulator.HasVideoProvider()) - { - var vp = Global.Emulator.AsVideoProvider(); - var buff = vp.GetVideoBuffer(); - if (buff.Length == 1) + if (Global.MovieSession.Movie.IsActive) + { + bs.PutLump(BinaryStateLump.Input, + delegate(TextWriter tw) { - // is a hacky opengl texture ID. can't handle this now! - // need to discuss options - // 1. cores must be able to provide a pixels videoprovider in addition to a texture ID, on command (not very hard overall but interface changing and work per core) - // 2. SavestateManager must be setup with a mechanism for resolving texture IDs (even less work, but sloppy) - // There are additional problems with AVWriting. They depend on VideoProvider providing pixels. - } - else + // this never should have been a core's responsibility + tw.WriteLine("Frame {0}", Global.Emulator.Frame); + Global.MovieSession.HandleMovieSaveState(tw); + }); + } + + if (Global.UserBag.Any()) + { + bs.PutLump(BinaryStateLump.UserData, + delegate(TextWriter tw) { - int out_w = vp.BufferWidth; - int out_h = vp.BufferHeight; + var data = ConfigService.SaveWithType(Global.UserBag); + tw.WriteLine(data); + }); + } - // if buffer is too big, scale down screenshot - if (!Global.Config.NoLowResLargeScreenshotWithStates && buff.Length >= Global.Config.BigScreenshotSize) - { - out_w /= 2; - out_h /= 2; - } - - using (new SimpleTime("Save Framebuffer")) - { - bs.PutLump(BinaryStateLump.Framebuffer, s => QuickBmpFile.Save(Global.Emulator.AsVideoProvider(), s, out_w, out_h)); - } - } - } - - if (Global.MovieSession.Movie.IsActive) - { - bs.PutLump(BinaryStateLump.Input, - delegate(TextWriter tw) - { - // this never should have been a core's responsibility - tw.WriteLine("Frame {0}", Global.Emulator.Frame); - Global.MovieSession.HandleMovieSaveState(tw); - }); - } - - if (Global.UserBag.Any()) - { - bs.PutLump(BinaryStateLump.UserData, - delegate(TextWriter tw) - { - var data = ConfigService.SaveWithType(Global.UserBag); - tw.WriteLine(data); - }); - } - - if (Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie is TasMovie) - { - bs.PutLump(BinaryStateLump.LagLog, - delegate(TextWriter tw) - { - (Global.MovieSession.Movie as TasMovie).TasLagLog.Save(tw); - }); - } + if (Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie is TasMovie) + { + bs.PutLump(BinaryStateLump.LagLog, + delegate(TextWriter tw) + { + ((TasMovie)Global.MovieSession.Movie).TasLagLog.Save(tw); + }); } } @@ -130,17 +127,6 @@ namespace BizHawk.Client.Common } } - public static void PopulateFramebuffer(byte[] bytes) - { - using (var ms = new MemoryStream(bytes)) - { - using (var br = new BinaryReader(ms)) - { - PopulateFramebuffer(br); - } - } - } - public static bool LoadStateFile(string path, string name) { var core = Global.Emulator.AsStatable(); @@ -208,10 +194,8 @@ namespace BizHawk.Client.Common return true; } - else - { - return false; - } + + return false; } } } diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index c0cc233d6e..ea24c43fad 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -14,13 +14,6 @@ namespace BizHawk.Client.Common public class MovieSession : IMovieSession { - public MovieSession() - { - ReadOnly = true; - MovieControllerAdapter = MovieService.DefaultInstance.LogGeneratorInstance().MovieControllerAdapter; - MultiTrack = new MultitrackRecorder(); - } - /// /// Gets the queued movie /// When initializing a movie, it will be stored here until Rom processes have been completed, then it will be moved to the Movie property @@ -31,11 +24,11 @@ namespace BizHawk.Client.Common // This wrapper but the logic could change, don't make the client code understand these details public bool MovieIsQueued => QueuedMovie != null; - public MultitrackRecorder MultiTrack { get; } - public IMovieController MovieControllerAdapter { get; set; } + public MultitrackRecorder MultiTrack { get; } = new MultitrackRecorder(); + public IMovieController MovieControllerAdapter { get; set; } = MovieService.DefaultInstance.LogGeneratorInstance().MovieControllerAdapter; public IMovie Movie { get; set; } - public bool ReadOnly { get; set; } + public bool ReadOnly { get; set; } = true; public Action MessageCallback { get; set; } public Func AskYesNoCallback { get; set; } @@ -308,10 +301,10 @@ namespace BizHawk.Client.Common public void HandleMovieAfterFrameLoop() { - if (Movie is TasMovie) + if (Movie is TasMovie tasMovie) { - (Movie as TasMovie).GreenzoneCurrentFrame(); - if (Movie.IsPlaying && Global.Emulator.Frame >= Movie.InputLogLength) + tasMovie.GreenzoneCurrentFrame(); + if (tasMovie.IsPlaying && Global.Emulator.Frame >= tasMovie.InputLogLength) { HandleFrameLoopForRecordMode(); } @@ -375,8 +368,7 @@ namespace BizHawk.Client.Common if (ReadOnly) { - string errorMsg; - var result = Movie.CheckTimeLines(reader, out errorMsg); + var result = Movie.CheckTimeLines(reader, out var errorMsg); if (!result) { Output(errorMsg); diff --git a/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/BizHawk.Client.EmuHawk/MainForm.Movie.cs index 36fbffa3fc..5056fa011b 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -10,11 +10,6 @@ namespace BizHawk.Client.EmuHawk { partial class MainForm { - public void StartNewMovie(string path, bool record) - { - StartNewMovie(MovieService.Get(Global.Config.RecentMovies.MostRecent), false); - } - public bool StartNewMovie(IMovie movie, bool record) { // SuuperW: Check changes. adelikat: this could break bk2 movies @@ -30,7 +25,7 @@ namespace BizHawk.Client.EmuHawk } catch (MoviePlatformMismatchException ex) { - using var ownerForm = new Form() { TopMost = true }; + using var ownerForm = new Form { TopMost = true }; MessageBox.Show(ownerForm, ex.Message, "Movie/Platform Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs index 68f3902d5a..db47709695 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs @@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk private void StateHistorySettings_Load(object sender, EventArgs e) { - _stateSizeMb = Statable.SaveStateBinary().Length / (decimal)1024 / (decimal)1024; + _stateSizeMb = Statable.SaveStateBinary().Length / (decimal)1024 / 1024; MemCapacityNumeric.Maximum = 1024 * 8; MemCapacityNumeric.Minimum = _stateSizeMb + 1; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs index 20473abe85..83c55fcfea 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs @@ -157,10 +157,10 @@ namespace BizHawk.Client.EmuHawk { if (MarkerView.AnyRowsSelected) { - while (MarkerView.SelectedRows.Last() > Markers.Count() - 1) + while (MarkerView.SelectedRows.Last() > Markers.Count - 1) { - MarkerView.SelectRow(Markers.Count(), false); - MarkerView.SelectRow(Markers.Count() - 1, true); + MarkerView.SelectRow(Markers.Count, false); + MarkerView.SelectRow(Markers.Count - 1, true); } } @@ -196,11 +196,11 @@ namespace BizHawk.Client.EmuHawk } else { - Markers.Add(new TasMovieMarker(markerFrame, "")); + Markers.Add(new TasMovieMarker(markerFrame)); UpdateValues(); } - MarkerView.ScrollToIndex(Markers.Count() - 1); + MarkerView.ScrollToIndex(Markers.Count - 1); Tastudio.RefreshDialog(); } @@ -272,11 +272,6 @@ namespace BizHawk.Client.EmuHawk } } - private void MarkerView_ItemActivate(object sender, EventArgs e) - { - Tastudio.GoToMarker(SelectedMarkers.First()); - } - // SuuperW: Marker renaming can be done with a right-click. // A much more useful feature would be to easily jump to it. private void MarkerView_MouseDoubleClick(object sender, MouseEventArgs e) diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs index 3391571b85..fba4cb4287 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/PlaybackBox.cs @@ -16,56 +16,31 @@ namespace BizHawk.Client.EmuHawk [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool TurboSeek { - get - { - return Global.Config.TurboSeek; - } - - set - { - TurboSeekCheckbox.Checked = value; - } + get => Global.Config.TurboSeek; + set => TurboSeekCheckbox.Checked = value; } [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool AutoRestore { - get - { - return Tastudio.Settings.AutoRestoreLastPosition; - } - - set - { - AutoRestoreCheckbox.Checked = value; - } + get => Tastudio.Settings.AutoRestoreLastPosition; + set => AutoRestoreCheckbox.Checked = value; } [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool FollowCursor { - get - { - return Tastudio.Settings.FollowCursor; - } - - set - { - FollowCursorCheckbox.Checked = value; - } + get => Tastudio.Settings.FollowCursor; + set => FollowCursorCheckbox.Checked = value; } [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool RecordingMode { - get - { - return Global.MovieSession.Movie.IsRecording; - } - + get => Global.MovieSession.Movie.IsRecording; set { RecordingModeCheckbox.Checked = value; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotForm.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotForm.cs index 3c765cb845..ce8fc52cca 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotForm.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/ScreenshotForm.cs @@ -4,9 +4,9 @@ using System.Windows.Forms; using BizHawk.Client.Common; // We pretend it's a tooltip kind of thing, so show only the actual contents -// and avoid stealing forcus, while still being topmost +// and avoid stealing focus, while still being topmost // http://stackoverflow.com/a/25219399/2792852 -// This is not an actual tooltip, because they can't reliably fade in and out with trasparency +// This is not an actual tooltip, because they can't reliably fade in and out with transparency namespace BizHawk.Client.EmuHawk { public partial class ScreenshotForm : Form @@ -22,9 +22,9 @@ namespace BizHawk.Client.EmuHawk private TasBranch _branch; private int _drawingHeight; - new public Font Font; - new public int Padding; - new public string Text; + public new Font Font; + public new int Padding; + public new string Text; public ScreenshotForm() { diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 41e7eca770..45db384e22 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -232,6 +232,7 @@ True True True + True True True True @@ -259,6 +260,7 @@ True True True + True True True True @@ -274,6 +276,7 @@ True True True + True True True True