SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Parallel.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "tree/Selector.h"
7 #include "AI.h"
8 
9 namespace ai {
10 
17 class Parallel: public Selector {
18 public:
19  SELECTOR_CLASS(Parallel)
20 
21  void getRunningChildren(const AIPtr& entity, std::vector<bool>& active) const override {
22  for (TreeNodes::const_iterator i = _children.begin(); i != _children.end(); ++i) {
23  active.push_back((*i)->getLastStatus(entity) != RUNNING);
24  }
25  }
30  TreeNodeStatus execute(const AIPtr& entity, int64_t deltaMillis) override {
31  if (Selector::execute(entity, deltaMillis) == CANNOTEXECUTE) {
32  return CANNOTEXECUTE;
33  }
34 
35  bool totalStatus = false;
36  for (const TreeNodePtr& child : _children) {
37  const bool isActive = child->execute(entity, deltaMillis) == RUNNING;
38  if (!isActive) {
39  child->resetState(entity);
40  }
41  totalStatus |= isActive;
42  }
43 
44  if (!totalStatus) {
45  resetState(entity);
46  }
47  return state(entity, totalStatus ? RUNNING : FINISHED);
48  }
49 };
50 
51 }
void getRunningChildren(const AIPtr &entity, std::vector< bool > &active) const override
Will only deliver valid results if the debugging for the given entity is active.
Definition: Parallel.h:21
virtual TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis)
Definition: TreeNodeImpl.h:184
Base class for all type of TreeNode selectors.
Definition: Selector.h:25
TreeNodeStatus execute(const AIPtr &entity, int64_t deltaMillis) override
If one of the children was executed, and is still running, the ::TreeNodeStatus::RUNNING is returned...
Definition: Parallel.h:30
virtual void resetState(const AIPtr &entity)
Reset the states in the node and also in the entity.
Definition: TreeNodeImpl.h:55
Executes all the connected children in the order they were added (no matter what the TreeNodeStatus o...
Definition: Parallel.h:17