CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUTimerNode.h
1 //
2 // CUTimerNode.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for a decorator behavior node with a timed
6 // delay. The delay may either be foreground (the node is selected an running,
7 // but is not doing anything) or background (the node cannot be selected until
8 // some time has passed).
9 //
10 // BehaviorNode objects are managed by BehaviorManager, and should never
11 // be allocated directly. Instead, you create a behavior node definition
12 // and pass it to a factor method in BehaviorManager.
13 //
14 // EXPERIMENTAL: This module is experimental. The API may change significantly
15 // in future CUGL releases.
16 //
17 // CUGL MIT License:
18 // This software is provided 'as-is', without any express or implied
19 // warranty. In no event will the authors be held liable for any damages
20 // arising from the use of this software.
21 //
22 // Permission is granted to anyone to use this software for any purpose,
23 // including commercial applications, and to alter it and redistribute it
24 // freely, subject to the following restrictions:
25 //
26 // 1. The origin of this software must not be misrepresented; you must not
27 // claim that you wrote the original software. If you use this software
28 // in a product, an acknowledgment in the product documentation would be
29 // appreciated but is not required.
30 //
31 // 2. Altered source versions must be plainly marked as such, and must not
32 // be misrepresented as being the original software.
33 //
34 // 3. This notice may not be removed or altered from any source distribution.
35 //
36 // Author: Apurv Sethi and Andrew Matsumoto (with Walker White)
37 // Version: 5/21/2018
38 //
39 #ifndef __CU_TIMER_NODE_H__
40 #define __CU_TIMER_NODE_H__
41 #include <cugl/ai/behavior/CUDecoratorNode.h>
42 #include <string>
43 #include <vector>
44 
45 namespace cugl {
46  namespace ai {
47 
60 class TimerNode : public DecoratorNode {
61 #pragma mark Values
62 protected:
65 
67  float _delay;
68 
70  bool _delaying;
71 
73  float _timer;
74 
75 public:
76 #pragma mark -
77 #pragma mark Constructors
78 
84  TimerNode();
85 
90 
98  void dispose() override;
99 
100 #pragma mark Attributes
101 
111  std::string toString(bool verbose = false) const override;
112 
127  bool isBackground() const { return _background; }
128 
143  void setBackground(bool background) { _background = background; }
144 
159  float getDelay() const { return _delay; }
160 
175  void setDelay(float delay) { _delay = delay; }
176 
184  float getCurrentDelay() const { return _timer; }
185 
193  void setState(BehaviorNode::State state) override;
194 
195 #pragma mark Behavior Management
196 
203  void reset() override;
204 
210  void preempt() override;
211 
226  virtual void query(float dt) override;
227 
243  BehaviorNode::State update(float dt) override;
244 };
245 
246  }
247 }
248 #endif /* __CU_TIMER_NODE_H__ */
cugl::ai::TimerNode::TimerNode
TimerNode()
cugl::ai::TimerNode::query
virtual void query(float dt) override
cugl::ai::TimerNode::setBackground
void setBackground(bool background)
Definition: CUTimerNode.h:143
cugl::ai::TimerNode::_delay
float _delay
Definition: CUTimerNode.h:67
cugl::ai::TimerNode::_timer
float _timer
Definition: CUTimerNode.h:73
cugl::ai::TimerNode::setState
void setState(BehaviorNode::State state) override
cugl::ai::TimerNode::reset
void reset() override
cugl::ai::TimerNode
Definition: CUTimerNode.h:60
cugl::ai::TimerNode::getDelay
float getDelay() const
Definition: CUTimerNode.h:159
cugl::ai::TimerNode::preempt
void preempt() override
cugl::ai::TimerNode::isBackground
bool isBackground() const
Definition: CUTimerNode.h:127
cugl::ai::TimerNode::getCurrentDelay
float getCurrentDelay() const
Definition: CUTimerNode.h:184
cugl::ai::TimerNode::setDelay
void setDelay(float delay)
Definition: CUTimerNode.h:175
cugl::ai::TimerNode::dispose
void dispose() override
cugl::ai::TimerNode::_delaying
bool _delaying
Definition: CUTimerNode.h:70
cugl::ai::TimerNode::update
BehaviorNode::State update(float dt) override
cugl::ai::BehaviorNode::State
State
Definition: CUBehaviorNode.h:290
cugl::ai::TimerNode::~TimerNode
~TimerNode()
Definition: CUTimerNode.h:89
cugl::ai::TimerNode::toString
std::string toString(bool verbose=false) const override
cugl::ai::TimerNode::_background
bool _background
Definition: CUTimerNode.h:64
cugl::ai::DecoratorNode
Definition: CUDecoratorNode.h:63