Skip to content

Commit

Permalink
Script conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
daihaminkey committed Mar 24, 2023
1 parent c283f12 commit d8ff140
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions addons/GDTask/AsyncLazy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Fractural.Tasks
{
public class AsyncLazy
public partial class AsyncLazy
{
static Action<object> continuation = SetCompletionSource;

Expand Down Expand Up @@ -122,7 +122,7 @@ static void SetCompletionSource(object state)
}
}

public class AsyncLazy<T>
public partial class AsyncLazy<T>
{
static Action<object> continuation = SetCompletionSource;

Expand Down
10 changes: 5 additions & 5 deletions addons/GDTask/Autoload/GDTaskPlayerLoopAutoload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface IPlayerLoopItem
/// <summary>
/// Singleton that forwards Godot calls and values to GDTasks.
/// </summary>
public class GDTaskPlayerLoopAutoload : Node
public partial class GDTaskPlayerLoopAutoload : Node
{
public static int MainThreadId => Global.mainThreadId;
public static bool IsMainThread => System.Threading.Thread.CurrentThread.ManagedThreadId == Global.mainThreadId;
Expand Down Expand Up @@ -81,8 +81,8 @@ public void LocalAddContinuation(PlayerLoopTiming timing, Action continuation)
}

public static GDTaskPlayerLoopAutoload Global { get; private set; }
public float DeltaTime => GetProcessDeltaTime();
public float PhysicsDeltaTime => GetPhysicsProcessDeltaTime();
public double DeltaTime => GetProcessDeltaTime();
public double PhysicsDeltaTime => GetPhysicsProcessDeltaTime();

private int mainThreadId;
private ContinuationQueue[] yielders;
Expand Down Expand Up @@ -124,13 +124,13 @@ public override void _Notification(int what)
}
}

public override void _Process(float delta)
public override void _Process(double delta)
{
yielders[(int) PlayerLoopTiming.Process].Run();
runners[(int) PlayerLoopTiming.Process].Run();
}

public override void _PhysicsProcess(float delta)
public override void _PhysicsProcess(double delta)
{
yielders[(int) PlayerLoopTiming.PhysicsProcess].Run();
runners[(int) PlayerLoopTiming.PhysicsProcess].Run();
Expand Down
4 changes: 2 additions & 2 deletions addons/GDTask/CancellationTokenEqualityComparer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading;

namespace Fractural.Tasks
{
public class CancellationTokenEqualityComparer : IEqualityComparer<CancellationToken>
public partial class CancellationTokenEqualityComparer : IEqualityComparer<CancellationToken>
{
public static readonly IEqualityComparer<CancellationToken> Default = new CancellationTokenEqualityComparer();

Expand Down
8 changes: 4 additions & 4 deletions addons/GDTask/GDTask.Delay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static GDTask WaitForPhysicsProcess(CancellationToken cancellationToken)

#if DEBUG
// force use Realtime.
if (GDTaskPlayerLoopAutoload.IsMainThread && Engine.EditorHint)
if (GDTaskPlayerLoopAutoload.IsMainThread && Engine.IsEditorHint())
{
delayType = DelayType.Realtime;
}
Expand Down Expand Up @@ -431,7 +431,7 @@ public bool MoveNext()
{
#if DEBUG
// force use Realtime.
if (GDTaskPlayerLoopAutoload.IsMainThread && Engine.EditorHint)
if (GDTaskPlayerLoopAutoload.IsMainThread && Engine.IsEditorHint())
{
//goto ++currentFrameCount
}
Expand Down Expand Up @@ -477,8 +477,8 @@ static DelayPromise()
}

int initialFrame;
float delayTimeSpan;
float elapsed;
double delayTimeSpan;
double elapsed;
CancellationToken cancellationToken;

GDTaskCompletionSourceCore<object> core;
Expand Down
6 changes: 3 additions & 3 deletions addons/GDTask/GDTask.WaitUntil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static GDTask WaitUntilCanceled(CancellationToken cancellationToken, Play
public static GDTask<U> WaitUntilValueChanged<T, U>(T target, Func<T, U> monitorFunction, PlayerLoopTiming monitorTiming = PlayerLoopTiming.Process, IEqualityComparer<U> equalityComparer = null, CancellationToken cancellationToken = default(CancellationToken))
where T : class
{
var isGodotObject = target is Godot.Object; // don't use (unityObject == null)
var isGodotObject = target is Godot.GodotObject; // don't use (unityObject == null)

return new GDTask<U>(isGodotObject
? WaitUntilValueChangedGodotObjectPromise<T, U>.Create(target, monitorFunction, equalityComparer, monitorTiming, cancellationToken, out var token)
Expand Down Expand Up @@ -343,7 +343,7 @@ static WaitUntilValueChangedGodotObjectPromise()
}

T target;
Godot.Object targetAsGodotObject;
Godot.GodotObject targetAsGodotObject;
U currentValue;
Func<T, U> monitorFunction;
IEqualityComparer<U> equalityComparer;
Expand All @@ -368,7 +368,7 @@ public static IGDTaskSource<U> Create(T target, Func<T, U> monitorFunction, IEqu
}

result.target = target;
result.targetAsGodotObject = target as Godot.Object;
result.targetAsGodotObject = target as Godot.GodotObject;
result.monitorFunction = monitorFunction;
result.currentValue = monitorFunction(target);
result.equalityComparer = equalityComparer ?? GodotEqualityComparer.GetDefault<U>();
Expand Down
10 changes: 5 additions & 5 deletions addons/GDTask/GDTaskCompletionSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -314,7 +314,7 @@ private static void CompletionSentinel(object _) // named method to aid debuggin
}
}

public class AutoResetGDTaskCompletionSource : IGDTaskSource, ITaskPoolNode<AutoResetGDTaskCompletionSource>, IPromise
public partial class AutoResetGDTaskCompletionSource : IGDTaskSource, ITaskPoolNode<AutoResetGDTaskCompletionSource>, IPromise
{
static TaskPool<AutoResetGDTaskCompletionSource> pool;
AutoResetGDTaskCompletionSource nextNode;
Expand Down Expand Up @@ -437,7 +437,7 @@ bool TryReturn()
}
}

public class AutoResetGDTaskCompletionSource<T> : IGDTaskSource<T>, ITaskPoolNode<AutoResetGDTaskCompletionSource<T>>, IPromise<T>
public partial class AutoResetGDTaskCompletionSource<T> : IGDTaskSource<T>, ITaskPoolNode<AutoResetGDTaskCompletionSource<T>>, IPromise<T>
{
static TaskPool<AutoResetGDTaskCompletionSource<T>> pool;
AutoResetGDTaskCompletionSource<T> nextNode;
Expand Down Expand Up @@ -565,7 +565,7 @@ bool TryReturn()
}
}

public class GDTaskCompletionSource : IGDTaskSource, IPromise
public partial class GDTaskCompletionSource : IGDTaskSource, IPromise
{
CancellationToken cancellationToken;
ExceptionHolder exception;
Expand Down Expand Up @@ -746,7 +746,7 @@ bool TrySignalCompletion(GDTaskStatus status)
}
}

public class GDTaskCompletionSource<T> : IGDTaskSource<T>, IPromise<T>
public partial class GDTaskCompletionSource<T> : IGDTaskSource<T>, IPromise<T>
{
CancellationToken cancellationToken;
T result;
Expand Down
4 changes: 2 additions & 2 deletions addons/GDTask/GDTaskSynchronizationContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Godot;
using Godot;
using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace Fractural.Tasks
{
public class GDTaskSynchronizationContext : SynchronizationContext
public partial class GDTaskSynchronizationContext : SynchronizationContext
{
const int MaxArrayLength = 0X7FEFFFFF;
const int InitialSize = 16;
Expand Down
38 changes: 19 additions & 19 deletions addons/GDTask/Internal/GodotEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ internal static class GodotEqualityComparer
public static readonly IEqualityComparer<Vector3> Vector3 = new Vector3EqualityComparer();
public static readonly IEqualityComparer<Color> Color = new ColorEqualityComparer();
public static readonly IEqualityComparer<Rect2> Rect2 = new Rect2EqualityComparer();
public static readonly IEqualityComparer<AABB> AABB = new AABBEqualityComparer();
public static readonly IEqualityComparer<Quat> Quat = new QuatEqualityComparer();
public static readonly IEqualityComparer<Aabb> AABB = new AABBEqualityComparer();
public static readonly IEqualityComparer<Quaternion> Quaternion = new QuatEqualityComparer();

static readonly RuntimeTypeHandle vector2Type = typeof(Vector2).TypeHandle;
static readonly RuntimeTypeHandle vector3Type = typeof(Vector3).TypeHandle;
static readonly RuntimeTypeHandle colorType = typeof(Color).TypeHandle;
static readonly RuntimeTypeHandle rectType = typeof(Rect2).TypeHandle;
static readonly RuntimeTypeHandle AABBType = typeof(AABB).TypeHandle;
static readonly RuntimeTypeHandle quaternionType = typeof(Quat).TypeHandle;
static readonly RuntimeTypeHandle AABBType = typeof(Aabb).TypeHandle;
static readonly RuntimeTypeHandle quaternionType = typeof(Quaternion).TypeHandle;

static class Cache<T>
{
Expand Down Expand Up @@ -52,7 +52,7 @@ static object GetDefaultHelper(Type type)
if (t.Equals(colorType)) return (object)GodotEqualityComparer.Color;
if (t.Equals(rectType)) return (object)GodotEqualityComparer.Rect2;
if (t.Equals(AABBType)) return (object)GodotEqualityComparer.AABB;
if (t.Equals(quaternionType)) return (object)GodotEqualityComparer.Quat;
if (t.Equals(quaternionType)) return (object)GodotEqualityComparer.Quaternion;

return null;
}
Expand All @@ -61,38 +61,38 @@ sealed class Vector2EqualityComparer : IEqualityComparer<Vector2>
{
public bool Equals(Vector2 self, Vector2 vector)
{
return self.x.Equals(vector.x) && self.y.Equals(vector.y);
return self.X.Equals(vector.X) && self.Y.Equals(vector.Y);
}

public int GetHashCode(Vector2 obj)
{
return obj.x.GetHashCode() ^ obj.y.GetHashCode() << 2;
return obj.X.GetHashCode() ^ obj.Y.GetHashCode() << 2;
}
}

sealed class Vector3EqualityComparer : IEqualityComparer<Vector3>
{
public bool Equals(Vector3 self, Vector3 vector)
{
return self.x.Equals(vector.x) && self.y.Equals(vector.y) && self.z.Equals(vector.z);
return self.X.Equals(vector.X) && self.Y.Equals(vector.Y) && self.Z.Equals(vector.Z);
}

public int GetHashCode(Vector3 obj)
{
return obj.x.GetHashCode() ^ obj.y.GetHashCode() << 2 ^ obj.z.GetHashCode() >> 2;
return obj.X.GetHashCode() ^ obj.Y.GetHashCode() << 2 ^ obj.Z.GetHashCode() >> 2;
}
}

sealed class ColorEqualityComparer : IEqualityComparer<Color>
{
public bool Equals(Color self, Color other)
{
return self.r.Equals(other.r) && self.g.Equals(other.g) && self.b.Equals(other.b) && self.a.Equals(other.a);
return self.R.Equals(other.R) && self.G.Equals(other.G) && self.B.Equals(other.B) && self.A.Equals(other.A);
}

public int GetHashCode(Color obj)
{
return obj.r.GetHashCode() ^ obj.g.GetHashCode() << 2 ^ obj.b.GetHashCode() >> 2 ^ obj.a.GetHashCode() >> 1;
return obj.R.GetHashCode() ^ obj.G.GetHashCode() << 2 ^ obj.B.GetHashCode() >> 2 ^ obj.A.GetHashCode() >> 1;
}
}

Expand All @@ -109,29 +109,29 @@ public int GetHashCode(Rect2 obj)
}
}

sealed class AABBEqualityComparer : IEqualityComparer<AABB>
sealed class AABBEqualityComparer : IEqualityComparer<Aabb>
{
public bool Equals(AABB self, AABB vector)
public bool Equals(Aabb self, Aabb vector)
{
return self.Position.Equals(vector.Position) && self.Size.Equals(vector.Size);
}

public int GetHashCode(AABB obj)
public int GetHashCode(Aabb obj)
{
return obj.Position.GetHashCode() ^ obj.Size.GetHashCode() << 2;
}
}

sealed class QuatEqualityComparer : IEqualityComparer<Quat>
sealed class QuatEqualityComparer : IEqualityComparer<Quaternion>
{
public bool Equals(Quat self, Quat vector)
public bool Equals(Quaternion self, Quaternion vector)
{
return self.x.Equals(vector.x) && self.y.Equals(vector.y) && self.z.Equals(vector.z) && self.w.Equals(vector.w);
return self.X.Equals(vector.X) && self.Y.Equals(vector.Y) && self.Z.Equals(vector.Z) && self.W.Equals(vector.W);
}

public int GetHashCode(Quat obj)
public int GetHashCode(Quaternion obj)
{
return obj.x.GetHashCode() ^ obj.y.GetHashCode() << 2 ^ obj.z.GetHashCode() >> 2 ^ obj.w.GetHashCode() >> 1;
return obj.X.GetHashCode() ^ obj.Y.GetHashCode() << 2 ^ obj.Z.GetHashCode() >> 2 ^ obj.W.GetHashCode() >> 1;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions addons/GDTask/Internal/RuntimeHelpersAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static bool WellKnownNoReferenceContainsTypeInitialize(Type t)
if (t == typeof(Vector3)) return true;
if (t == typeof(Color)) return true;
if (t == typeof(Rect2)) return true;
if (t == typeof(AABB)) return true;
if (t == typeof(Quat)) return true;
if (t == typeof(Aabb)) return true;
if (t == typeof(Quaternion)) return true;

return false;
}
Expand Down
10 changes: 5 additions & 5 deletions addons/GDTask/PlayerLoopTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static PlayerLoopTimer Create(TimeSpan interval, bool periodic, DelayType
{
#if DEBUG
// force use Realtime.
if (GDTaskPlayerLoopAutoload.IsMainThread && Engine.EditorHint)
if (GDTaskPlayerLoopAutoload.IsMainThread && Engine.IsEditorHint())
{
delayType = DelayType.Realtime;
}
Expand Down Expand Up @@ -143,8 +143,8 @@ bool IPlayerLoopItem.MoveNext()
sealed class DeltaTimePlayerLoopTimer : PlayerLoopTimer
{
int initialFrame;
float elapsed;
float interval;
double elapsed;
double interval;

public DeltaTimePlayerLoopTimer(TimeSpan interval, bool periodic, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action<object> timerCallback, object state)
: base(periodic, playerLoopTiming, cancellationToken, timerCallback, state)
Expand All @@ -154,7 +154,7 @@ public DeltaTimePlayerLoopTimer(TimeSpan interval, bool periodic, PlayerLoopTimi

protected override bool MoveNextCore()
{
if (elapsed == 0.0f)
if (elapsed == 0.0)
{
if (initialFrame == Engine.GetFramesDrawn())
{
Expand All @@ -173,7 +173,7 @@ protected override bool MoveNextCore()

protected override void ResetCore(TimeSpan? interval)
{
this.elapsed = 0.0f;
this.elapsed = 0.0;
this.initialFrame = GDTaskPlayerLoopAutoload.IsMainThread ? Engine.GetFramesDrawn() : -1;
if (interval != null)
{
Expand Down
2 changes: 1 addition & 1 deletion addons/GDTask/Triggers/AsyncDestroyTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static AsyncDestroyTrigger GetAsyncDestroyTrigger(this Node node)
}
}

public sealed class AsyncDestroyTrigger : Node
public sealed partial class AsyncDestroyTrigger : Node
{
bool awakeCalled = false;
bool called = false;
Expand Down
2 changes: 1 addition & 1 deletion addons/GDTask/Triggers/AsyncEnterTreeTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static AsyncEnterTreeTrigger GetAsyncAwakeTrigger(this Node node)
}
}

public sealed class AsyncEnterTreeTrigger : AsyncTriggerBase<AsyncUnit>
public sealed partial class AsyncEnterTreeTrigger : AsyncTriggerBase<AsyncUnit>
{
public GDTask AwakeAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion addons/GDTask/Triggers/AsyncReadyTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static AsyncReadyTrigger GetAsyncStartTrigger(this Node node)
}
}

public sealed class AsyncReadyTrigger : AsyncTriggerBase<AsyncUnit>
public sealed partial class AsyncReadyTrigger : AsyncTriggerBase<AsyncUnit>
{
bool called;

Expand Down
2 changes: 1 addition & 1 deletion addons/GDTask/Triggers/AsyncTriggerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Fractural.Tasks.Triggers
{
public abstract class AsyncTriggerBase<T> : Node
public abstract partial class AsyncTriggerBase<T> : Node
{
TriggerEvent<T> triggerEvent;

Expand Down
8 changes: 4 additions & 4 deletions addons/GDTask/Triggers/NodeMessagesTriggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public static AsyncPhysicsProcessTrigger GetAsyncPhysicsProcessTrigger(this Node
}
}

public sealed class AsyncPhysicsProcessTrigger : AsyncTriggerBase<AsyncUnit>
public sealed partial class AsyncPhysicsProcessTrigger : AsyncTriggerBase<AsyncUnit>
{
public override void _PhysicsProcess(float delta)
public override void _PhysicsProcess(double delta)
{
RaiseEvent(AsyncUnit.Default);
}
Expand Down Expand Up @@ -80,9 +80,9 @@ public static AsyncProcessTrigger GetAsyncProcessTrigger(this Node node)
}
}

public sealed class AsyncProcessTrigger : AsyncTriggerBase<AsyncUnit>
public sealed partial class AsyncProcessTrigger : AsyncTriggerBase<AsyncUnit>
{
public override void _Process(float delta)
public override void _Process(double delta)
{
RaiseEvent(AsyncUnit.Default);
}
Expand Down

0 comments on commit d8ff140

Please sign in to comment.