-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBehaviorTreeEvent.cpp
More file actions
54 lines (45 loc) · 808 Bytes
/
Copy pathBehaviorTreeEvent.cpp
File metadata and controls
54 lines (45 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "pch.h"
#include "BehaviorTreeEvent.h"
#include<assert.h>
using namespace BTEvent;
void BehaviorTree::Tick()
{
Behaviors.push_back(nullptr);
while (Step())
{
}
}
bool BehaviorTree :: Step()
{
Behavior* Current = Behaviors.front();
Behaviors.pop_front();
if (Current == nullptr)
return false;
Current->Tick();
if (Current->IsTerminate() && Current->Observer)
{
Current->Observer(Current->GetStatus());
}
else
{
Behaviors.push_back(Current);
}
return true;
}
void BehaviorTree::Start(Behavior* Bh, BehaviorObserver* Observe)
{
if (Observe)
{
Bh->Observer = *Observe;
}
Behaviors.push_front(Bh);
}
void BehaviorTree::Stop(Behavior* Bh, EStatus Result)
{
assert(Result != EStatus::Running);
Bh->SetStatus(Result);
if (Bh->Observer)
{
Bh->Observer(Result);
}
}