Skip to content

Commit 051d8af

Browse files
committed
Completion of parallel composite
1 parent c4f4cfd commit 051d8af

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

Assets/FluidBehaviorTree/Editor/Testing/ParentTasks/ParallelTest.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
namespace Adnc.FluidBT.Testing {
77
public class ParallelTest {
8-
public class UpdateMethod {
9-
private Parallel parallel;
8+
private Parallel parallel;
109

11-
[SetUp]
12-
public void SetParallel () {
13-
parallel = new Parallel();
14-
}
10+
[SetUp]
11+
public void SetParallel () {
12+
parallel = new Parallel();
13+
}
1514

15+
public class UpdateMethod : ParallelTest {
1616
public class OnSuccess : UpdateMethod {
1717
[SetUp]
1818
public void CreateTree () {
@@ -117,21 +117,42 @@ public void Runs_end_on_all_children_when_complete () {
117117
}
118118
}
119119

120-
public class EndMethod {
120+
public class EndMethod : ParallelTest {
121+
[Test]
121122
public void Ends_all_ongoing_tasks () {
123+
parallel
124+
.AddChild(A.TaskStub().Build())
125+
.AddChild(A.TaskStub().Build());
122126

123-
}
124-
125-
public void Does_not_end_any_tasks_if_called_before_update () {
127+
parallel.End();
126128

129+
parallel.children.ForEach((child) => child.Received(1).End());
127130
}
128131
}
129132

130-
public class ResetMethod {
133+
public class ResetMethod : ParallelTest {
134+
[Test]
131135
public void Does_not_recall_previous_node_status_after_usage () {
136+
parallel
137+
.AddChild(A.TaskStub().WithUpdateStatus(TaskStatus.Continue).Build())
138+
.AddChild(A.TaskStub().Build());
139+
140+
parallel.Update();
141+
parallel.Reset();
142+
parallel.Update();
143+
144+
parallel.children.ForEach((child) => child.Received(2).Update());
132145
}
133146

147+
[Test]
134148
public void Does_not_trigger_end_on_children () {
149+
parallel
150+
.AddChild(A.TaskStub().Build())
151+
.AddChild(A.TaskStub().Build());
152+
153+
parallel.Reset();
154+
155+
parallel.children.ForEach((child) => child.Received(0).End());
135156
}
136157
}
137158
}

Assets/FluidBehaviorTree/Scripts/TaskParents/Composites/Parallel.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,28 @@ protected override TaskStatus OnUpdate () {
3030
}
3131

3232
if (successCount == children.Count) {
33-
foreach (var child in children) {
34-
child.End();
35-
}
36-
33+
End();
3734
return TaskStatus.Success;
3835
}
3936

4037
if (failureCount > 0) {
41-
foreach (var child in children) {
42-
child.End();
43-
}
44-
38+
End();
4539
return TaskStatus.Failure;
4640
}
4741

4842
return TaskStatus.Continue;
4943
}
44+
45+
public override void Reset (bool hardReset = false) {
46+
_childStatus.Clear();
47+
48+
base.Reset(hardReset);
49+
}
50+
51+
public override void End () {
52+
foreach (var child in children) {
53+
child.End();
54+
}
55+
}
5056
}
5157
}

0 commit comments

Comments
 (0)