6 #include <unordered_map> 8 #include "Mountain/core.hpp" 108 MOUNTAIN_API bool_t await_ready();
111 MOUNTAIN_API
void await_suspend(std::coroutine_handle<promise_type>);
114 MOUNTAIN_API
void await_resume();
117 MOUNTAIN_API
static inline std::unordered_map<Guid, Coroutine> m_RunningRoutines;
128 MOUNTAIN_API
static void Start(
Coroutine&& coroutine,
Guid* coroutineId);
130 MOUNTAIN_API
static void UpdateAll();
132 MOUNTAIN_API
static void Stop(
const Guid& coroutineId);
134 MOUNTAIN_API
static void StopAll();
137 MOUNTAIN_API
static bool_t IsRunning(
const Guid& coroutineId);
140 MOUNTAIN_API
static bool_t IsRunningAndNotEmpty(
const Guid& coroutineId);
143 MOUNTAIN_API
static size_t GetRunningCount();
167 MOUNTAIN_API
void Resume()
const;
176 MOUNTAIN_API bool_t
Finished()
const;
197 MOUNTAIN_API bool_t
Valid()
const;
201 MOUNTAIN_API
void Reset();
216 template <
typename... Args>
MOUNTAIN_API bool_t FinishedSafe() const
Safely returns whether the Coroutine finished its execution by first checking if Valid() is true...
MOUNTAIN_API Awaitable await_transform(const AwaitType &duration)
Converts a AwaitType value to an Awaitable. Called when co_await is used with an AwaitType value...
MOUNTAIN_API bool_t Finished() const
Returns whether the Coroutine finished its execution.
std::coroutine_handle< promise_type > HandleType
The coroutine handle type.
AwaitType awaitValue
The last co_await value.
MOUNTAIN_API Guid GetId() const
Returns the Guid of this Coroutine.
MOUNTAIN_API void return_void()
Called when co_return is used in a Coroutine body. Empty implementation.
std::function< Coroutine(Args...)> CoroutineFunction
Coroutine function prototype.
MOUNTAIN_API void Destroy()
Destroys the Coroutine. It can't be resumed afterward.
Wrapper around C++20 Coroutines.
MOUNTAIN_API std::suspend_always final_suspend() noexcept
Empty implementation.
MOUNTAIN_API bool_t Valid() const
Gets whether the Coroutine is valid, e.g. if it hasn't been default-initialized.
MOUNTAIN_API std::suspend_always initial_suspend()
Empty implementation.
MOUNTAIN_API void DestroySafe()
Safely destroys the Coroutine by first checking if Valid() is true.
MOUNTAIN_API std::suspend_always yield_value(nullptr_t)
Yields the coroutine using a nullptr value. The coroutine will be resumed on the next frame...
MOUNTAIN_API void unhandled_exception()
Logs the exception and rethrows it.
MOUNTAIN_API void ResumeSafe() const
Safely resumes the Coroutine by first checking if Valid() is true.
MOUNTAIN_API void Reset()
Resets the Coroutine.
Defines the Mountain::Guid class.
Stands for Global Unique Identifier, it represents a unique ID that's used to link pointers during se...
MOUNTAIN_API Coroutine get_return_object()
Returns the object that will be returns to the caller of a CoroutineFunc.
MOUNTAIN_API void Resume() const
Resumes the Coroutine.
std::chrono::duration< double_t > AwaitType
Default duration type for Coroutine wait, equivalent to floating-point seconds.
Promise type for C++20 coroutines.
Contains all declarations of the Mountain Framework.