NoJobEngine
2.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
BTTree.h
Go to the documentation of this file.
1
6
#pragma once
7
#include "
BTNode.h
"
8
#include <memory>
9
#include <stdexcept>
10
#include <unordered_set>
11
#include <vector>
12
13
namespace
NoJob
{
14
class
BTTree
{
15
public
:
16
explicit
BTTree
(std::unique_ptr<BTNode> root) : m_Root(std::move(root)) {
17
if
(!m_Root)
throw
std::invalid_argument(
"Behavior Tree requires a root"
);
18
std::unordered_set<BTNodeID> ids;
19
std::vector<const BTNode*> pending{m_Root.get()};
20
while
(!pending.empty()) {
21
const BTNode* node = pending.back();
22
pending.pop_back();
23
if (node->GetID() == 0 || !ids.insert(node->GetID()).second)
24
throw std::invalid_argument(
"Behavior Tree has zero or duplicate node ID"
);
25
node->CollectChildren(pending);
26
}
27
}
28
const
BTNode
&
Root
()
const
{
return
*m_Root; }
29
private
:
30
std::unique_ptr<BTNode> m_Root;
31
};
32
}
BTNode.h
Base interface for behavior tree nodes.
NoJob::BTNode
Base class for behavior tree nodes with stable node identifiers.
Definition
BTNode.h:15
NoJob::BTTree::BTTree
BTTree(std::unique_ptr< BTNode > root)
Definition
BTTree.h:16
NoJob::BTTree::Root
const BTNode & Root() const
Definition
BTTree.h:28
NoJob
Definition
BTActionNode.h:13
Engine
AI
BehaviorTree
BTTree.h
Generated by
1.18.0