Skip to content

Commit

Permalink
fixed frame advancing on both update and fixed update
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Aug 2, 2023
1 parent ea0a6b1 commit 401ce80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 12 additions & 1 deletion UniTAS/Patcher/Implementations/FrameAdvancing/FrameAdvancing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void UpdateUnconditional()
_fixedUpdateIndex = 0;
}

// check if update offset is valid after the last fixed update
if (_pendingUpdateOffsetFixState == PendingUpdateOffsetFixState.PendingCheckUpdateOffset)
{
var actualOffset = _pendingUpdateOffsetFixStateCheckingOffset + _timeEnv.FrameTime;
Expand All @@ -102,9 +103,16 @@ public void UpdateUnconditional()
$"invalid offset after FixedUpdate, expected {actualOffset}, current: {UpdateInvokeOffset.Offset}, fixing");
_syncFixedUpdate.OnSync(_updateOffsetSyncFix, actualOffset);
// pause until offset is synced
// this also presents this broken Update
// this also prevents this broken Update
_monoBehaviourController.PausedExecution = true;
_pendingUpdateOffsetFixState = PendingUpdateOffsetFixState.PendingSync;

// also _pendingPauseFrames needs to be decrease
if (_pendingPauseFrames > 0)
{
_pendingPauseFrames--;
}

return;
}

Expand Down Expand Up @@ -158,6 +166,9 @@ private void FrameAdvanceUpdate(bool update)

CheckAndAddPendingFrameAdvances();

// do we have new frame advance to do? don't bother pausing then
if (_pendingPauseFrames != 0) return;

_coroutine.Start(Pause(update));
}

Expand Down
2 changes: 0 additions & 2 deletions UniTAS/Patcher/Implementations/VirtualEnvironment/TimeEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using UniTAS.Patcher.Services;
using UniTAS.Patcher.Services.UnitySafeWrappers.Wrappers;
using UniTAS.Patcher.Services.VirtualEnvironment;
using UniTAS.Patcher.Utils;
using UnityEngine;

namespace UniTAS.Patcher.Implementations.VirtualEnvironment;
Expand Down Expand Up @@ -81,7 +80,6 @@ public void PreUpdateActual()

public void OnLastUpdateActual()
{
StaticLogger.Log.LogDebug($"Adding ft {FrameTime}");
RealtimeSinceStartup += FrameTime;
UnscaledTime += FrameTime;
// TODO test if this works accurately vs before
Expand Down

0 comments on commit 401ce80

Please sign in to comment.