NoJobEngine
2.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
BTParallel.h
Go to the documentation of this file.
1
6
#pragma once
7
#include "
BTNode.h
"
8
#include <memory>
9
#include <stdexcept>
10
namespace
NoJob
{
11
// Main task and background task advance on the same frame, no threads.
12
class
BTParallel
final :
public
BTNode
{
13
public
:
14
BTParallel
(
BTNodeID
id
, std::unique_ptr<BTNode> mainTask, std::unique_ptr<BTNode> background)
15
:
BTNode
(id), m_Main(std::move(mainTask)), m_Background(std::move(background)) {
16
if
(!m_Main || !m_Background)
throw
std::invalid_argument(
"Parallel needs two children"
);
17
}
18
std::string
DebugLabel
()
const override
{
return
"Simple Parallel"
; }
19
BTStatus
Tick
(
BTContext
& ctx,
float
dt)
const override
{
20
const
auto
primary = m_Main->Tick(ctx, dt);
21
if
(primary ==
BTStatus::Running
) m_Background->Tick(ctx, dt);
22
else
Reset
(ctx);
23
ctx.
RecordStatus
(
GetID
(),
static_cast<
int
>
(primary));
24
return
primary;
25
}
26
void
Reset
(
BTContext
& ctx)
const override
{
27
m_Main->Reset(ctx); m_Background->Reset(ctx);
BTNode::Reset
(ctx);
28
}
29
void
CollectChildren
(std::vector<const BTNode*>& out)
const override
{
30
out.push_back(m_Main.get()); out.push_back(m_Background.get());
31
}
32
private
:
33
std::unique_ptr<BTNode> m_Main, m_Background;
34
};
35
}
BTNode.h
Base interface for behavior tree nodes.
NoJob::BTContext
Definition
BTContext.h:24
NoJob::BTContext::RecordStatus
void RecordStatus(BTNodeID id, int status)
Definition
BTContext.h:77
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::BTParallel::BTParallel
BTParallel(BTNodeID id, std::unique_ptr< BTNode > mainTask, std::unique_ptr< BTNode > background)
Definition
BTParallel.h:14
NoJob::BTParallel::CollectChildren
void CollectChildren(std::vector< const BTNode * > &out) const override
Definition
BTParallel.h:29
NoJob::BTParallel::DebugLabel
std::string DebugLabel() const override
Definition
BTParallel.h:18
NoJob::BTParallel::Tick
BTStatus Tick(BTContext &ctx, float dt) const override
Evaluates this node for one update.
Definition
BTParallel.h:19
NoJob::BTParallel::Reset
void Reset(BTContext &ctx) const override
Definition
BTParallel.h:26
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::Running
@ Running
Definition
BTNode.h:13
Engine
AI
BehaviorTree
BTParallel.h
Generated by
1.18.0