NoJobEngine
2.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
BTSequence.h
Go to the documentation of this file.
1
6
#pragma once
7
#include "
BTNode.h
"
8
#include <memory>
9
#include <utility>
10
#include <vector>
11
12
namespace
NoJob
{
13
class
BTSequence
final :
public
BTNode
{
14
public
:
15
explicit
BTSequence
(
BTNodeID
id
) :
BTNode
(id) {}
16
void
AddChild
(std::unique_ptr<BTNode> child) {
17
if
(child) m_Children.push_back(std::move(child));
18
}
19
std::string
DebugLabel
()
const override
{
return
"Sequence"
; }
20
BTStatus
Tick
(
BTContext
& context,
float
dt)
const override
{
21
while
(
true
) {
22
const
auto
index = context.
GetNodeState
(
GetID
()).
CurrentChild
;
23
if
(index >= m_Children.size()) {
24
Reset
(context);
25
return
BTStatus::Success
;
26
}
27
const
auto
status = m_Children[index]->Tick(context, dt);
28
if
(status ==
BTStatus::Running
)
return
BTStatus::Running
;
29
if
(status ==
BTStatus::Failure
) {
30
Reset
(context);
31
return
BTStatus::Failure
;
32
}
33
context.
GetNodeState
(
GetID
()).
CurrentChild
= index + 1;
34
}
35
}
36
void
Reset
(
BTContext
& context)
const override
{
37
for
(
const
auto
& child : m_Children) child->Reset(context);
38
BTNode::Reset
(context);
39
}
40
void
CollectChildren
(std::vector<const BTNode*>& out)
const override
{
41
for
(
const
auto
& child : m_Children) out.push_back(child.get());
42
}
43
private
:
44
std::vector<std::unique_ptr<BTNode>> m_Children;
45
};
46
}
BTNode.h
Base interface for behavior tree nodes.
NoJob::BTContext
Definition
BTContext.h:24
NoJob::BTContext::GetNodeState
BTNodeRuntimeState & GetNodeState(BTNodeID id)
Definition
BTContext.h:44
NoJob::BTNode::Reset
virtual void Reset(BTContext &context) const
Definition
BTNode.h:28
NoJob::BTNode::BTNode
BTNode(BTNodeID id)
Definition
BTNode.h:17
NoJob::BTNode::GetID
BTNodeID GetID() const
Definition
BTNode.h:21
NoJob::BTSequence::AddChild
void AddChild(std::unique_ptr< BTNode > child)
Definition
BTSequence.h:16
NoJob::BTSequence::BTSequence
BTSequence(BTNodeID id)
Definition
BTSequence.h:15
NoJob::BTSequence::Tick
BTStatus Tick(BTContext &context, float dt) const override
Evaluates this node for one update.
Definition
BTSequence.h:20
NoJob::BTSequence::Reset
void Reset(BTContext &context) const override
Definition
BTSequence.h:36
NoJob::BTSequence::DebugLabel
std::string DebugLabel() const override
Definition
BTSequence.h:19
NoJob::BTSequence::CollectChildren
void CollectChildren(std::vector< const BTNode * > &out) const override
Definition
BTSequence.h:40
NoJob
Definition
BTActionNode.h:13
NoJob::BTNodeID
std::uint64_t BTNodeID
Definition
BTContext.h:19
NoJob::BTStatus
BTStatus
Result of a behavior tree node tick.
Definition
BTNode.h:13
NoJob::BTStatus::Success
@ Success
Definition
BTNode.h:13
NoJob::BTStatus::Running
@ Running
Definition
BTNode.h:13
NoJob::BTStatus::Failure
@ Failure
Definition
BTNode.h:13
NoJob::BTNodeRuntimeState::CurrentChild
std::size_t CurrentChild
Definition
BTContext.h:21
Engine
AI
BehaviorTree
BTSequence.h
Generated by
1.18.0