Skip to content

Commit

Permalink
Cleanup before/after frame logic in MovieSession (#4023)
Browse files Browse the repository at this point in the history
This does change some behavior, but hopefully the new structure is more logical and more correct. Calling HandleFrameAfter from HandleFrameBefore definitely didn't feel proper.
  • Loading branch information
Morilli authored Sep 8, 2024
1 parent 09f0375 commit a72b0f7
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions src/BizHawk.Client.Common/movie/MovieSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,30 @@ public void HandleFrameBefore()
else if (Movie.IsPlaying())
{
LatchInputToLog();

if (Movie.IsRecording()) // The movie end situation can cause the switch to record mode, in that case we need to capture some input for this frame
// if we're at the movie's end and the MovieEndAction is record, just continue recording in play mode
// TODO change to TAStudio check
if (Movie is ITasMovie && Movie.Emulator.Frame == Movie.FrameCount && Settings.MovieEndAction == MovieEndAction.Record)
{
HandleFrameLoopForRecordMode();
Movie.RecordFrame(Movie.Emulator.Frame, MovieOut.Source);
}
}
else if (Movie.IsRecording())
{
HandleFrameLoopForRecordMode();
LatchInputToUser();
Movie.RecordFrame(Movie.Emulator.Frame, MovieOut.Source);
}
}

// TODO: this is a mess, simplify
public void HandleFrameAfter()
{
if (Movie is ITasMovie tasMovie)
{
tasMovie.GreenzoneCurrentFrame();
if (tasMovie.IsPlayingOrFinished() && Settings.MovieEndAction == MovieEndAction.Record && Movie.Emulator.Frame >= tasMovie.InputLogLength)
{
HandleFrameLoopForRecordMode();
return;
}
// TODO change to TAStudio check
if (Settings.MovieEndAction == MovieEndAction.Record) return;
}

if (Movie.IsPlaying() && Movie.Emulator.Frame >= Movie.InputLogLength)
if (Movie.IsPlaying() && Movie.Emulator.Frame >= Movie.FrameCount)
{
HandlePlaybackEnd();
}
Expand Down Expand Up @@ -329,13 +327,8 @@ private void LatchInputToUser()
private void LatchInputToLog()
{
var input = Movie.GetInputState(Movie.Emulator.Frame);
if (input == null)
{
HandleFrameAfter();
return;
}

MovieController.SetFrom(input);
MovieController.SetFrom(input ?? GenerateMovieController());
MovieOut.Source = MovieController;
}

Expand Down Expand Up @@ -414,20 +407,5 @@ private void HandlePlaybackEnd()

_modeChangedCallback();
}

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.IsPlayingOrFinished())
{
MovieController.SetFromSticky(StickySource);
}
else
{
MovieController.SetFrom(MovieIn);
}

Movie.RecordFrame(Movie.Emulator.Frame, MovieController);
}
}
}

0 comments on commit a72b0f7

Please sign in to comment.