From da72229c9b3bb7c6da62c8e3276ca09c11e2540f Mon Sep 17 00:00:00 2001 From: DE-YU Date: Wed, 10 Jan 2024 18:00:40 +0800 Subject: [PATCH] Fix incorrect timing when calling Delay with PhysicsProcess --- addons/GDTask/GDTask.Delay.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/GDTask/GDTask.Delay.cs b/addons/GDTask/GDTask.Delay.cs index 74eb6ad..35e4fd5 100644 --- a/addons/GDTask/GDTask.Delay.cs +++ b/addons/GDTask/GDTask.Delay.cs @@ -486,6 +486,7 @@ static DelayPromise() ulong initialFrame; double delayTimeSpan; double elapsed; + PlayerLoopTiming timing; CancellationToken cancellationToken; GDTaskCompletionSourceCore core; @@ -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(); @@ -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);