I have a quick question about this type of implementation calling in a behavioral tree pattern. From what I can see the first line they call the pointer to an object "builder" but every subsequent line after it they omit calling the pointer object "builder". They also omit the ";" semicolon
a: what type of pattern is this and where can I find a reference to calling members on a pointer like this
BT::BehaviorTree* Bt=Builder
->ActiveSelector()
->Sequence()
->Condition(BT::EConditionMode::IsSeeEnemy,false)
->Back()
->ActiveSelector()
-> Sequence()
->Condition(BT::EConditionMode::IsHealthLow,false)
->Back()
->Action(BT::EActionMode::Runaway)
->Back()
->Back()
->Parallel(BT::EPolicy::RequireAll, BT::EPolicy::RequireOne)
->Condition(BT::EConditionMode::IsEnemyDead,true)
->Back()
->Action(BT::EActionMode::Attack)
->Back()
->Back()
->Back()
->Back()
->Action(BT::EActionMode::Patrol)
->End();
The Definition of the class looks like this
class BehaviorTreeBuilder
{
public:
BehaviorTreeBuilder() { }
~BehaviorTreeBuilder() { }
BehaviorTreeBuilder* Sequence();
BehaviorTreeBuilder* Action(EActionMode ActionModes);
BehaviorTreeBuilder* Condition(EConditionMode ConditionMode, bool IsNegation);
BehaviorTreeBuilder* Selector();
BehaviorTreeBuilder* Repeat(int RepeatNum);
BehaviorTreeBuilder* ActiveSelector();
BehaviorTreeBuilder* Filter();
BehaviorTreeBuilder* Parallel(EPolicy InSucess, EPolicy InFailure);
BehaviorTreeBuilder* Monitor(EPolicy InSucess, EPolicy InFailure);
BehaviorTreeBuilder* Back();
BehaviorTree* End();
}
The main question I have is that the I understand that they creating an object pointer and adding methods to the pointer.
but what I dont understand is when they call the tree builder that each new line omits the pointer name and gets away with following eg
...= Builder
-> functionA()
-> functionB()
-> functionA()
-> functionC();
Is this perhaps some kind of a lambda expression or stack or queue pattern? . What's the patterns name and where can I find a reference to it as all the books I've read makes no reference to doing things like this.
Thanks in advance!
The implimentation of the class
This is not a class implementation, this is a class definition.
The possible class member function implementation:
BehaviorTreeBuilder* BehaviorTreeBuilder::Sequence() {
// Do stuff
return this;
}
All the magic is in return this
.
= Builder
-> functionA()
-> functionB();
It's same as
= (Builder
-> functionA())
-> functionB();
If a function returns a pointer, you can deal with a result as with a pointer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.