![]() |
KTech 1.1.0
C++ 2D terminal game engine library
|
Calls a function after a given time. More...
#include <invocation.hpp>
Public Member Functions | |
| Invocation (Engine &engine, const std::function< bool()> &callback) | |
Construct an Invocation. | |
| ~Invocation () | |
Safely deregister invocation from Time. | |
| void | Invoke (long time, Measurement measurement) |
| Invoke your callback function. | |
| void | Cancel () |
| Cancel the current invocation. | |
Public Attributes | |
| Engine & | engine |
Parent Engine. | |
| std::function< bool()> | m_callback |
| Function to invoke. | |
| bool | m_active = false |
Whether currently invoked (true: invoked, false: stationary). | |
| long | m_timePassed = 0 |
| How much time (in microseconds) actually passed since invocation started until now (if active), or until invocation ended (if inactive). | |
| long | m_duration = 0 |
| How much time (in microseconds) should pass before your function gets called (if active), or 0 (if inactive). | |
Calls a function after a given time.
This class uses RAII to prevent cases where your member functions are called after their parent structure was deconstructed from memory.
For example:
| KTech::Time::Invocation::Invocation | ( | Engine & | engine, |
| const std::function< bool()> & | callback ) |
Construct an Invocation.
| engine | Parent Engine. |
| callback | Your callback function. It should return a bool explained in Output::ShouldRenderThisTick(). |
Output::ShouldRenderThisTick() | void KTech::Time::Invocation::Invoke | ( | long | time, |
| Measurement | measurement ) |
Invoke your callback function.
Can be invoked once at a time. Meaning, invoking while already invoked will restart the current invocation (rather than ). For example:
| time | Duration to wait for before calling your function. |
| measurement | The time measurement for your given time. |
Time::Measurement