IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
task_stage.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/task_queue.hxx>
8
9namespace ice
10{
11
12 template<typename StageObject = void>
14 {
15 inline explicit TaskStageAwaitable(ice::TaskQueue& queue) noexcept
16 : _awaitable{ ._params{.modifier = TaskAwaitableModifier::Unused} }
17 , _queue{ queue }
18 { }
19
20 inline bool await_ready() const noexcept
21 {
22 return false;
23 }
24
25 inline auto await_suspend(ice::coroutine_handle<> coroutine) noexcept
26 {
27 _awaitable._coro = coroutine;
28 _queue.push_back(&_awaitable);
29 }
30
31 inline auto await_resume() const noexcept -> StageObject&
32 {
33 return *reinterpret_cast<StageObject*>(_awaitable.result.ptr);
34 }
35
38 };
39
40 template<>
41 struct TaskStageAwaitable<void>
42 {
43 inline explicit TaskStageAwaitable(ice::TaskQueue& queue) noexcept
44 : _awaitable{ ._params{.modifier = TaskAwaitableModifier::Unused} }
45 , _queue{ queue }
46 { }
47
48 inline bool await_ready() const noexcept
49 {
50 return false;
51 }
52
53 inline auto await_suspend(ice::coroutine_handle<> coroutine) noexcept
54 {
55 _awaitable._coro = coroutine;
56 _queue.push_back(&_awaitable);
57 }
58
59 inline void await_resume() const noexcept
60 {
61 }
62
65 };
66
67 template<typename StageResult = void>
68 struct TaskStage
69 {
71
72 inline auto operator co_await() const noexcept -> ice::TaskStageAwaitable<StageResult>
73 {
75 }
76 };
77
78} // namespace ice
Definition task_queue.hxx:13
Definition queue.hxx:111
SPDX-License-Identifier: MIT.
Definition array.hxx:12
@ Unused
Definition task_awaitable.hxx:13
std::coroutine_handle< Type > coroutine_handle
Definition task_types.hxx:42
Definition task_awaitable.hxx:36
ice::TaskQueue & _queue
Definition task_stage.hxx:64
auto await_suspend(ice::coroutine_handle<> coroutine) noexcept
Definition task_stage.hxx:53
ice::TaskAwaitableBase _awaitable
Definition task_stage.hxx:63
TaskStageAwaitable(ice::TaskQueue &queue) noexcept
Definition task_stage.hxx:43
bool await_ready() const noexcept
Definition task_stage.hxx:48
void await_resume() const noexcept
Definition task_stage.hxx:59
Definition task_stage.hxx:14
ice::TaskAwaitableBase _awaitable
Definition task_stage.hxx:36
auto await_resume() const noexcept -> StageObject &
Definition task_stage.hxx:31
bool await_ready() const noexcept
Definition task_stage.hxx:20
TaskStageAwaitable(ice::TaskQueue &queue) noexcept
Definition task_stage.hxx:15
auto await_suspend(ice::coroutine_handle<> coroutine) noexcept
Definition task_stage.hxx:25
ice::TaskQueue & _queue
Definition task_stage.hxx:37
Definition task_stage.hxx:69
ice::TaskQueue & _queue
Definition task_stage.hxx:70