Skip to content

Commit

Permalink
Merge pull request #4 from Delsin-Yu/4.x
Browse files Browse the repository at this point in the history
Remove the requirement for marking GDTaskPlayerLoopAutoload as autoload
  • Loading branch information
Atlinx authored Dec 4, 2023
2 parents 69678b2 + 427448d commit 865f087
Show file tree
Hide file tree
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
Expand Up @@ -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),
Expand All @@ -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)
Expand Down
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
Expand Up @@ -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"
Expand Down

0 comments on commit 865f087

Please sign in to comment.