MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_task_node.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_TASK_NODE_H_1622533593
12#define INCGUARD_MGL_TASK_NODE_H_1622533593
13
15
16namespace MGL::Task
17{
19class Node
20{
21public:
22 /* ------------------------------------------------------------------------- */
27 /* ------------------------------------------------------------------------- */
28 constexpr Node(Identifier identifier) noexcept
29 : _identifier(identifier)
30 {
31 }
32
33 virtual ~Node() = default;
34
35 /* ------------------------------------------------------------------------- */
40 /* ------------------------------------------------------------------------- */
41 [[nodiscard]] constexpr Identifier GetIdentifier() const noexcept
42 {
43 return _identifier;
44 }
45
46 /* ------------------------------------------------------------------------- */
50 /* ------------------------------------------------------------------------- */
51 constexpr void Kill() noexcept
52 {
53 _isRequestedKill = true;
54 }
55
56 /* ------------------------------------------------------------------------- */
62 /* ------------------------------------------------------------------------- */
63 [[nodiscard]] constexpr bool IsRequestedKill() const noexcept
64 {
65 return _isRequestedKill;
66 }
67
68 /* ------------------------------------------------------------------------- */
73 /* ------------------------------------------------------------------------- */
74 constexpr void SetResideLevel(ResideLevel resideLevel) noexcept
75 {
76 _resideLevel = resideLevel;
77 }
78
79 /* ------------------------------------------------------------------------- */
84 /* ------------------------------------------------------------------------- */
85 [[nodiscard]] constexpr ResideLevel GetResideLevel() const noexcept
86 {
87 return _resideLevel;
88 }
89
90 /* ------------------------------------------------------------------------- */
96 /* ------------------------------------------------------------------------- */
97 [[nodiscard]] constexpr bool IsResident() const noexcept
98 {
99 return _resideLevel > ResideLevel::NoResident;
100 }
101
102 /* ------------------------------------------------------------------------- */
109 /* ------------------------------------------------------------------------- */
110 template <typename TaskIDType>
111 constexpr void SetAsynchronous(bool isEnabled, TaskIDType barrierIdentifier = TaskIDType()) noexcept
112 {
113 _isAsynchronous = isEnabled;
114 _barrierIdentifier = Identifier(barrierIdentifier);
115 }
116
117 /* ------------------------------------------------------------------------- */
123 /* ------------------------------------------------------------------------- */
124 [[nodiscard]] constexpr bool IsEnabledAsynchronous() const noexcept
125 {
126 return _isAsynchronous;
127 }
128
129 /* ------------------------------------------------------------------------- */
133 /* ------------------------------------------------------------------------- */
134 template <typename TaskIDType = Identifier>
135 [[nodiscard]] constexpr TaskIDType GetBarrierIdentifier() const noexcept
136 {
137 return TaskIDType(_barrierIdentifier);
138 }
139
140 /* ------------------------------------------------------------------------- */
146 /* ------------------------------------------------------------------------- */
147 [[nodiscard]] constexpr bool IsEnabledBarrier() const noexcept
148 {
149 return _barrierIdentifier > _identifier;
150 }
151
152 /* ------------------------------------------------------------------------- */
156 /* ------------------------------------------------------------------------- */
157 virtual void OnInitialize() noexcept
158 {
159 }
160
161 /* ------------------------------------------------------------------------- */
168 /* ------------------------------------------------------------------------- */
169 template <typename EventIDType>
170 void NotifyEvent(EventIDType event, void *argument) noexcept
171 {
172 OnReceiveTaskEvent(EventIdentifier(event), argument);
173 }
174
175 /* ------------------------------------------------------------------------- */
180 /* ------------------------------------------------------------------------- */
181 virtual void OnExecute(ExecuteStage stage) noexcept = 0;
182
183
184protected:
185 /* ------------------------------------------------------------------------- */
191 /* ------------------------------------------------------------------------- */
192 virtual void OnReceiveTaskEvent(EventIdentifier eventID, void *argument) noexcept
193 {
194 (void)eventID;
195 (void)argument;
196 }
197
198private:
199 Identifier _identifier{0};
200 ResideLevel _resideLevel{ResideLevel::NoResident};
201 bool _isRequestedKill{false};
202 bool _isAsynchronous{false};
203 Identifier _barrierIdentifier{0};
204};
205} // namespace MGL::Task
206
207#endif // INCGUARD_MGL_TASK_NODE_H_1622533593
208
209// vim: et ts=4 sw=4 sts=4
タスクノード
Definition mgl_task_node.h:20
constexpr bool IsResident() const noexcept
常駐タスクかどうかを取得
Definition mgl_task_node.h:97
constexpr void SetAsynchronous(bool isEnabled, TaskIDType barrierIdentifier=TaskIDType()) noexcept
非同期実行の設定
Definition mgl_task_node.h:111
constexpr void Kill() noexcept
削除要求
Definition mgl_task_node.h:51
constexpr bool IsEnabledBarrier() const noexcept
有効なバリアIDが設定されているかを取得
Definition mgl_task_node.h:147
virtual void OnInitialize() noexcept
タスク生成時に呼び出される関数
Definition mgl_task_node.h:157
constexpr TaskIDType GetBarrierIdentifier() const noexcept
非同期実行時のバリアIDを取得
Definition mgl_task_node.h:135
constexpr Identifier GetIdentifier() const noexcept
このタスクノードのIDを取得
Definition mgl_task_node.h:41
constexpr bool IsEnabledAsynchronous() const noexcept
非同期実行が有効化されているかを取得
Definition mgl_task_node.h:124
virtual void OnExecute(ExecuteStage stage) noexcept=0
タスク実行時に呼び出される関数
constexpr Node(Identifier identifier) noexcept
コンストラクタ
Definition mgl_task_node.h:28
constexpr void SetResideLevel(ResideLevel resideLevel) noexcept
常駐レベルの設定
Definition mgl_task_node.h:74
constexpr ResideLevel GetResideLevel() const noexcept
常駐レベルの取得
Definition mgl_task_node.h:85
constexpr bool IsRequestedKill() const noexcept
削除要求されているかを取得
Definition mgl_task_node.h:63
void NotifyEvent(EventIDType event, void *argument) noexcept
タスクへのイベント通知
Definition mgl_task_node.h:170
virtual void OnReceiveTaskEvent(EventIdentifier eventID, void *argument) noexcept
タスクのイベント受信処理
Definition mgl_task_node.h:192
uint32_t Identifier
実績用の識別子の型
Definition mgl_achievement_defs.h:26
MGL タスク関連定義
ResideLevel
常駐レベル
Definition mgl_task_defs.h:109
uint32_t EventIdentifier
イベントIDを表す型
Definition mgl_task_defs.h:105
uint8_t ExecuteStage
実行ステージ
Definition mgl_task_defs.h:68