|
|
@@ -154,126 +154,6 @@ public:
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @brief Schedules a process for the next tick.
|
|
|
- *
|
|
|
- * Returned value can be used to attach a continuation for the last process.
|
|
|
- * The continutation is scheduled automatically when the process terminates
|
|
|
- * and only if the process returns with success.
|
|
|
- *
|
|
|
- * Example of use (pseudocode):
|
|
|
- *
|
|
|
- * @code{.cpp}
|
|
|
- * // schedules a task in the form of a process class
|
|
|
- * scheduler.attach<my_process>(arguments...)
|
|
|
- * // appends a child in the form of a lambda function
|
|
|
- * .then([](auto delta, void *, auto succeed, auto fail) {
|
|
|
- * // code
|
|
|
- * })
|
|
|
- * // appends a child in the form of another process class
|
|
|
- * .then<my_other_process>();
|
|
|
- * @endcode
|
|
|
- *
|
|
|
- * @tparam Proc Type of process to schedule.
|
|
|
- * @tparam Args Types of arguments to use to initialize the process.
|
|
|
- * @param args Parameters to use to initialize the process.
|
|
|
- * @return This process scheduler.
|
|
|
- */
|
|
|
- template<typename Proc, typename... Args>
|
|
|
- basic_scheduler &attach(Args &&...args) {
|
|
|
- handlers.first().emplace_back(std::allocate_shared<Proc>(handlers.second(), std::forward<Args>(args)...));
|
|
|
- return *this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @brief Schedules a process for the next tick.
|
|
|
- *
|
|
|
- * A process can be either a lambda or a functor. The scheduler wraps both
|
|
|
- * of them in a process adaptor internally.<br/>
|
|
|
- * The signature of the function call operator should be equivalent to the
|
|
|
- * following:
|
|
|
- *
|
|
|
- * @code{.cpp}
|
|
|
- * void(Delta delta, void *data, auto succeed, auto fail);
|
|
|
- * @endcode
|
|
|
- *
|
|
|
- * Where:
|
|
|
- *
|
|
|
- * * `delta` is the elapsed time.
|
|
|
- * * `data` is an opaque pointer to user data if any, `nullptr` otherwise.
|
|
|
- * * `succeed` is a function to call when a process terminates with success.
|
|
|
- * * `fail` is a function to call when a process terminates with errors.
|
|
|
- *
|
|
|
- * The signature of the function call operator of both `succeed` and `fail`
|
|
|
- * is equivalent to the following:
|
|
|
- *
|
|
|
- * @code{.cpp}
|
|
|
- * void();
|
|
|
- * @endcode
|
|
|
- *
|
|
|
- * Returned value can be used to attach a continuation for the last process.
|
|
|
- * The continutation is scheduled automatically when the process terminates
|
|
|
- * and only if the process returns with success.
|
|
|
- *
|
|
|
- * Example of use (pseudocode):
|
|
|
- *
|
|
|
- * @code{.cpp}
|
|
|
- * // schedules a task in the form of a lambda function
|
|
|
- * scheduler.attach([](auto delta, void *, auto succeed, auto fail) {
|
|
|
- * // code
|
|
|
- * })
|
|
|
- * // appends a child in the form of another lambda function
|
|
|
- * .then([](auto delta, void *, auto succeed, auto fail) {
|
|
|
- * // code
|
|
|
- * })
|
|
|
- * // appends a child in the form of a process class
|
|
|
- * .then<my_process>(arguments...);
|
|
|
- * @endcode
|
|
|
- *
|
|
|
- * @sa process_adaptor
|
|
|
- *
|
|
|
- * @tparam Func Type of process to schedule.
|
|
|
- * @param func Either a lambda or a functor to use as a process.
|
|
|
- * @return This process scheduler.
|
|
|
- */
|
|
|
- template<typename Func>
|
|
|
- basic_scheduler &attach(Func &&func) {
|
|
|
- using Proc = process_adaptor<Delta, std::decay_t<Func>>;
|
|
|
- return attach<Proc>(std::forward<Func>(func));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @brief Sets a process as a continuation of the last scheduled process.
|
|
|
- * @tparam Proc Type of process to use as a continuation.
|
|
|
- * @tparam Args Types of arguments to use to initialize the process.
|
|
|
- * @param args Parameters to use to initialize the process.
|
|
|
- * @return This process scheduler.
|
|
|
- */
|
|
|
- template<typename Proc, typename... Args>
|
|
|
- basic_scheduler &then(Args &&...args) {
|
|
|
- ENTT_ASSERT(!handlers.first().empty(), "Process not available");
|
|
|
- auto curr = handlers.first().back();
|
|
|
-
|
|
|
- for(auto child = curr->peek(); child; child = curr->peek()) {
|
|
|
- curr = child;
|
|
|
- }
|
|
|
-
|
|
|
- curr->then(std::allocate_shared<Proc>(handlers.second(), std::forward<Args>(args)...));
|
|
|
- return *this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @brief Sets a process as a continuation of the last scheduled process.
|
|
|
- * @tparam Func Type of process to use as a continuation.
|
|
|
- * @param func Either a lambda or a functor to use as a process.
|
|
|
- * @return This process scheduler.
|
|
|
- */
|
|
|
- template<typename Func>
|
|
|
- basic_scheduler &then(Func &&func) {
|
|
|
- using Proc = process_adaptor<Delta, std::decay_t<Func>>;
|
|
|
- return then<Proc>(std::forward<Func>(func));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @brief Updates all scheduled processes.
|
|
|
*
|