1 #ifndef ENTT_PROCESS_PROCESS_HPP
2 #define ENTT_PROCESS_PROCESS_HPP
7 #include "../config/config.h"
8 #include "../core/type_traits.hpp"
73 template<
typename Derived,
typename Delta>
75 enum class state: unsigned int {
85 template<
typename Target = Derived>
87 -> decltype(std::declval<Target>().init(),
void()) {
88 static_cast<Target *
>(
this)->init();
91 template<
typename Target = Derived>
93 -> decltype(std::declval<Target>().update(delta, data),
void()) {
94 static_cast<Target *
>(
this)->update(delta, data);
97 template<
typename Target = Derived>
99 -> decltype(std::declval<Target>().succeeded(),
void()) {
100 static_cast<Target *
>(
this)->succeeded();
103 template<
typename Target = Derived>
105 -> decltype(std::declval<Target>().failed(),
void()) {
106 static_cast<Target *
>(
this)->failed();
109 template<
typename Target = Derived>
111 -> decltype(std::declval<Target>().aborted(),
void()) {
112 static_cast<Target *
>(
this)->aborted();
115 void next(...)
const ENTT_NOEXCEPT {}
126 current = state::SUCCEEDED;
138 current = state::FAILED;
149 if(current == state::RUNNING) {
150 current = state::PAUSED;
161 if(current == state::PAUSED) {
162 current = state::RUNNING;
172 static_assert(std::is_base_of_v<process, Derived>,
"Incorrect use of the class template");
183 void abort(
const bool immediately =
false) {
185 current = state::ABORTED;
197 [[nodiscard]]
bool alive() const ENTT_NOEXCEPT {
198 return current == state::RUNNING || current == state::PAUSED;
205 [[nodiscard]]
bool dead() const ENTT_NOEXCEPT {
206 return current == state::FINISHED;
213 [[nodiscard]]
bool paused() const ENTT_NOEXCEPT {
214 return current == state::PAUSED;
221 [[nodiscard]]
bool rejected() const ENTT_NOEXCEPT {
230 void tick(
const Delta delta,
void *data =
nullptr) {
232 case state::UNINITIALIZED:
234 current = state::RUNNING;
246 case state::SUCCEEDED:
248 current = state::FINISHED;
252 current = state::FINISHED;
257 current = state::FINISHED;
267 state current{state::UNINITIALIZED};
311 template<
typename Func,
typename Delta>
318 template<
typename... Args>
320 : Func{std::forward<Args>(args)...}
328 void update(
const Delta delta,
void *data) {
329 Func::operator()(delta, data, [
this]() { this->
succeed(); }, [
this]() { this->
fail(); });