Skip to content

Commit

Permalink
Merge pull request #8 from Delsin-Yu/4.x
Browse files Browse the repository at this point in the history
Fix incorrect timing when calling Delay with PhysicsProcess
  • Loading branch information
Atlinx authored Mar 26, 2024
2 parents 4bf2655 + da72229 commit 7e60152
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion addons/GDTask/GDTask.Delay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ static DelayPromise()
ulong initialFrame;
double delayTimeSpan;
double elapsed;
PlayerLoopTiming timing;
CancellationToken cancellationToken;

GDTaskCompletionSourceCore<object> core;
Expand All @@ -510,6 +511,7 @@ public static IGDTaskSource Create(TimeSpan delayTimeSpan, PlayerLoopTiming timi
result.delayTimeSpan = (float)delayTimeSpan.TotalSeconds;
result.cancellationToken = cancellationToken;
result.isMainThread = GDTaskPlayerLoopAutoload.IsMainThread;
result.timing = timing;
if (result.isMainThread)
result.initialFrame = Engine.GetProcessFrames();

Expand Down Expand Up @@ -564,7 +566,11 @@ public bool MoveNext()
}
}

elapsed += GDTaskPlayerLoopAutoload.Global.DeltaTime;
if (timing == PlayerLoopTiming.Process)
elapsed += GDTaskPlayerLoopAutoload.Global.DeltaTime;
else
elapsed += GDTaskPlayerLoopAutoload.Global.PhysicsDeltaTime;

if (elapsed >= delayTimeSpan)
{
core.TrySetResult(null);
Expand Down

0 comments on commit 7e60152

Please sign in to comment.