From 54de7ad178d66ecd075d25e5f3aee3b1120709a8 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 23 May 2020 13:35:10 -0500 Subject: [PATCH] Use more movie mode extension methods, make MovieSession null until a movie is loaded --- .../movie/MovieSession.cs | 18 +++++------ .../movie/interfaces/IMovie.cs | 3 +- .../DisplayManager/OSDManager.cs | 4 +-- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 14 ++++----- src/BizHawk.Client.EmuHawk/MainForm.Movie.cs | 2 +- src/BizHawk.Client.EmuHawk/MainForm.cs | 30 ++++++++----------- .../TAStudio/TAStudio.IControlMainForm.cs | 2 +- .../tools/VirtualPads/VirtualpadsTool.cs | 10 ++----- 8 files changed, 36 insertions(+), 47 deletions(-) diff --git a/src/BizHawk.Client.Common/movie/MovieSession.cs b/src/BizHawk.Client.Common/movie/MovieSession.cs index c22fcfe9ea..a1ac266c20 100644 --- a/src/BizHawk.Client.Common/movie/MovieSession.cs +++ b/src/BizHawk.Client.Common/movie/MovieSession.cs @@ -36,8 +36,6 @@ namespace BizHawk.Client.Common ?? throw new ArgumentNullException($"{nameof(pauseCallback)} cannot be null."); _modeChangedCallback = modeChangedCallback ?? throw new ArgumentNullException($"{nameof(modeChangedCallback)} CannotUnloadAppDomainException be null."); - - Movie = new Bk2Movie(); } public IMovie Movie { get; private set; } @@ -104,7 +102,7 @@ namespace BizHawk.Client.Common LatchInputToUser(); } } - else if (Movie.IsPlaying()) + else if (Movie.IsPlayingOrFinished()) { LatchInputToLog(); @@ -151,12 +149,12 @@ namespace BizHawk.Client.Common if (Movie is ITasMovie tasMovie) { tasMovie.GreenzoneCurrentFrame(); - if (tasMovie.IsPlaying() && _emulator.Frame >= tasMovie.InputLogLength) + if (tasMovie.IsPlayingOrFinished() && _emulator.Frame >= tasMovie.InputLogLength) { HandleFrameLoopForRecordMode(); } } - else if (Movie.Mode == MovieMode.Play && _emulator.Frame >= Movie.InputLogLength) + else if (Movie.IsPlaying() && _emulator.Frame >= Movie.InputLogLength) { HandlePlaybackEnd(); } @@ -198,7 +196,7 @@ namespace BizHawk.Client.Common { Movie.SwitchToPlay(); } - else if (Movie.IsPlaying()) + else if (Movie.IsPlayingOrFinished()) { LatchInputToLog(); } @@ -213,7 +211,7 @@ namespace BizHawk.Client.Common { Movie.StartNewRecording(); } - else if (Movie.IsPlaying()) + else if (Movie.IsPlayingOrFinished()) { Movie.SwitchToRecord(); } @@ -346,7 +344,7 @@ namespace BizHawk.Client.Common { message += "recording "; } - else if (Movie.IsPlaying()) + else if (Movie.IsPlayingOrFinished()) { message += "playback "; } @@ -381,7 +379,7 @@ namespace BizHawk.Client.Common private void ClearFrame() { - if (Movie.IsPlaying()) + if (Movie.IsPlayingOrFinished()) { Movie.ClearFrame(_emulator.Frame); Output($"Scrubbed input at frame {_emulator.Frame}"); @@ -486,7 +484,7 @@ namespace BizHawk.Client.Common private void HandleFrameLoopForRecordMode() { // we don't want TasMovie to latch user input outside its internal recording mode, so limit it to autohold - if (Movie is ITasMovie && Movie.IsPlaying()) + if (Movie is ITasMovie && Movie.IsPlayingOrFinished()) { MovieController.SetFromSticky(Global.InputManager.AutofireStickyXorAdapter); } diff --git a/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs b/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs index 052774fab3..2fbf3039a6 100644 --- a/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs +++ b/src/BizHawk.Client.Common/movie/interfaces/IMovie.cs @@ -230,9 +230,10 @@ namespace BizHawk.Client.Common { public static bool IsActive(this IMovie movie) => movie != null && movie.Mode != MovieMode.Inactive; public static bool NotActive(this IMovie movie) => movie == null || movie.Mode == MovieMode.Inactive; - public static bool IsPlaying(this IMovie movie) => movie?.Mode == MovieMode.Play || movie?.Mode == MovieMode.Finished; + public static bool IsPlaying(this IMovie movie) => movie?.Mode == MovieMode.Play; public static bool IsRecording(this IMovie movie) => movie?.Mode == MovieMode.Record; public static bool IsFinished(this IMovie movie) => movie?.Mode == MovieMode.Finished; + public static bool IsPlayingOrFinished(this IMovie movie) => movie?.Mode == MovieMode.Play || movie?.Mode == MovieMode.Finished; public static bool IsPlayingOrRecording(this IMovie movie) => movie?.Mode == MovieMode.Play || movie?.Mode == MovieMode.Record; diff --git a/src/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs b/src/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs index 314071cd3b..6bbb480e15 100644 --- a/src/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs +++ b/src/BizHawk.Client.EmuHawk/DisplayManager/OSDManager.cs @@ -78,7 +78,7 @@ namespace BizHawk.Client.EmuHawk return sb.ToString(); } - if (Global.MovieSession.Movie.IsPlaying()) + if (Global.MovieSession.Movie.IsPlayingOrFinished()) { var sb = new StringBuilder(); sb @@ -272,7 +272,7 @@ namespace BizHawk.Client.EmuHawk if (Global.Config.DisplayInput && !Global.Game.IsNullInstance()) { - if (Global.MovieSession.Movie.Mode == MovieMode.Play + if (Global.MovieSession.Movie.IsPlaying() || (Global.MovieSession.Movie.IsFinished() && Global.Emulator.Frame == Global.MovieSession.Movie.InputLogLength)) // Account for the last frame of the movie, the movie state is immediately "Finished" here but we still want to show the input { var input = InputStrMovie(); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 39aa5a7ccb..da06501180 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -688,10 +688,10 @@ namespace BizHawk.Client.EmuHawk PauseMenuItem.Checked = _didMenuPause ? _wasPaused : EmulatorPaused; SoftResetMenuItem.Enabled = Emulator.ControllerDefinition.BoolButtons.Contains("Reset") - && MovieSession.Movie.Mode != MovieMode.Play; + && !MovieSession.Movie.IsPlaying(); HardResetMenuItem.Enabled = Emulator.ControllerDefinition.BoolButtons.Contains("Power") - && MovieSession.Movie.Mode != MovieMode.Play; + && !MovieSession.Movie.IsPlaying(); PauseMenuItem.ShortcutKeyDisplayString = Config.HotkeyBindings["Pause"].Bindings; RebootCoreMenuItem.ShortcutKeyDisplayString = Config.HotkeyBindings["Reboot Core"].Bindings; @@ -1614,7 +1614,7 @@ namespace BizHawk.Client.EmuHawk private void FdsEjectDiskMenuItem_Click(object sender, EventArgs e) { - if (MovieSession.Movie.Mode != MovieMode.Play) + if (!MovieSession.Movie.IsPlaying()) { InputManager.ClickyVirtualPadController.Click("FDS Eject"); AddOnScreenMessage("FDS disk ejected."); @@ -1626,7 +1626,7 @@ namespace BizHawk.Client.EmuHawk if (Emulator is NES nes && nes.IsVS || Emulator is SubNESHawk sub && sub.IsVs) { - if (MovieSession.Movie.Mode != MovieMode.Play) + if (!MovieSession.Movie.IsPlaying()) { InputManager.ClickyVirtualPadController.Click("Insert Coin P1"); AddOnScreenMessage("P1 Coin Inserted"); @@ -1639,7 +1639,7 @@ namespace BizHawk.Client.EmuHawk if (Emulator is NES nes && nes.IsVS || Emulator is SubNESHawk sub && sub.IsVs) { - if (MovieSession.Movie.Mode != MovieMode.Play) + if (!MovieSession.Movie.IsPlaying()) { InputManager.ClickyVirtualPadController.Click("Insert Coin P2"); AddOnScreenMessage("P2 Coin Inserted"); @@ -1652,7 +1652,7 @@ namespace BizHawk.Client.EmuHawk if (Emulator is NES nes && nes.IsVS || Emulator is SubNESHawk sub && sub.IsVs) { - if (MovieSession.Movie.Mode != MovieMode.Play) + if (!MovieSession.Movie.IsPlaying()) { InputManager.ClickyVirtualPadController.Click("Service Switch"); AddOnScreenMessage("Service Switch Pressed"); @@ -2844,7 +2844,7 @@ namespace BizHawk.Client.EmuHawk private void LinkConnectStatusBarButton_Click(object sender, EventArgs e) { // toggle Link status (only outside of a movie session) - if (MovieSession.Movie.Mode != MovieMode.Play) + if (!MovieSession.Movie.IsPlaying()) { Emulator.AsLinkable().LinkConnected ^= true; Console.WriteLine("Cable connect status to {0}", Emulator.AsLinkable().LinkConnected); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs index 5785fe9a10..65980eb420 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -44,7 +44,7 @@ namespace BizHawk.Client.EmuHawk public void SetMainformMovieInfo() { - if (MovieSession.Movie.IsPlaying()) + if (MovieSession.Movie.IsPlayingOrFinished()) { PlayRecordStatusButton.Image = Properties.Resources.Play; PlayRecordStatusButton.ToolTipText = "Movie is in playback mode"; diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index c98cc6cc29..c9d14ddf55 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -2388,26 +2388,22 @@ namespace BizHawk.Client.EmuHawk private void SoftReset() { // is it enough to run this for one frame? maybe.. - if (Emulator.ControllerDefinition.BoolButtons.Contains("Reset")) + if (Emulator.ControllerDefinition.BoolButtons.Contains("Reset") + && !MovieSession.Movie.IsPlaying()) { - if (MovieSession.Movie.Mode != MovieMode.Play) - { - InputManager.ClickyVirtualPadController.Click("Reset"); - AddOnScreenMessage("Reset button pressed."); - } + InputManager.ClickyVirtualPadController.Click("Reset"); + AddOnScreenMessage("Reset button pressed."); } } private void HardReset() { // is it enough to run this for one frame? maybe.. - if (Emulator.ControllerDefinition.BoolButtons.Contains("Power")) + if (Emulator.ControllerDefinition.BoolButtons.Contains("Power") + && !MovieSession.Movie.IsPlaying()) { - if (MovieSession.Movie.Mode != MovieMode.Play) - { - InputManager.ClickyVirtualPadController.Click("Power"); - AddOnScreenMessage("Power button pressed."); - } + InputManager.ClickyVirtualPadController.Click("Power"); + AddOnScreenMessage("Power button pressed."); } } @@ -2683,13 +2679,11 @@ namespace BizHawk.Client.EmuHawk { FDSControlsMenuItem.DropDownItems.Add(name, null, delegate { - if (Emulator.ControllerDefinition.BoolButtons.Contains(button)) + if (Emulator.ControllerDefinition.BoolButtons.Contains(button) + && !MovieSession.Movie.IsPlaying()) { - if (MovieSession.Movie.Mode != MovieMode.Play) - { - InputManager.ClickyVirtualPadController.Click(button); - AddOnScreenMessage(msg); - } + InputManager.ClickyVirtualPadController.Click(button); + AddOnScreenMessage(msg); } }); } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs index af5176f571..f3e8b2a5e7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs @@ -62,7 +62,7 @@ namespace BizHawk.Client.EmuHawk public void ToggleReadOnly() { - if (CurrentTasMovie.IsPlaying()) + if (CurrentTasMovie.IsPlayingOrFinished()) { TastudioRecordMode(); } diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs index dafc7ba906..b2d650806a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualpadsTool.cs @@ -146,7 +146,7 @@ namespace BizHawk.Client.EmuHawk Pads.ForEach(p => p.SetPrevious(null)); // Not the cleanest way to clear this every frame - if (MovieSession.Movie.Mode == MovieMode.Play) + if (MovieSession.Movie.IsPlaying()) { Readonly = true; if (MovieSession.CurrentInput != null) @@ -154,13 +154,9 @@ namespace BizHawk.Client.EmuHawk Pads.ForEach(p => p.Set(MovieSession.CurrentInput)); } } - else + else if (MovieSession.Movie.IsRecording()) { - if (MovieSession.Movie.IsRecording()) - { - Pads.ForEach(p => p.SetPrevious(MovieSession.PreviousFrame)); - } - + Pads.ForEach(p => p.SetPrevious(MovieSession.PreviousFrame)); Readonly = false; }