Skip to content

Commit

Permalink
Remove redundant unity code
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlinx committed Feb 11, 2023
1 parent 081d20f commit e7934d1
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 283 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[submodule "addons/FracturalCommons"]
path = addons/FracturalCommons
url = https://github.com/Fractural/FracturalCommons.git
branch = release
1 change: 0 additions & 1 deletion addons/FracturalCommons
Submodule FracturalCommons deleted from ba68b1
4 changes: 2 additions & 2 deletions addons/GDTask/CompilerServices/AsyncGDTaskMethodBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void SetStateMachine(IAsyncStateMachine stateMachine)
// don't use boxed stateMachine.
}

#if DEBUG || !UNITY_2018_3_OR_NEWER
#if DEBUG
// Important for IDE debugger.
object debuggingId;
private object ObjectIdForDebugger
Expand Down Expand Up @@ -246,7 +246,7 @@ public void SetStateMachine(IAsyncStateMachine stateMachine)
// don't use boxed stateMachine.
}

#if DEBUG || !UNITY_2018_3_OR_NEWER
#if DEBUG
// Important for IDE debugger.
object debuggingId;
private object ObjectIdForDebugger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void SetStateMachine(IAsyncStateMachine stateMachine)
// don't use boxed stateMachine.
}

#if DEBUG || !UNITY_2018_3_OR_NEWER
#if DEBUG
// Important for IDE debugger.
object debuggingId;
private object ObjectIdForDebugger
Expand Down
9 changes: 0 additions & 9 deletions addons/GDTask/CompilerServices/StateMachineRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@

namespace Fractural.Tasks.CompilerServices
{
// #ENABLE_IL2CPP in this file is to avoid bug of IL2CPP VM.
// Issue is tracked on https://issuetracker.unity3d.com/issues/il2cpp-incorrect-results-when-calling-a-method-from-outside-class-in-a-struct
// but currently it is labeled `Won't Fix`.

internal interface IStateMachineRunner
{
Action MoveNext { get; }
void Return();

#if ENABLE_IL2CPP
Action ReturnAction { get; }
#endif
}

internal interface IStateMachineRunnerPromise : IGDTaskSource
Expand Down Expand Up @@ -53,9 +47,7 @@ internal sealed class AsyncGDTaskVoid<TStateMachine> : IStateMachineRunner, ITas
{
static TaskPool<AsyncGDTaskVoid<TStateMachine>> pool;

#if ENABLE_IL2CPP
public Action ReturnAction { get; }
#endif

TStateMachine stateMachine;

Expand Down Expand Up @@ -308,7 +300,6 @@ bool TryReturn()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Run()
{
// UnityEngine.Debug.Log($"MoveNext State:" + StateMachineUtility.GetState(stateMachine));
stateMachine.MoveNext();
}

Expand Down
22 changes: 0 additions & 22 deletions addons/GDTask/GDTask.Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,6 @@ public static Action Action(Func<CancellationToken, GDTaskVoid> asyncAction, Can
return () => asyncAction(cancellationToken).Forget();
}

#if UNITY_2018_3_OR_NEWER

/// <summary>
/// Create async void(GDTaskVoid) UnityAction.
/// For exampe: onClick.AddListener(GDTask.UnityAction(async () => { /* */ } ))
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<GDTaskVoid> asyncAction)
{
return () => asyncAction().Forget();
}

/// <summary>
/// Create async void(GDTaskVoid) UnityAction.
/// For exampe: onClick.AddListener(GDTask.UnityAction(FooAsync, this.GetCancellationTokenOnDestroy()))
/// </summary>
public static UnityEngine.Events.UnityAction UnityAction(Func<CancellationToken, GDTaskVoid> asyncAction, CancellationToken cancellationToken)
{
return () => asyncAction(cancellationToken).Forget();
}

#endif

/// <summary>
/// Defer the task creation just before call await.
/// </summary>
Expand Down
71 changes: 10 additions & 61 deletions addons/GDTask/GDTask.Threading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ namespace Fractural.Tasks
{
public partial struct GDTask
{
#if UNITY_2018_3_OR_NEWER

/// <summary>
/// If running on mainthread, do nothing. Otherwise, same as GDTask.Yield(PlayerLoopTiming.Update).
/// </summary>
public static SwitchToMainThreadAwaitable SwitchToMainThread(CancellationToken cancellationToken = default)
{
return new SwitchToMainThreadAwaitable(PlayerLoopTiming.Update, cancellationToken);
return new SwitchToMainThreadAwaitable(PlayerLoopTiming.Process, cancellationToken);
}

/// <summary>
Expand All @@ -31,7 +30,7 @@ public static SwitchToMainThreadAwaitable SwitchToMainThread(PlayerLoopTiming ti
/// </summary>
public static ReturnToMainThread ReturnToMainThread(CancellationToken cancellationToken = default)
{
return new ReturnToMainThread(PlayerLoopTiming.Update, cancellationToken);
return new ReturnToMainThread(PlayerLoopTiming.Process, cancellationToken);
}

/// <summary>
Expand All @@ -45,12 +44,11 @@ public static ReturnToMainThread ReturnToMainThread(PlayerLoopTiming timing, Can
/// <summary>
/// Queue the action to PlayerLoop.
/// </summary>
public static void Post(Action action, PlayerLoopTiming timing = PlayerLoopTiming.Update)
public static void Post(Action action, PlayerLoopTiming timing = PlayerLoopTiming.Process)
{
PlayerLoopHelper.AddContinuation(timing, action);
GDTaskPlayerLoopAutoload.AddContinuation(timing, action);
}

#endif

public static SwitchToThreadPoolAwaitable SwitchToThreadPool()
{
Expand Down Expand Up @@ -82,8 +80,6 @@ public static ReturnToSynchronizationContext ReturnToCurrentSynchronizationConte
}
}

#if UNITY_2018_3_OR_NEWER

public struct SwitchToMainThreadAwaitable
{
readonly PlayerLoopTiming playerLoopTiming;
Expand Down Expand Up @@ -113,7 +109,7 @@ public bool IsCompleted
get
{
var currentThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
if (PlayerLoopHelper.MainThreadId == currentThreadId)
if (GDTaskPlayerLoopAutoload.MainThreadId == currentThreadId)
{
return true; // run immediate.
}
Expand All @@ -128,12 +124,12 @@ public bool IsCompleted

public void OnCompleted(Action continuation)
{
PlayerLoopHelper.AddContinuation(playerLoopTiming, continuation);
GDTaskPlayerLoopAutoload.AddContinuation(playerLoopTiming, continuation);
}

public void UnsafeOnCompleted(Action continuation)
{
PlayerLoopHelper.AddContinuation(playerLoopTiming, continuation);
GDTaskPlayerLoopAutoload.AddContinuation(playerLoopTiming, continuation);
}
}
}
Expand Down Expand Up @@ -167,23 +163,22 @@ public Awaiter(PlayerLoopTiming timing, CancellationToken cancellationToken)

public Awaiter GetAwaiter() => this;

public bool IsCompleted => PlayerLoopHelper.MainThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId;
public bool IsCompleted => GDTaskPlayerLoopAutoload.MainThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId;

public void GetResult() { cancellationToken.ThrowIfCancellationRequested(); }

public void OnCompleted(Action continuation)
{
PlayerLoopHelper.AddContinuation(timing, continuation);
GDTaskPlayerLoopAutoload.AddContinuation(timing, continuation);
}

public void UnsafeOnCompleted(Action continuation)
{
PlayerLoopHelper.AddContinuation(timing, continuation);
GDTaskPlayerLoopAutoload.AddContinuation(timing, continuation);
}
}
}

#endif

public struct SwitchToThreadPoolAwaitable
{
Expand All @@ -203,11 +198,7 @@ public void OnCompleted(Action continuation)

public void UnsafeOnCompleted(Action continuation)
{
#if NETCOREAPP3_1
ThreadPool.UnsafeQueueUserWorkItem(ThreadPoolWorkItem.Create(continuation), false);
#else
ThreadPool.UnsafeQueueUserWorkItem(switchToCallback, continuation);
#endif
}

static void Callback(object state)
Expand All @@ -216,48 +207,6 @@ static void Callback(object state)
continuation();
}
}

#if NETCOREAPP3_1

sealed class ThreadPoolWorkItem : IThreadPoolWorkItem, ITaskPoolNode<ThreadPoolWorkItem>
{
static TaskPool<ThreadPoolWorkItem> pool;
ThreadPoolWorkItem nextNode;
public ref ThreadPoolWorkItem NextNode => ref nextNode;

static ThreadPoolWorkItem()
{
TaskPool.RegisterSizeGetter(typeof(ThreadPoolWorkItem), () => pool.Size);
}

Action continuation;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ThreadPoolWorkItem Create(Action continuation)
{
if (!pool.TryPop(out var item))
{
item = new ThreadPoolWorkItem();
}

item.continuation = continuation;
return item;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Execute()
{
var call = continuation;
continuation = null;
if (call != null)
{
pool.TryPush(this);
call.Invoke();
}
}
}

#endif
}

public struct SwitchToTaskPoolAwaitable
Expand Down
3 changes: 1 addition & 2 deletions addons/GDTask/GDTask.WhenAll.Generated.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;
Expand Down
3 changes: 1 addition & 2 deletions addons/GDTask/GDTask.WhenAny.Generated.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;
Expand Down
3 changes: 1 addition & 2 deletions addons/GDTask/GDTaskExtensions.Shorthand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System.Collections.Generic;
using System.Collections.Generic;

namespace Fractural.Tasks
{
Expand Down
Loading

0 comments on commit e7934d1

Please sign in to comment.