Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mewlist committed Nov 30, 2023
1 parent d044241 commit de59ef2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 39 deletions.
26 changes: 1 addition & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ taskQueue.Enqueue(async ct => { ... }, priority: 0); // This task is processed f

If you add tasks to a queue with a maximum size of 2 as follows,
and exceed the maximum number, the last added task is discarded.
If the priority of the task to be added is higher, the task with a lower priority is discarded and queued.

```csharp
taskQueue = new TaskQueue(TaskQueueLimitType.Discard, maxSize: 2);
Expand Down Expand Up @@ -198,28 +199,3 @@ TaskInterval
.Create(1000 /* ms */, TestTaskAsync, IntervalTimerType.UnityUnscaledTime)
.Start(destroyCancellationToken);
```

### Specifying PlayerLoop

You can specify the PlayerLoop timing for processing tasks.
The following timing types are defined.

| Timing | Description |
|-------------------------|------|
| `MewUnityEarlyUpdate` | Called at the beginning of Unity's frame update. At this stage, initial event processing and input updates occur. |
| `MewUnityFixedUpdate` | The timing for physics updates. Corresponds to fixed-frame-rate processing in Unity Engine. |
| `MewUnityPreUpdate` | Processing executed before the Update method. Includes scene state updates and animation updates. |
| `MewUnityUpdate` | The normal Update method timing, mainly used for updating game logic. |
| `MewUnityPreLateUpdate` | Processing executed before LateUpdate. Some post-processing for cameras and animations may occur. |
| `MewUnityPostLateUpdate` | Processing at the end of the frame, including rendering preparation and final camera updates. |

To specify PlayerLoop timing, specify the timing type for TaskInterval.
For example, specifying MewUnityFixedUpdate can ensure stable game-time task execution even in case of frame skips, preventing delays.

```csharp
TaskInterval<MewUnityFixedUpdate>
.Create(1000 /* ms */, TestTaskAsync, IntervalTimerType.UnityUnscaledTime)
.Start(destroyCancellationToken);
```


1 change: 1 addition & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ taskQueue.Enqueue(async ct => { ... }, priority: 0); // このタスクが優先
#### TaskQueueLimitType.Discard

最大サイズ 2 のキューに対して以下のようにタスクを追加し、最大数を超えた場合、最後に追加されたタスクが破棄されます。
追加されるタスクの優先度が高い場合は、より低い優先度のタスクが破棄されキューイングが行われます。

```csharp
taskQueue = new TaskQueue(TaskQueueLimitType.Discard, maxSize: 2);
Expand Down
3 changes: 2 additions & 1 deletion docs/en/TaskQueue/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ <h3 id="executing-priority-tasks">Executing Priority Tasks</h3>
<h3 id="setting-the-maximum-queue-size">Setting the Maximum Queue Size</h3>
<h4 id="taskqueuelimittypediscard">TaskQueueLimitType.Discard</h4>
<p>If you add tasks to a queue with a maximum size of 2 as follows,
and exceed the maximum number, the last added task is discarded.</p>
and exceed the maximum number, the last added task is discarded.
If the priority of the task to be added is higher, the task with a lower priority is discarded and queued.</p>
<pre><code class="lang-csharp">taskQueue = new TaskQueue(TaskQueueLimitType.Discard, maxSize: 2);
taskQueue.Enqueue(async ct =&gt; { ... });
taskQueue.Enqueue(async ct =&gt; { ... });
Expand Down
4 changes: 2 additions & 2 deletions docs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"en/TaskQueue/index.html": {
"href": "en/TaskQueue/index.html",
"title": "TaskQueue | MewCore",
"keywords": "TaskQueue TaskQueue is a library for handling serial processing of asynchronous functions in Unity development. Asynchronous functions are executed in the order they are input into the queue. It also has the feature of a priority queue, which allows you to prioritize important tasks. Main Features Dynamic Function Addition: You can add asynchronous functions to the task queue at runtime. This allows you to flexibly respond to changing requirements and situations. Execution management based on priority: You can set a priority for each asynchronous function and process important tasks preferentially. This prevents delays in important processing. Serial processing and safety: Multiple asynchronous functions are executed in order and wait for the completion of one function before starting the execution of the next. This improves the safety of UI updates and game sequences. Maximum size of the queue: You can set the maximum number of tasks that can be input into the queue. This allows you to prevent tasks from building up in the queue. Use Scenarios Dynamic UI Updates: Used for smooth control of dynamic display and hiding of dialog boxes and menus in the game. Game Event Sequencing: Suitable for managing ordered events such as story progression and tutorials. Command Pattern Adaptation: Suitable for implementing the command pattern, including asynchronous processes. UI Event Handling: Used to prevent concurrent execution in response to asynchronous UI events such as clicks. Sample Code class Sample : Monobehaviour { void Start() { var taskQueue = new TaskQueue(); // By passing the destroyCancellationToken, processing is automatically stoppped and disposed when MonoBehaviour is destroyed. taskQueue.Start(destroyCancellationToken); // Add an asynchronous function to TaskQueue. taskQueue.Enqueue(async cancellationToken => { Debug.Log(\"Hello\"); await Task.Delay(1000, cancellationToken); }); taskQueue.Enqueue(async cancellationToken => { await Task.Delay(1000, cancellationToken); Debug.Log(\"Bye\"); }); } } Execution Result Hello // 2sec later Bye Executing Priority Tasks You can execute priority tasks by specifying the priority as the second argument to Enqueue. The processing with a smaller priority value is prioritized. The default value is 0. taskQueue.Enqueue(async ct => { ... }, priority: 1); taskQueue.Enqueue(async ct => { ... }, priority: 0); // This task is processed first Setting the Maximum Queue Size TaskQueueLimitType.Discard If you add tasks to a queue with a maximum size of 2 as follows, and exceed the maximum number, the last added task is discarded. taskQueue = new TaskQueue(TaskQueueLimitType.Discard, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // This task is discarded TaskQueueLimitType.SwapLast If you add tasks to a queue with a maximum size of 2 as follows, and exceed the maximum number, the last task is replaced. If the queue is made up of tasks that have a higher priority than the task to be added, no replacement will be made. taskQueue = new TaskQueue(TaskQueueLimitType.SwapLast, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // This task is discarded taskQueue.Enqueue(async ct => { ... });"
"keywords": "TaskQueue TaskQueue is a library for handling serial processing of asynchronous functions in Unity development. Asynchronous functions are executed in the order they are input into the queue. It also has the feature of a priority queue, which allows you to prioritize important tasks. Main Features Dynamic Function Addition: You can add asynchronous functions to the task queue at runtime. This allows you to flexibly respond to changing requirements and situations. Execution management based on priority: You can set a priority for each asynchronous function and process important tasks preferentially. This prevents delays in important processing. Serial processing and safety: Multiple asynchronous functions are executed in order and wait for the completion of one function before starting the execution of the next. This improves the safety of UI updates and game sequences. Maximum size of the queue: You can set the maximum number of tasks that can be input into the queue. This allows you to prevent tasks from building up in the queue. Use Scenarios Dynamic UI Updates: Used for smooth control of dynamic display and hiding of dialog boxes and menus in the game. Game Event Sequencing: Suitable for managing ordered events such as story progression and tutorials. Command Pattern Adaptation: Suitable for implementing the command pattern, including asynchronous processes. UI Event Handling: Used to prevent concurrent execution in response to asynchronous UI events such as clicks. Sample Code class Sample : Monobehaviour { void Start() { var taskQueue = new TaskQueue(); // By passing the destroyCancellationToken, processing is automatically stoppped and disposed when MonoBehaviour is destroyed. taskQueue.Start(destroyCancellationToken); // Add an asynchronous function to TaskQueue. taskQueue.Enqueue(async cancellationToken => { Debug.Log(\"Hello\"); await Task.Delay(1000, cancellationToken); }); taskQueue.Enqueue(async cancellationToken => { await Task.Delay(1000, cancellationToken); Debug.Log(\"Bye\"); }); } } Execution Result Hello // 2sec later Bye Executing Priority Tasks You can execute priority tasks by specifying the priority as the second argument to Enqueue. The processing with a smaller priority value is prioritized. The default value is 0. taskQueue.Enqueue(async ct => { ... }, priority: 1); taskQueue.Enqueue(async ct => { ... }, priority: 0); // This task is processed first Setting the Maximum Queue Size TaskQueueLimitType.Discard If you add tasks to a queue with a maximum size of 2 as follows, and exceed the maximum number, the last added task is discarded. If the priority of the task to be added is higher, the task with a lower priority is discarded and queued. taskQueue = new TaskQueue(TaskQueueLimitType.Discard, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // This task is discarded TaskQueueLimitType.SwapLast If you add tasks to a queue with a maximum size of 2 as follows, and exceed the maximum number, the last task is replaced. If the queue is made up of tasks that have a higher priority than the task to be added, no replacement will be made. taskQueue = new TaskQueue(TaskQueueLimitType.SwapLast, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // This task is discarded taskQueue.Enqueue(async ct => { ... });"
},
"en/TaskQueue/player-loop.html": {
"href": "en/TaskQueue/player-loop.html",
Expand Down Expand Up @@ -182,7 +182,7 @@
"ja/TaskQueue/index.html": {
"href": "ja/TaskQueue/index.html",
"title": "TaskQueue | MewCore",
"keywords": "TaskQueue TaskQueue は Unity 開発における非同期関数の直列処理を行うためのライブラリです。 キューに入力した順で非同期関数が実行されます。 また、優先度付きキューの機能も備えており、重要なタスクを優先的に実行することができます。 主な特徴 動的な関数追加: ランタイムで非同期関数をタスクキューに追加することができます。これにより、変化する要件や状況に柔軟に対応可能です。 優先度に基づく実行管理: 各非同期関数に優先度を設定し、重要なタスクを優先的に処理します。これにより、重要な処理の遅延を防ぎます。 直列処理と安全性: 複数の非同期関数を順序立てて実行し、一つの関数が完了するまで次の関数の実行を待機します。これにより、UI 更新やゲームシーケンスの安全性が向上します。 キューの最大サイズ: キューに入力できるタスクの最大数を設定できます。これにより、キューにタスクが溜まりすぎることを防ぐことができます。 シンプルな記述: シンプルに記述できるように設計されています。 使用シナリオ UIの動的更新: ゲーム内でのダイアログボックスやメニューの動的な表示・非表示をスムーズに制御する際に使用します。 ゲームイベントのシーケンシング: 物語進行やチュートリアルなど、順序立てられたイベントの管理に適しています。 TaskQueue を使用することで、Unity 開発における非同期処理の複雑さを軽減し、より効果的かつ効率的なコード記述を可能にします。 コマンドパターンへの適応: 非同期処理を含めたコマンドパターンの実装に適しています。 UI イベントのハンドリング: クリックなど UI の非同期イベントに対して並列実行を防ぐために使用します。 サンプルコード class Sample : Monobehaviour { void Start() { var taskQueue = new TaskQueue(); // destroyCancellationToken を渡すことで // MonoBehaviour が破棄されたタイミングで自動的に処理を停止し Dispose されます。 taskQueue.Start(destroyCancellationToken); // TaskQueue に非同期関数を追加します。 taskQueue.Enqueue(async cancellationToken => { Debug.Log(\"Hello\"); await Task.Delay(1000, cancellationToken); }); taskQueue.Enqueue(async cancellationToken => { await Task.Delay(1000, cancellationToken); Debug.Log(\"Bye\"); }); } } 実行結果 Hello // 二秒後 Bye 優先度付きタスクの実行 Enqueue の第二引数に優先度を指定することで、優先度付きタスクを実行することができます。 priotiry値が小さい処理が優先されます。既定値は 0 です。 taskQueue.Enqueue(async ct => { ... }, priority: 1); taskQueue.Enqueue(async ct => { ... }, priority: 0); // このタスクが優先して処理される キュー最大サイズの設定 TaskQueueLimitType.Discard 最大サイズ 2 のキューに対して以下のようにタスクを追加し、最大数を超えた場合、最後に追加されたタスクが破棄されます。 taskQueue = new TaskQueue(TaskQueueLimitType.Discard, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // このタスクが破棄される TaskQueueLimitType.SwapLast 最大サイズ 2 のキューに対して以下のようにタスクを追加し、最大数を超えた場合、最後のタスクを入れ替えます。 追加されるタスクより優先度が高いタスクでキューが構成される場合は、入れ替えは行われません。 taskQueue = new TaskQueue(TaskQueueLimitType.SwapLast, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // このタスクが破棄される taskQueue.Enqueue(async ct => { ... });"
"keywords": "TaskQueue TaskQueue は Unity 開発における非同期関数の直列処理を行うためのライブラリです。 キューに入力した順で非同期関数が実行されます。 また、優先度付きキューの機能も備えており、重要なタスクを優先的に実行することができます。 主な特徴 動的な関数追加: ランタイムで非同期関数をタスクキューに追加することができます。これにより、変化する要件や状況に柔軟に対応可能です。 優先度に基づく実行管理: 各非同期関数に優先度を設定し、重要なタスクを優先的に処理します。これにより、重要な処理の遅延を防ぎます。 直列処理と安全性: 複数の非同期関数を順序立てて実行し、一つの関数が完了するまで次の関数の実行を待機します。これにより、UI 更新やゲームシーケンスの安全性が向上します。 キューの最大サイズ: キューに入力できるタスクの最大数を設定できます。これにより、キューにタスクが溜まりすぎることを防ぐことができます。 シンプルな記述: シンプルに記述できるように設計されています。 使用シナリオ UIの動的更新: ゲーム内でのダイアログボックスやメニューの動的な表示・非表示をスムーズに制御する際に使用します。 ゲームイベントのシーケンシング: 物語進行やチュートリアルなど、順序立てられたイベントの管理に適しています。 TaskQueue を使用することで、Unity 開発における非同期処理の複雑さを軽減し、より効果的かつ効率的なコード記述を可能にします。 コマンドパターンへの適応: 非同期処理を含めたコマンドパターンの実装に適しています。 UI イベントのハンドリング: クリックなど UI の非同期イベントに対して並列実行を防ぐために使用します。 サンプルコード class Sample : Monobehaviour { void Start() { var taskQueue = new TaskQueue(); // destroyCancellationToken を渡すことで // MonoBehaviour が破棄されたタイミングで自動的に処理を停止し Dispose されます。 taskQueue.Start(destroyCancellationToken); // TaskQueue に非同期関数を追加します。 taskQueue.Enqueue(async cancellationToken => { Debug.Log(\"Hello\"); await Task.Delay(1000, cancellationToken); }); taskQueue.Enqueue(async cancellationToken => { await Task.Delay(1000, cancellationToken); Debug.Log(\"Bye\"); }); } } 実行結果 Hello // 二秒後 Bye 優先度付きタスクの実行 Enqueue の第二引数に優先度を指定することで、優先度付きタスクを実行することができます。 priotiry値が小さい処理が優先されます。既定値は 0 です。 taskQueue.Enqueue(async ct => { ... }, priority: 1); taskQueue.Enqueue(async ct => { ... }, priority: 0); // このタスクが優先して処理される キュー最大サイズの設定 TaskQueueLimitType.Discard 最大サイズ 2 のキューに対して以下のようにタスクを追加し、最大数を超えた場合、最後に追加されたタスクが破棄されます。 追加されるタスクの優先度が高い場合は、より低い優先度のタスクが破棄されキューイングが行われます。 taskQueue = new TaskQueue(TaskQueueLimitType.Discard, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // このタスクが破棄される TaskQueueLimitType.SwapLast 最大サイズ 2 のキューに対して以下のようにタスクを追加し、最大数を超えた場合、最後のタスクを入れ替えます。 追加されるタスクより優先度が高いタスクでキューが構成される場合は、入れ替えは行われません。 taskQueue = new TaskQueue(TaskQueueLimitType.SwapLast, maxSize: 2); taskQueue.Enqueue(async ct => { ... }); taskQueue.Enqueue(async ct => { ... }); // このタスクが破棄される taskQueue.Enqueue(async ct => { ... });"
},
"ja/TaskQueue/player-loop.html": {
"href": "ja/TaskQueue/player-loop.html",
Expand Down
Loading

0 comments on commit de59ef2

Please sign in to comment.