diff --git a/src/entt/process/scheduler.hpp b/src/entt/process/scheduler.hpp index 23c76427d..c6bd97eb2 100644 --- a/src/entt/process/scheduler.hpp +++ b/src/entt/process/scheduler.hpp @@ -7,6 +7,7 @@ #include #include #include +#include "fwd.hpp" #include "process.hpp" namespace entt { @@ -38,11 +39,11 @@ namespace entt { * @tparam Delta Type to use to provide elapsed time. */ template -class scheduler { +class basic_scheduler { struct process_handler { using instance_type = std::unique_ptr; - using update_fn_type = bool(scheduler &, std::size_t, Delta, void *); - using abort_fn_type = void(scheduler &, std::size_t, bool); + using update_fn_type = bool(basic_scheduler &, std::size_t, Delta, void *); + using abort_fn_type = void(basic_scheduler &, std::size_t, bool); using next_type = std::unique_ptr; instance_type instance; @@ -58,8 +59,8 @@ class scheduler { template continuation then(Args &&...args) { static_assert(std::is_base_of_v, Proc>, "Invalid process type"); - auto proc = typename process_handler::instance_type{new Proc{std::forward(args)...}, &scheduler::deleter}; - handler->next.reset(new process_handler{std::move(proc), &scheduler::update, &scheduler::abort, nullptr}); + auto proc = typename process_handler::instance_type{new Proc{std::forward(args)...}, &basic_scheduler::deleter}; + handler->next.reset(new process_handler{std::move(proc), &basic_scheduler::update, &basic_scheduler::abort, nullptr}); handler = handler->next.get(); return *this; } @@ -74,7 +75,7 @@ class scheduler { }; template - [[nodiscard]] static bool update(scheduler &owner, std::size_t pos, const Delta delta, void *data) { + [[nodiscard]] static bool update(basic_scheduler &owner, std::size_t pos, const Delta delta, void *data) { auto *process = static_cast(owner.handlers[pos].instance.get()); process->tick(delta, data); @@ -94,7 +95,7 @@ class scheduler { } template - static void abort(scheduler &owner, std::size_t pos, const bool immediately) { + static void abort(basic_scheduler &owner, std::size_t pos, const bool immediately) { static_cast(owner.handlers[pos].instance.get())->abort(immediately); } @@ -104,18 +105,20 @@ class scheduler { } public: + /*! @brief Unsigned integer type. */ + using delta_type = Delta; /*! @brief Unsigned integer type. */ using size_type = std::size_t; /*! @brief Default constructor. */ - scheduler() + basic_scheduler() : handlers{} {} /*! @brief Default move constructor. */ - scheduler(scheduler &&) = default; + basic_scheduler(basic_scheduler &&) = default; /*! @brief Default move assignment operator. @return This scheduler. */ - scheduler &operator=(scheduler &&) = default; + basic_scheduler &operator=(basic_scheduler &&) = default; /** * @brief Number of processes currently scheduled. @@ -171,8 +174,8 @@ public: template auto attach(Args &&...args) { static_assert(std::is_base_of_v, Proc>, "Invalid process type"); - auto proc = typename process_handler::instance_type{new Proc{std::forward(args)...}, &scheduler::deleter}; - auto &&ref = handlers.emplace_back(process_handler{std::move(proc), &scheduler::update, &scheduler::abort, nullptr}); + auto proc = typename process_handler::instance_type{new Proc{std::forward(args)...}, &basic_scheduler::deleter}; + auto &&ref = handlers.emplace_back(process_handler{std::move(proc), &basic_scheduler::update, &basic_scheduler::abort, nullptr}); // forces the process to exit the uninitialized state ref.update(*this, handlers.size() - 1u, {}, nullptr); return continuation{&handlers.back()}; @@ -246,7 +249,7 @@ public: * @param delta Elapsed time. * @param data Optional data. */ - void update(const Delta delta, void *data = nullptr) { + void update(const delta_type delta, void *data = nullptr) { for(auto pos = handlers.size(); pos; --pos) { const auto curr = pos - 1u; diff --git a/test/entt/process/scheduler.cpp b/test/entt/process/scheduler.cpp index c08c44ca5..21487a685 100644 --- a/test/entt/process/scheduler.cpp +++ b/test/entt/process/scheduler.cpp @@ -4,7 +4,7 @@ #include #include -struct foo_process: entt::process { +struct foo_process: entt::process { foo_process(std::function upd, std::function abort) : on_update{upd}, on_aborted{abort} {} @@ -20,7 +20,7 @@ struct foo_process: entt::process { std::function on_aborted; }; -struct succeeded_process: entt::process { +struct succeeded_process: entt::process { void update(delta_type, void *) { ++invoked; succeed(); @@ -29,7 +29,7 @@ struct succeeded_process: entt::process { static inline unsigned int invoked; }; -struct failed_process: entt::process { +struct failed_process: entt::process { void update(delta_type, void *) { ++invoked; fail(); @@ -46,7 +46,7 @@ struct Scheduler: ::testing::Test { }; TEST_F(Scheduler, Functionalities) { - entt::scheduler scheduler{}; + entt::scheduler scheduler{}; bool updated = false; bool aborted = false; @@ -77,7 +77,7 @@ TEST_F(Scheduler, Functionalities) { } TEST_F(Scheduler, Then) { - entt::scheduler scheduler; + entt::scheduler scheduler; // failing process with successor scheduler.attach() @@ -106,7 +106,7 @@ TEST_F(Scheduler, Then) { } TEST_F(Scheduler, Functor) { - entt::scheduler scheduler; + entt::scheduler scheduler; bool first_functor = false; bool second_functor = false; @@ -135,7 +135,7 @@ TEST_F(Scheduler, Functor) { } TEST_F(Scheduler, SpawningProcess) { - entt::scheduler scheduler; + entt::scheduler scheduler; scheduler.attach([&scheduler](auto, void *, auto resolve, auto) { scheduler.attach().then();