Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #89 (Guarded task start() method running before guard) #127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[1.8.3-SNAPSHOT]
- Updated to libgdx 1.11.0
- Start guarded task only if the guard succeeds

[1.8.2]
- Updated to libgdx 1.9.8
Expand Down
8 changes: 4 additions & 4 deletions gdx-ai/src/com/badlogic/gdx/ai/btree/BehaviorTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
8 changes: 4 additions & 4 deletions gdx-ai/src/com/badlogic/gdx/ai/btree/Decorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
8 changes: 4 additions & 4 deletions gdx-ai/src/com/badlogic/gdx/ai/btree/LoopDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 9 additions & 9 deletions gdx-ai/src/com/badlogic/gdx/ai/btree/branch/Parallel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.<br>
* Its actual behavior depends on its {@link #orchestrator} and {@link #policy}.<br>
* <br>
* The execution of the parallel task's children depends on its {@link #orchestrator}:
* <ul>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down