NoJobEngine 2.0.7
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
13namespace NoJob {
14class BTTree {
15public:
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; }
29private:
30 std::unique_ptr<BTNode> m_Root;
31};
32}
Base interface for behavior tree nodes.
Base class for behavior tree nodes with stable node identifiers.
Definition BTNode.h:15
BTTree(std::unique_ptr< BTNode > root)
Definition BTTree.h:16
const BTNode & Root() const
Definition BTTree.h:28