-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Cysharp/feature/net7.0
Adopt to .NET 7
- Loading branch information
Showing
28 changed files
with
1,666 additions
and
1,778 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 45 additions & 48 deletions
93
src/LogicLooper/CompilerServices/LogicLooperCoroutineAsyncValueTaskMethodBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,63 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Cysharp.Threading.CompilerServices | ||
{ | ||
namespace Cysharp.Threading.CompilerServices; | ||
|
||
#if !DEBUG | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
#endif | ||
public struct LogicLooperCoroutineAsyncValueTaskMethodBuilder | ||
{ | ||
private readonly LogicLooperCoroutine _coroutine; | ||
public struct LogicLooperCoroutineAsyncValueTaskMethodBuilder | ||
{ | ||
private readonly LogicLooperCoroutine _coroutine; | ||
|
||
public static LogicLooperCoroutineAsyncValueTaskMethodBuilder Create() | ||
{ | ||
return new LogicLooperCoroutineAsyncValueTaskMethodBuilder(new LogicLooperCoroutine(LogicLooperCoroutineActionContext.Current!)); | ||
} | ||
public static LogicLooperCoroutineAsyncValueTaskMethodBuilder Create() | ||
{ | ||
return new LogicLooperCoroutineAsyncValueTaskMethodBuilder(new LogicLooperCoroutine(LogicLooperCoroutineActionContext.Current!)); | ||
} | ||
|
||
private LogicLooperCoroutineAsyncValueTaskMethodBuilder(LogicLooperCoroutine coroutine) | ||
{ | ||
_coroutine = coroutine ?? throw new ArgumentNullException(nameof(coroutine)); | ||
} | ||
private LogicLooperCoroutineAsyncValueTaskMethodBuilder(LogicLooperCoroutine coroutine) | ||
{ | ||
_coroutine = coroutine ?? throw new ArgumentNullException(nameof(coroutine)); | ||
} | ||
|
||
public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine | ||
{ | ||
stateMachine.MoveNext(); | ||
} | ||
public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine | ||
{ | ||
stateMachine.MoveNext(); | ||
} | ||
|
||
public void SetStateMachine(IAsyncStateMachine stateMachine) | ||
{ | ||
} | ||
public void SetStateMachine(IAsyncStateMachine stateMachine) | ||
{ | ||
} | ||
|
||
public void SetResult() | ||
{ | ||
_coroutine.SetResult(); | ||
} | ||
public void SetResult() | ||
{ | ||
_coroutine.SetResult(); | ||
} | ||
|
||
public void SetException(Exception exception) | ||
{ | ||
_coroutine.SetException(exception); | ||
} | ||
public void SetException(Exception exception) | ||
{ | ||
_coroutine.SetException(exception); | ||
} | ||
|
||
public LogicLooperCoroutine Task => _coroutine; | ||
public LogicLooperCoroutine Task => _coroutine; | ||
|
||
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : INotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : INotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
|
||
awaiter.OnCompleted(stateMachine.MoveNext); | ||
} | ||
awaiter.OnCompleted(stateMachine.MoveNext); | ||
} | ||
|
||
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : ICriticalNotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : ICriticalNotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
|
||
awaiter.UnsafeOnCompleted(stateMachine.MoveNext); | ||
} | ||
awaiter.UnsafeOnCompleted(stateMachine.MoveNext); | ||
} | ||
} |
93 changes: 45 additions & 48 deletions
93
src/LogicLooper/CompilerServices/LogicLooperCoroutineAsyncValueTaskMethodBuilder`1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,63 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Cysharp.Threading.CompilerServices | ||
{ | ||
namespace Cysharp.Threading.CompilerServices; | ||
|
||
#if !DEBUG | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
#endif | ||
public struct LogicLooperCoroutineAsyncValueTaskMethodBuilder<TResult> | ||
{ | ||
private readonly LogicLooperCoroutine<TResult> _coroutine; | ||
public struct LogicLooperCoroutineAsyncValueTaskMethodBuilder<TResult> | ||
{ | ||
private readonly LogicLooperCoroutine<TResult> _coroutine; | ||
|
||
public static LogicLooperCoroutineAsyncValueTaskMethodBuilder<TResult> Create() | ||
{ | ||
return new LogicLooperCoroutineAsyncValueTaskMethodBuilder<TResult>(new LogicLooperCoroutine<TResult>(LogicLooperCoroutineActionContext.Current!)); | ||
} | ||
public static LogicLooperCoroutineAsyncValueTaskMethodBuilder<TResult> Create() | ||
{ | ||
return new LogicLooperCoroutineAsyncValueTaskMethodBuilder<TResult>(new LogicLooperCoroutine<TResult>(LogicLooperCoroutineActionContext.Current!)); | ||
} | ||
|
||
private LogicLooperCoroutineAsyncValueTaskMethodBuilder(LogicLooperCoroutine<TResult> coroutine) | ||
{ | ||
_coroutine = coroutine ?? throw new ArgumentNullException(nameof(coroutine)); | ||
} | ||
private LogicLooperCoroutineAsyncValueTaskMethodBuilder(LogicLooperCoroutine<TResult> coroutine) | ||
{ | ||
_coroutine = coroutine ?? throw new ArgumentNullException(nameof(coroutine)); | ||
} | ||
|
||
public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine | ||
{ | ||
stateMachine.MoveNext(); | ||
} | ||
public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine | ||
{ | ||
stateMachine.MoveNext(); | ||
} | ||
|
||
public void SetStateMachine(IAsyncStateMachine stateMachine) | ||
{ | ||
} | ||
public void SetStateMachine(IAsyncStateMachine stateMachine) | ||
{ | ||
} | ||
|
||
public void SetResult(TResult result) | ||
{ | ||
_coroutine.SetResult(result); | ||
} | ||
public void SetResult(TResult result) | ||
{ | ||
_coroutine.SetResult(result); | ||
} | ||
|
||
public void SetException(Exception exception) | ||
{ | ||
_coroutine.SetException(exception); | ||
} | ||
public void SetException(Exception exception) | ||
{ | ||
_coroutine.SetException(exception); | ||
} | ||
|
||
public LogicLooperCoroutine<TResult> Task => _coroutine; | ||
public LogicLooperCoroutine<TResult> Task => _coroutine; | ||
|
||
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : INotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : INotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
|
||
awaiter.OnCompleted(stateMachine.MoveNext); | ||
} | ||
awaiter.OnCompleted(stateMachine.MoveNext); | ||
} | ||
|
||
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : ICriticalNotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) | ||
where TAwaiter : ICriticalNotifyCompletion | ||
where TStateMachine : IAsyncStateMachine | ||
{ | ||
if (!(awaiter is LogicLooperCoroutineFrameAwaitable)) | ||
throw new InvalidOperationException($"Cannot use general-purpose awaitable in the Coroutine action. Use {nameof(LogicLooperCoroutineActionContext)}'s methods instead of {nameof(Task)}'s."); | ||
|
||
awaiter.UnsafeOnCompleted(stateMachine.MoveNext); | ||
} | ||
awaiter.UnsafeOnCompleted(stateMachine.MoveNext); | ||
} | ||
} |
48 changes: 23 additions & 25 deletions
48
src/LogicLooper/CompilerServices/LogicLooperCoroutineFrameAwaitable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Cysharp.Threading.CompilerServices | ||
{ | ||
namespace Cysharp.Threading.CompilerServices; | ||
|
||
#if !DEBUG | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
#endif | ||
public struct LogicLooperCoroutineFrameAwaitable : INotifyCompletion, ICriticalNotifyCompletion | ||
{ | ||
private readonly int _waitFrames; | ||
private readonly LogicLooperCoroutine _coroutine; | ||
public struct LogicLooperCoroutineFrameAwaitable : INotifyCompletion, ICriticalNotifyCompletion | ||
{ | ||
private readonly int _waitFrames; | ||
private readonly LogicLooperCoroutine _coroutine; | ||
|
||
public LogicLooperCoroutineFrameAwaitable GetAwaiter() => this; | ||
public LogicLooperCoroutineFrameAwaitable GetAwaiter() => this; | ||
|
||
public bool IsCompleted => false; | ||
public void GetResult() | ||
{ } | ||
public bool IsCompleted => false; | ||
public void GetResult() | ||
{ } | ||
|
||
public LogicLooperCoroutineFrameAwaitable(LogicLooperCoroutine coroutine, int waitFrames) | ||
{ | ||
_coroutine = coroutine ?? throw new ArgumentNullException(nameof(coroutine)); | ||
_waitFrames = (waitFrames > 0) ? waitFrames - 1 : throw new ArgumentOutOfRangeException(nameof(waitFrames)); | ||
} | ||
public LogicLooperCoroutineFrameAwaitable(LogicLooperCoroutine coroutine, int waitFrames) | ||
{ | ||
_coroutine = coroutine ?? throw new ArgumentNullException(nameof(coroutine)); | ||
_waitFrames = (waitFrames > 0) ? waitFrames - 1 : throw new ArgumentOutOfRangeException(nameof(waitFrames)); | ||
} | ||
|
||
public void OnCompleted(Action continuation) | ||
{ | ||
_coroutine.SetContinuation(_waitFrames, continuation); | ||
} | ||
public void OnCompleted(Action continuation) | ||
{ | ||
_coroutine.SetContinuation(_waitFrames, continuation); | ||
} | ||
|
||
public void UnsafeOnCompleted(Action continuation) | ||
{ | ||
_coroutine.SetContinuation(_waitFrames, continuation); | ||
} | ||
public void UnsafeOnCompleted(Action continuation) | ||
{ | ||
_coroutine.SetContinuation(_waitFrames, continuation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
namespace Cysharp.Threading; | ||
|
||
namespace Cysharp.Threading | ||
/// <summary> | ||
/// Provides interface for update loop programming model. | ||
/// </summary> | ||
public interface ILogicLooper : IDisposable | ||
{ | ||
/// <summary> | ||
/// Provides interface for update loop programming model. | ||
/// Gets a unique identifier of the looper. | ||
/// </summary> | ||
public interface ILogicLooper : IDisposable | ||
{ | ||
/// <summary> | ||
/// Gets a unique identifier of the looper. | ||
/// </summary> | ||
int Id { get; } | ||
int Id { get; } | ||
|
||
/// <summary> | ||
/// Gets an approximately count of running actions. | ||
/// </summary> | ||
int ApproximatelyRunningActions { get; } | ||
/// <summary> | ||
/// Gets an approximately count of running actions. | ||
/// </summary> | ||
int ApproximatelyRunningActions { get; } | ||
|
||
/// <summary> | ||
/// Gets a duration of the last processed frame. | ||
/// </summary> | ||
TimeSpan LastProcessingDuration { get; } | ||
/// <summary> | ||
/// Gets a duration of the last processed frame. | ||
/// </summary> | ||
TimeSpan LastProcessingDuration { get; } | ||
|
||
/// <summary> | ||
/// Gets a target frame rate of the looper. | ||
/// </summary> | ||
double TargetFrameRate { get; } | ||
/// <summary> | ||
/// Gets a target frame rate of the looper. | ||
/// </summary> | ||
double TargetFrameRate { get; } | ||
|
||
/// <summary> | ||
/// Registers a loop-frame action to the looper and returns <see cref="Task"/> to wait for completion. | ||
/// </summary> | ||
/// <param name="loopAction"></param> | ||
/// <returns></returns> | ||
Task RegisterActionAsync(LogicLooperActionDelegate loopAction); | ||
/// <summary> | ||
/// Registers a loop-frame action to the looper and returns <see cref="Task"/> to wait for completion. | ||
/// </summary> | ||
/// <param name="loopAction"></param> | ||
/// <returns></returns> | ||
Task RegisterActionAsync(LogicLooperActionDelegate loopAction); | ||
|
||
/// <summary> | ||
/// Registers a loop-frame action with state object to the looper and returns <see cref="Task"/> to wait for completion. | ||
/// </summary> | ||
/// <param name="loopAction"></param> | ||
/// <param name="state"></param> | ||
/// <returns></returns> | ||
Task RegisterActionAsync<TState>(LogicLooperActionWithStateDelegate<TState> loopAction, TState state); | ||
/// <summary> | ||
/// Registers a loop-frame action with state object to the looper and returns <see cref="Task"/> to wait for completion. | ||
/// </summary> | ||
/// <param name="loopAction"></param> | ||
/// <param name="state"></param> | ||
/// <returns></returns> | ||
Task RegisterActionAsync<TState>(LogicLooperActionWithStateDelegate<TState> loopAction, TState state); | ||
|
||
/// <summary> | ||
/// Stops the action loop of the looper. | ||
/// </summary> | ||
/// <param name="shutdownDelay"></param> | ||
Task ShutdownAsync(TimeSpan shutdownDelay); | ||
} | ||
/// <summary> | ||
/// Stops the action loop of the looper. | ||
/// </summary> | ||
/// <param name="shutdownDelay"></param> | ||
Task ShutdownAsync(TimeSpan shutdownDelay); | ||
} |
Oops, something went wrong.