Skip to content

Commit

Permalink
fixed not pausing instantly on initial pause
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Aug 27, 2023
1 parent 8141361 commit 6af6cf1
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions UniTAS/Patcher/Implementations/FrameAdvancing/FrameAdvancing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public void TogglePause()

public void UpdateUnconditional()
{
if (!_monoBehaviourController.PausedExecution && !_monoBehaviourController.PausedUpdate)
{
_fixedUpdateIndex = 0;
}
// if (!_monoBehaviourController.PausedExecution && !_monoBehaviourController.PausedUpdate)
// {
_fixedUpdateIndex = 0;
// }

// check if update offset is valid after the last fixed update
if (_pendingUpdateOffsetFixState == PendingUpdateOffsetFixState.PendingCheckUpdateOffset)
Expand Down Expand Up @@ -124,10 +124,10 @@ public void UpdateUnconditional()

public void FixedUpdateUnconditional()
{
if (!_monoBehaviourController.PausedExecution)
{
_fixedUpdateIndex++;
}
// if (!_monoBehaviourController.PausedExecution)
// {
_fixedUpdateIndex++;
// }

FrameAdvanceUpdate(false);
}
Expand Down Expand Up @@ -203,15 +203,27 @@ private IEnumerable<CoroutineWait> Pause(bool update)
if (_paused || _pendingPause) yield break;
_pendingPause = true;

// pause at right timing, basically let the game run until reached requirement timing of pause depending on user choice
if ((update && (_frameAdvanceMode & FrameAdvanceMode.Update) == 0) ||
(!update && (_frameAdvanceMode & FrameAdvanceMode.FixedUpdate) != 0))
// if not initial pause
if (_paused)
{
yield return new WaitForFixedUpdateUnconditional();
// pause at right timing, basically let the game run until reached requirement timing of pause depending on user choice
// we run FixedUpdate if mode only includes FixedUpdate
// or if mode has FixedUpdate along with other mode and currently is not update
if (_frameAdvanceMode == FrameAdvanceMode.FixedUpdate ||
(!update && (_frameAdvanceMode & FrameAdvanceMode.FixedUpdate) != 0))
{
_logger.LogDebug("Pausing frame advance on FixedUpdate");
yield return new WaitForFixedUpdateUnconditional();
}
else
{
_logger.LogDebug("Pausing frame advance on Update");
yield return new WaitForUpdateUnconditional();
}
}
else
{
yield return new WaitForUpdateUnconditional();
_logger.LogDebug("Initial frame advance pause");
}

_updateRestoreOffset = UpdateInvokeOffset.Offset;
Expand Down

0 comments on commit 6af6cf1

Please sign in to comment.