Просмотр исходного кода

process: pass directly the base process to callbacks

skypjack 8 месяцев назад
Родитель
Сommit
cec550ad11
3 измененных файлов с 14 добавлено и 14 удалено
  1. 1 1
      src/entt/process/process.hpp
  2. 6 6
      test/entt/process/process.cpp
  3. 7 7
      test/entt/process/scheduler.cpp

+ 1 - 1
src/entt/process/process.hpp

@@ -300,7 +300,7 @@ struct basic_process_adaptor: public basic_process<Delta> {
      * @param data Optional data.
      */
     void update(const delta_type delta, void *data) override {
-        func(delta, data, [this]() { this->succeed(); }, [this]() { this->fail(); });
+        func(delta, data, *this);
     }
 
 private:

+ 6 - 6
test/entt/process/process.cpp

@@ -201,10 +201,10 @@ TEST(Process, ThenPeek) {
 
 TEST(ProcessAdaptor, Resolved) {
     bool updated = false;
-    auto lambda = [&updated](std::uint32_t, void *, auto resolve, auto) {
+    auto lambda = [&updated](std::uint32_t, void *, auto &proc) {
         ASSERT_FALSE(updated);
         updated = true;
-        resolve();
+        proc.succeed();
     };
 
     entt::process_adaptor<decltype(lambda)> process{lambda};
@@ -218,10 +218,10 @@ TEST(ProcessAdaptor, Resolved) {
 
 TEST(ProcessAdaptor, Rejected) {
     bool updated = false;
-    auto lambda = [&updated](std::uint32_t, void *, auto, auto rejected) {
+    auto lambda = [&updated](std::uint32_t, void *, auto &proc) {
         ASSERT_FALSE(updated);
         updated = true;
-        rejected();
+        proc.fail();
     };
 
     entt::process_adaptor<decltype(lambda)> process{lambda};
@@ -235,9 +235,9 @@ TEST(ProcessAdaptor, Rejected) {
 
 TEST(ProcessAdaptor, Data) {
     int value = 0;
-    auto lambda = [](std::uint32_t, void *data, auto resolve, auto) {
+    auto lambda = [](std::uint32_t, void *data, auto &proc) {
         *static_cast<int *>(data) = 2;
-        resolve();
+        proc.succeed();
     };
 
     entt::process_adaptor<decltype(lambda)> process{lambda};

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

@@ -138,19 +138,19 @@ TEST(Scheduler, Functor) {
     bool first_functor = false;
     bool second_functor = false;
 
-    auto attach = [&first_functor](auto, void *, auto resolve, auto) {
+    auto attach = [&first_functor](auto, void *, auto &proc) {
         ASSERT_FALSE(first_functor);
         first_functor = true;
-        resolve();
+        proc.succeed();
     };
 
-    auto then = [&second_functor](auto, void *, auto, auto reject) {
+    auto then = [&second_functor](auto, void *, auto &proc) {
         ASSERT_FALSE(second_functor);
         second_functor = true;
-        reject();
+        proc.fail();
     };
 
-    scheduler.attach(std::move(attach)).then(std::move(then)).then([](auto...) { FAIL(); });
+    scheduler.attach(std::move(attach)).then(std::move(then)).then([](auto &&...) { FAIL(); });
 
     while(!scheduler.empty()) {
         scheduler.update(0);
@@ -165,9 +165,9 @@ TEST(Scheduler, SpawningProcess) {
     entt::scheduler scheduler{};
     std::pair<int, int> counter{};
 
-    scheduler.attach([&scheduler](auto, void *, auto resolve, auto) {
+    scheduler.attach([&scheduler](auto, void *, auto &proc) {
         scheduler.attach<succeeded_process>().then<failed_process>();
-        resolve();
+        proc.succeed();
     });
 
     while(!scheduler.empty()) {