diff --git a/addons/GDTask/Autoload/GDTaskPlayerLoopAutoload.cs b/addons/GDTask/Autoload/GDTaskPlayerLoopAutoload.cs index 289308c..9bd83af 100644 --- a/addons/GDTask/Autoload/GDTaskPlayerLoopAutoload.cs +++ b/addons/GDTask/Autoload/GDTaskPlayerLoopAutoload.cs @@ -80,23 +80,44 @@ public void LocalAddContinuation(PlayerLoopTiming timing, Action continuation) q.Enqueue(continuation); } - public static GDTaskPlayerLoopAutoload Global { get; private set; } + public static GDTaskPlayerLoopAutoload Global + { + get + { + if (s_Global != null) return s_Global; + + var newInstance = new GDTaskPlayerLoopAutoload(); + newInstance.Initialize(); + var currentScene = ((SceneTree)Engine.GetMainLoop()).CurrentScene; + currentScene.AddChild(newInstance); + currentScene.MoveChild(newInstance, 0); + newInstance.Name = "GDTaskPlayerLoopAutoload"; + s_Global = newInstance; + + return s_Global; + } + } public double DeltaTime => GetProcessDeltaTime(); public double PhysicsDeltaTime => GetPhysicsProcessDeltaTime(); + private static GDTaskPlayerLoopAutoload s_Global; private int mainThreadId; private ContinuationQueue[] yielders; private PlayerLoopRunner[] runners; public override void _Ready() { - if (Global != null) + if (s_Global == null) { - QueueFree(); + Initialize(); + s_Global = this; return; } - Global = this; + QueueFree(); + } + private void Initialize() + { mainThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; yielders = new[] { new ContinuationQueue(PlayerLoopTiming.Process), @@ -113,7 +134,7 @@ public override void _Notification(int what) if (what == NotificationPredelete) { if (Global == this) - Global = null; + s_Global = null; if (yielders != null) { foreach (var yielder in yielders) diff --git a/addons/GDTask/CompilerServices/AsyncMethodBuilderAttribute.cs b/addons/GDTask/CompilerServices/AsyncMethodBuilderAttribute.cs deleted file mode 100644 index 8d3906d..0000000 --- a/addons/GDTask/CompilerServices/AsyncMethodBuilderAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable CS0436 - -namespace System.Runtime.CompilerServices -{ - internal sealed class AsyncMethodBuilderAttribute : Attribute - { - public Type BuilderType { get; } - - public AsyncMethodBuilderAttribute(Type builderType) - { - BuilderType = builderType; - } - } -} diff --git a/project.godot b/project.godot index a050174..2a69b95 100644 --- a/project.godot +++ b/project.godot @@ -29,10 +29,6 @@ boot_splash/bg_color=Color(0, 0, 0, 1) boot_splash/image="res://bootsplash.png" config/icon="res://icon.png" -[autoload] - -GdTaskPlayerLoopAutoload="*res://addons/GDTask/Autoload/GDTaskPlayerLoopAutoload.cs" - [dotnet] project/assembly_name="GDTask"