Mountain
1.0.0
Simple C++ 2D Game Framework
|
Wrapper around C++20 Coroutines. More...
#include <coroutine.hpp>
Classes | |
struct | promise_type |
Promise type for C++20 coroutines. More... | |
Public Types | |
using | AwaitType = std::chrono::duration< double_t > |
Default duration type for Coroutine wait, equivalent to floating-point seconds. | |
using | HandleType = std::coroutine_handle< promise_type > |
The coroutine handle type. | |
Public Member Functions | |
MOUNTAIN_API | Coroutine (HandleType handle) |
Constructs a new Coroutine from the given handle. | |
MOUNTAIN_API Coroutine & | operator= (HandleType handle) noexcept |
Coroutine (const Coroutine &)=delete | |
Coroutine & | operator= (const Coroutine &)=delete |
MOUNTAIN_API | Coroutine (Coroutine &&other) noexcept |
MOUNTAIN_API Coroutine & | operator= (Coroutine &&other) noexcept |
MOUNTAIN_API void | Resume () const |
Resumes the Coroutine. More... | |
MOUNTAIN_API void | ResumeSafe () const |
Safely resumes the Coroutine by first checking if Valid() is true . More... | |
MOUNTAIN_API bool_t | Finished () const |
Returns whether the Coroutine finished its execution. More... | |
MOUNTAIN_API bool_t | FinishedSafe () const |
Safely returns whether the Coroutine finished its execution by first checking if Valid() is true . More... | |
MOUNTAIN_API void | Destroy () |
Destroys the Coroutine. It can't be resumed afterward. More... | |
MOUNTAIN_API void | DestroySafe () |
Safely destroys the Coroutine by first checking if Valid() is true . More... | |
MOUNTAIN_API bool_t | Valid () const |
Gets whether the Coroutine is valid, e.g. if it hasn't been default-initialized. More... | |
MOUNTAIN_API void | Reset () |
Resets the Coroutine. More... | |
MOUNTAIN_API Guid | GetId () const |
Returns the Guid of this Coroutine. | |
Static Public Member Functions | |
static MOUNTAIN_API Guid | Start (Coroutine &&coroutine) |
static MOUNTAIN_API void | Start (Coroutine &&coroutine, Guid *coroutineId) |
Starts a coroutine using an existing coroutine Guid. More... | |
static MOUNTAIN_API void | UpdateAll () |
static MOUNTAIN_API void | Stop (const Guid &coroutineId) |
static MOUNTAIN_API void | StopAll () |
static MOUNTAIN_API bool_t | IsRunning (const Guid &coroutineId) |
static MOUNTAIN_API bool_t | IsRunningAndNotEmpty (const Guid &coroutineId) |
static MOUNTAIN_API size_t | GetRunningCount () |
Wrapper around C++20 Coroutines.
Example Coroutine usage:
Instead of manually resuming the Coroutine, the framework can do it for you:
And the Coroutine will be resumed automatically each frame. Use the returned Guid
with the static functions in the Coroutine class.
Definition at line 61 of file coroutine.hpp.
MOUNTAIN_API void Mountain::Coroutine::Destroy | ( | ) |
Destroys the Coroutine. It can't be resumed afterward.
Valid()
is false
, this is undefined behavior. Consider using DestroySafe()
instead. MOUNTAIN_API void Mountain::Coroutine::DestroySafe | ( | ) |
MOUNTAIN_API bool_t Mountain::Coroutine::Finished | ( | ) | const |
Returns whether the Coroutine finished its execution.
Valid()
is false
, this is undefined behavior. Consider using FinishedSafe()
instead. MOUNTAIN_API bool_t Mountain::Coroutine::FinishedSafe | ( | ) | const |
Safely returns whether the Coroutine finished its execution by first checking if Valid()
is true
.
If Valid()
is false
, returns false
.
Finished()
MOUNTAIN_API void Mountain::Coroutine::Reset | ( | ) |
MOUNTAIN_API void Mountain::Coroutine::Resume | ( | ) | const |
Resumes the Coroutine.
Valid()
is false
, this is undefined behavior. Consider using ResumeSafe()
instead. MOUNTAIN_API void Mountain::Coroutine::ResumeSafe | ( | ) | const |
|
static |
Starts a coroutine using an existing coroutine Guid.
This stops the existing coroutine if it is still running and assigns the guid with a newly created one.
MOUNTAIN_API bool_t Mountain::Coroutine::Valid | ( | ) | const |