From 8e68cb469917850566743fb8da95dce9864b3099 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Tue, 31 Jan 2023 17:50:47 +0330 Subject: [PATCH 1/3] Execute task.start() only if the guard succeeds. --- .../com/badlogic/gdx/ai/btree/BehaviorTree.java | 8 ++++---- .../src/com/badlogic/gdx/ai/btree/Decorator.java | 8 ++++---- .../com/badlogic/gdx/ai/btree/LoopDecorator.java | 8 ++++---- .../gdx/ai/btree/SingleRunningChildBranch.java | 7 ++++--- .../badlogic/gdx/ai/btree/branch/Parallel.java | 16 ++++++++-------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/gdx-ai/src/com/badlogic/gdx/ai/btree/BehaviorTree.java b/gdx-ai/src/com/badlogic/gdx/ai/btree/BehaviorTree.java index aab24e7b..496d3f9e 100644 --- a/gdx-ai/src/com/badlogic/gdx/ai/btree/BehaviorTree.java +++ b/gdx-ai/src/com/badlogic/gdx/ai/btree/BehaviorTree.java @@ -119,11 +119,11 @@ public void step () { rootTask.run(); } else { rootTask.setControl(this); - rootTask.start(); - if (rootTask.checkGuard(this)) + if (rootTask.checkGuard(this)) { + rootTask.start(); rootTask.run(); - else - rootTask.fail(); + } else + childFail(null); // actually child has not failed but child guard has failed } } diff --git a/gdx-ai/src/com/badlogic/gdx/ai/btree/Decorator.java b/gdx-ai/src/com/badlogic/gdx/ai/btree/Decorator.java index f38b18c3..fcfb4ce1 100644 --- a/gdx-ai/src/com/badlogic/gdx/ai/btree/Decorator.java +++ b/gdx-ai/src/com/badlogic/gdx/ai/btree/Decorator.java @@ -66,11 +66,11 @@ public void run () { child.run(); } else { child.setControl(this); - child.start(); - if (child.checkGuard(this)) + if (child.checkGuard(this)) { + child.start(); child.run(); - else - child.fail(); + } else + childFail(null); // actually child has not failed but child guard has failed } } diff --git a/gdx-ai/src/com/badlogic/gdx/ai/btree/LoopDecorator.java b/gdx-ai/src/com/badlogic/gdx/ai/btree/LoopDecorator.java index 0e60a68e..f5fa7d92 100644 --- a/gdx-ai/src/com/badlogic/gdx/ai/btree/LoopDecorator.java +++ b/gdx-ai/src/com/badlogic/gdx/ai/btree/LoopDecorator.java @@ -51,11 +51,11 @@ public void run () { child.run(); } else { child.setControl(this); - child.start(); - if (child.checkGuard(this)) + if (child.checkGuard(this)) { + child.start(); child.run(); - else - child.fail(); + } else + childFail(null); // actually child has not failed but child guard has failed } } } diff --git a/gdx-ai/src/com/badlogic/gdx/ai/btree/SingleRunningChildBranch.java b/gdx-ai/src/com/badlogic/gdx/ai/btree/SingleRunningChildBranch.java index 0c4ce74b..30a75363 100644 --- a/gdx-ai/src/com/badlogic/gdx/ai/btree/SingleRunningChildBranch.java +++ b/gdx-ai/src/com/badlogic/gdx/ai/btree/SingleRunningChildBranch.java @@ -84,11 +84,12 @@ public void run () { runningChild = children.get(currentChildIndex); } runningChild.setControl(this); - runningChild.start(); if (!runningChild.checkGuard(this)) - runningChild.fail(); - else + childFail(null); // actually child has not failed but child guard has failed + else { + runningChild.start(); run(); + } } else { // Should never happen; this case must be handled by subclasses in childXXX methods } diff --git a/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java b/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java index 95a7f6ba..548173b7 100644 --- a/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java +++ b/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java @@ -173,11 +173,11 @@ public void execute(Parallel parallel) { child.run(); } else { child.setControl(parallel); - child.start(); - if (child.checkGuard(parallel)) + if (child.checkGuard(parallel)) { + child.start(); child.run(); - else - child.fail(); + } else + parallel.childFail(null); // actually child has not failed but child guard has failed } if (parallel.lastResult != null) { // Current child has finished either with success or fail @@ -210,11 +210,11 @@ public void execute(Parallel parallel) { break; default: child.setControl(parallel); - child.start(); - if (child.checkGuard(parallel)) + if (child.checkGuard(parallel)) { + child.start(); child.run(); - else - child.fail(); + } else + parallel.childFail(null); // actually child has not failed but child guard has failed break; } From ea62ef3ddafcf1e8851fa74fc51918208a6487a5 Mon Sep 17 00:00:00 2001 From: Ali-RS Date: Tue, 31 Jan 2023 17:52:08 +0330 Subject: [PATCH 2/3] Fix javadoc --- gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java b/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java index 548173b7..f030b29c 100644 --- a/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java +++ b/gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java @@ -23,7 +23,7 @@ import com.badlogic.gdx.utils.Array; /** A {@code Parallel} is a special branch task that runs all children when stepped. - * Its actual behavior depends on its {@link orchestrator} and {@link policy}.
+ * Its actual behavior depends on its {@link #orchestrator} and {@link #policy}.
*
* The execution of the parallel task's children depends on its {@link #orchestrator}: *