Skip to content

Commit

Permalink
fixed merged coroutine waits to report false information about fixed …
Browse files Browse the repository at this point in the history
…update end timing
  • Loading branch information
Eddio0141 committed Aug 27, 2024
1 parent efd1c60 commit b64f09c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions UniTAS/Patcher/MonoBehaviourScripts/MonoBehaviourUpdateInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ private void Awake()

_monoBehEventInvoker.InvokeAwake();

StartCoroutine(WhileCoroutine());
StartCoroutine(EndOfFrameCoroutine());
StartCoroutine(FixedUpdateCoroutine());
}

private void OnDestroy()
Expand Down Expand Up @@ -60,25 +61,33 @@ private void OnEnable()
_monoBehEventInvoker.InvokeOnEnable();
}

private void OnApplicationFocus(bool hasFocus)
{
_logger.LogDebug($"game in focus = {hasFocus}");
_gameInfo.IsFocused = hasFocus;
}

// stupid optimization since object alloc
private readonly WaitForEndOfFrame _waitForEndOfFrame = new();
private readonly WaitForFixedUpdate _waitForFixedUpdate = new();

private IEnumerator WhileCoroutine()
private IEnumerator EndOfFrameCoroutine()
{
while (true)
{
yield return _waitForFixedUpdate;
_monoBehEventInvoker.CoroutineFixedUpdate();
yield return _waitForEndOfFrame;
_monoBehEventInvoker.InvokeLastUpdate();
}
// ReSharper disable once IteratorNeverReturns
}

private void OnApplicationFocus(bool hasFocus)
private IEnumerator FixedUpdateCoroutine()
{
_logger.LogDebug($"game in focus = {hasFocus}");
_gameInfo.IsFocused = hasFocus;
while (true)
{
yield return _waitForFixedUpdate;
_monoBehEventInvoker.CoroutineFixedUpdate();
}
// ReSharper disable once IteratorNeverReturns
}
}

0 comments on commit b64f09c

Please sign in to comment.