Browse Source

scheduler: cleanup API

Michele Caini 8 months ago
parent
commit
21e82abfa7
2 changed files with 7 additions and 127 deletions
  1. 0 120
      src/entt/process/scheduler.hpp
  2. 7 7
      test/entt/process/scheduler.cpp

+ 0 - 120
src/entt/process/scheduler.hpp

@@ -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.
      *

+ 7 - 7
test/entt/process/scheduler.cpp

@@ -82,7 +82,7 @@ TEST(Scheduler, Swap) {
     entt::scheduler other{};
     int counter{};
 
-    scheduler.attach([&counter](auto &&...) { ++counter; });
+    scheduler.attach(entt::process_from([&counter](entt::process &, std::uint32_t, void *) { ++counter; }));
 
     ASSERT_EQ(scheduler.size(), 1u);
     ASSERT_EQ(other.size(), 0u);
@@ -130,19 +130,19 @@ TEST(Scheduler, Functor) {
     bool first_functor = false;
     bool second_functor = false;
 
-    auto attach = [&first_functor](auto &proc, auto, void *) {
+    auto attach = [&first_functor](entt::process &proc, std::uint32_t, void *) {
         ASSERT_FALSE(first_functor);
         first_functor = true;
         proc.succeed();
     };
 
-    auto then = [&second_functor](auto &proc, auto, void *) {
+    auto then = [&second_functor](entt::process &proc, std::uint32_t, void *) {
         ASSERT_FALSE(second_functor);
         second_functor = true;
         proc.fail();
     };
 
-    scheduler.attach(std::move(attach)).then(std::move(then)).then([](auto &&...) { FAIL(); });
+    scheduler.attach(entt::process_from(std::move(attach))->then(entt::process_from(std::move(then))->then(entt::process_from([](entt::process &, std::uint32_t, void *) { FAIL(); }))));
 
     while(!scheduler.empty()) {
         scheduler.update(0);
@@ -157,10 +157,10 @@ TEST(Scheduler, SpawningProcess) {
     entt::scheduler scheduler{};
     std::pair<int, int> counter{};
 
-    scheduler.attach([&scheduler](auto &proc, auto, void *) {
+    scheduler.attach(entt::process_from([&scheduler](entt::process &proc, std::uint32_t, void *) {
         scheduler.attach(std::make_shared<succeeded_process>()->then(std::make_shared<failed_process>()));
         proc.succeed();
-    });
+    }));
 
     while(!scheduler.empty()) {
         scheduler.update(0, &counter);
@@ -177,7 +177,7 @@ TEST(Scheduler, CustomAllocator) {
     ASSERT_EQ(scheduler.get_allocator(), allocator);
     ASSERT_FALSE(scheduler.get_allocator() != allocator);
 
-    scheduler.attach([](auto &&...) {});
+    scheduler.attach(entt::process_from([](entt::process &, std::uint32_t, void *) {}));
     const decltype(scheduler) other{std::move(scheduler), allocator};
 
     ASSERT_EQ(other.size(), 1u);