Use more movie mode extension methods, make MovieSession null until a movie is loaded

This commit is contained in:
adelikat 2020-05-23 13:35:10 -05:00
parent d0d526f746
commit 54de7ad178
8 changed files with 36 additions and 47 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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();

View File

@ -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);

View File

@ -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";

View File

@ -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);
}
});
}

View File

@ -62,7 +62,7 @@ namespace BizHawk.Client.EmuHawk
public void ToggleReadOnly()
{
if (CurrentTasMovie.IsPlaying())
if (CurrentTasMovie.IsPlayingOrFinished())
{
TastudioRecordMode();
}

View File

@ -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;
}