Skip to content

Commit

Permalink
Remove the requirement for marking GDTaskPlayerLoopAutoload as autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
Delsin-Yu committed Oct 17, 2023
1 parent 69678b2 commit 427448d
Showing 3 changed files with 26 additions and 24 deletions.
31 changes: 26 additions & 5 deletions addons/GDTask/Autoload/GDTaskPlayerLoopAutoload.cs
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 0 additions & 15 deletions addons/GDTask/CompilerServices/AsyncMethodBuilderAttribute.cs

This file was deleted.

4 changes: 0 additions & 4 deletions project.godot
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 427448d

Please sign in to comment.