23
23
24
24
namespace BT
25
25
{
26
-
27
26
// IMPORTANT: Actions which returned SUCCESS or FAILURE will not be ticked
28
27
// again unless resetStatus() is called first.
29
28
// Keep this in mind when writing your custom Control and Decorator nodes.
@@ -35,15 +34,14 @@ namespace BT
35
34
*/
36
35
class ActionNodeBase : public LeafNode
37
36
{
38
- public:
39
-
40
- ActionNodeBase (const std::string& name, const NodeConfiguration& config);
41
- ~ActionNodeBase () override = default ;
42
-
43
- virtual NodeType type () const override final
44
- {
45
- return NodeType::ACTION;
46
- }
37
+ public:
38
+ ActionNodeBase (const std::string& name, const NodeConfiguration& config);
39
+ ~ActionNodeBase () override = default ;
40
+
41
+ virtual NodeType type () const override final
42
+ {
43
+ return NodeType::ACTION;
44
+ }
47
45
};
48
46
49
47
/* *
@@ -53,17 +51,16 @@ class ActionNodeBase : public LeafNode
53
51
*/
54
52
class SyncActionNode : public ActionNodeBase
55
53
{
56
- public:
57
-
58
- SyncActionNode (const std::string& name, const NodeConfiguration& config);
59
- ~SyncActionNode () override = default ;
54
+ public:
55
+ SyncActionNode (const std::string& name, const NodeConfiguration& config);
56
+ ~SyncActionNode () override = default ;
60
57
61
- // / throws if the derived class return RUNNING.
62
- virtual NodeStatus executeTick () override ;
58
+ // / throws if the derived class return RUNNING.
59
+ virtual NodeStatus executeTick () override ;
63
60
64
- // / You don't need to override this
65
- virtual void halt () override final
66
- { }
61
+ // / You don't need to override this
62
+ virtual void halt () override final
63
+ { }
67
64
};
68
65
69
66
/* *
@@ -80,19 +77,19 @@ class SyncActionNode : public ActionNodeBase
80
77
*/
81
78
class SimpleActionNode : public SyncActionNode
82
79
{
83
- public:
84
- typedef std::function<NodeStatus(TreeNode&)> TickFunctor;
80
+ public:
81
+ typedef std::function<NodeStatus(TreeNode&)> TickFunctor;
85
82
86
- // You must provide the function to call when tick() is invoked
87
- SimpleActionNode (const std::string& name, TickFunctor tick_functor,
88
- const NodeConfiguration& config);
83
+ // You must provide the function to call when tick() is invoked
84
+ SimpleActionNode (const std::string& name, TickFunctor tick_functor,
85
+ const NodeConfiguration& config);
89
86
90
- ~SimpleActionNode () override = default ;
87
+ ~SimpleActionNode () override = default ;
91
88
92
- protected:
93
- virtual NodeStatus tick () override final ;
89
+ protected:
90
+ virtual NodeStatus tick () override final ;
94
91
95
- TickFunctor tick_functor_;
92
+ TickFunctor tick_functor_;
96
93
};
97
94
98
95
/* *
@@ -116,28 +113,26 @@ class SimpleActionNode : public SyncActionNode
116
113
*/
117
114
class AsyncActionNode : public ActionNodeBase
118
115
{
119
- public:
120
-
121
- AsyncActionNode (const std::string& name, const NodeConfiguration& config):ActionNodeBase(name, config)
122
- {
123
- }
124
-
125
- bool isHaltRequested () const
126
- {
127
- return halt_requested_.load ();
128
- }
129
-
130
- // This method spawn a new thread. Do NOT remove the "final" keyword.
131
- virtual NodeStatus executeTick () override final ;
132
-
133
- virtual void halt () override ;
134
-
135
- private:
136
-
137
- std::exception_ptr exptr_;
138
- std::atomic_bool halt_requested_;
139
- std::future<void > thread_handle_;
140
- std::mutex mutex_;
116
+ public:
117
+ AsyncActionNode (const std::string& name, const NodeConfiguration& config) :
118
+ ActionNodeBase (name, config)
119
+ {}
120
+
121
+ bool isHaltRequested () const
122
+ {
123
+ return halt_requested_.load ();
124
+ }
125
+
126
+ // This method spawn a new thread. Do NOT remove the "final" keyword.
127
+ virtual NodeStatus executeTick () override final ;
128
+
129
+ virtual void halt () override ;
130
+
131
+ private:
132
+ std::exception_ptr exptr_;
133
+ std::atomic_bool halt_requested_;
134
+ std::future<void > thread_handle_;
135
+ std::mutex mutex_;
141
136
};
142
137
143
138
/* *
@@ -157,29 +152,28 @@ class AsyncActionNode : public ActionNodeBase
157
152
*/
158
153
class StatefulActionNode : public ActionNodeBase
159
154
{
160
- public:
161
- StatefulActionNode (const std::string& name, const NodeConfiguration& config):
162
- ActionNodeBase (name,config)
163
- {}
164
-
165
- // do not override this method
166
- NodeStatus tick () override final ;
167
- // do not override this method
168
- void halt () override final ;
169
-
170
- // / method to be called at the beginning.
171
- // / If it returns RUNNING, this becomes an asychronous node.
172
- virtual NodeStatus onStart () = 0;
173
-
174
- // / method invoked by a RUNNING action.
175
- virtual NodeStatus onRunning () = 0;
176
-
177
- // / when the method halt() is called and the action is RUNNING, this method is invoked.
178
- // / This is a convenient place todo a cleanup, if needed.
179
- virtual void onHalted () = 0;
155
+ public:
156
+ StatefulActionNode (const std::string& name, const NodeConfiguration& config) :
157
+ ActionNodeBase (name, config)
158
+ {}
159
+
160
+ // do not override this method
161
+ NodeStatus tick () override final ;
162
+ // do not override this method
163
+ void halt () override final ;
164
+
165
+ // / method to be called at the beginning.
166
+ // / If it returns RUNNING, this becomes an asychronous node.
167
+ virtual NodeStatus onStart () = 0;
168
+
169
+ // / method invoked by a RUNNING action.
170
+ virtual NodeStatus onRunning () = 0;
171
+
172
+ // / when the method halt() is called and the action is RUNNING, this method is invoked.
173
+ // / This is a convenient place todo a cleanup, if needed.
174
+ virtual void onHalted () = 0;
180
175
};
181
176
182
-
183
177
#ifndef BT_NO_COROUTINES
184
178
185
179
/* *
@@ -191,18 +185,17 @@ class StatefulActionNode : public ActionNodeBase
191
185
*/
192
186
class CoroActionNode : public ActionNodeBase
193
187
{
194
- public:
195
-
196
- CoroActionNode (const std::string& name, const NodeConfiguration& config);
197
- virtual ~CoroActionNode () override ;
188
+ public:
189
+ CoroActionNode (const std::string& name, const NodeConfiguration& config);
190
+ virtual ~CoroActionNode () override ;
198
191
199
- // / Use this method to return RUNNING and temporary "pause" the Action.
200
- void setStatusRunningAndYield ();
192
+ // / Use this method to return RUNNING and temporary "pause" the Action.
193
+ void setStatusRunningAndYield ();
201
194
202
- // This method triggers the TickEngine. Do NOT remove the "final" keyword.
203
- virtual NodeStatus executeTick () override final ;
195
+ // This method triggers the TickEngine. Do NOT remove the "final" keyword.
196
+ virtual NodeStatus executeTick () override final ;
204
197
205
- /* * You may want to override this method. But still, remember to call this
198
+ /* * You may want to override this method. But still, remember to call this
206
199
* implementation too.
207
200
*
208
201
* Example:
@@ -213,15 +206,14 @@ class CoroActionNode : public ActionNodeBase
213
206
* CoroActionNode::halt();
214
207
* }
215
208
*/
216
- void halt () override ;
217
-
218
- protected:
209
+ void halt () override ;
219
210
220
- struct Pimpl ; // The Pimpl idiom
221
- std::unique_ptr<Pimpl> _p;
211
+ protected:
212
+ struct Pimpl ; // The Pimpl idiom
213
+ std::unique_ptr<Pimpl> _p;
222
214
};
223
215
#endif
224
216
225
- } // end namespace
217
+ } // namespace BT
226
218
227
219
#endif
0 commit comments