Panda3D
cInterval.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file cInterval.I
10  * @author drose
11  * @date 2002-08-27
12  */
13 
14 /**
15  * Returns the interval's name.
16  */
17 INLINE const std::string &CInterval::
18 get_name() const {
19  return _name;
20 }
21 
22 /**
23  * Returns the duration of the interval in seconds.
24  */
25 INLINE double CInterval::
26 get_duration() const {
27  recompute();
28  return _duration;
29 }
30 
31 /**
32  * Returns the state of the "open_ended" flag. This is primarily intended for
33  * instantaneous intervals like FunctionIntervals; it indicates true if the
34  * interval has some lasting effect that should be applied even if the
35  * interval doesn't get started until after its finish time, or false if the
36  * interval is a transitive thing that doesn't need to be called late.
37  */
38 INLINE bool CInterval::
39 get_open_ended() const {
40  return _open_ended;
41 }
42 
43 /**
44  * Indicates the state the interval believes it is in: whether it has been
45  * started, is currently in the middle, or has been finalized.
46  */
47 INLINE CInterval::State CInterval::
48 get_state() const {
49  return _state;
50 }
51 
52 /**
53  * Returns true if the interval is in either its initial or final states (but
54  * not in a running or paused state).
55  */
56 INLINE bool CInterval::
57 is_stopped() const {
58  return (_state == S_initial || _state == S_final);
59 }
60 
61 /**
62  * Sets the event that is generated whenever the interval reaches its final
63  * state, whether it is explicitly finished or whether it gets there on its
64  * own.
65  */
66 INLINE void CInterval::
67 set_done_event(const std::string &event) {
68  _done_event = event;
69 }
70 
71 /**
72  * Returns the event that is generated whenever the interval reaches its final
73  * state, whether it is explicitly finished or whether it gets there on its
74  * own.
75  */
76 INLINE const std::string &CInterval::
77 get_done_event() const {
78  return _done_event;
79 }
80 
81 /**
82  * Returns the current time of the interval: the last value of t passed to
83  * priv_initialize(), priv_step(), or priv_finalize().
84  */
85 INLINE double CInterval::
86 get_t() const {
87  return _curr_t;
88 }
89 
90 /**
91  * Changes the state of the 'auto_pause' flag. If this is true, the interval
92  * may be arbitrarily interrupted when the system needs to reset due to some
93  * external event by calling CIntervalManager::interrupt(). If this is false
94  * (the default), the interval must always be explicitly finished or paused.
95  */
96 INLINE void CInterval::
97 set_auto_pause(bool auto_pause) {
98  _auto_pause = auto_pause;
99 }
100 
101 /**
102  * Returns the state of the 'auto_pause' flag. See set_auto_pause().
103  */
104 INLINE bool CInterval::
105 get_auto_pause() const {
106  return _auto_pause;
107 }
108 
109 /**
110  * Changes the state of the 'auto_finish' flag. If this is true, the interval
111  * may be arbitrarily finished when the system needs to reset due to some
112  * external event by calling CIntervalManager::interrupt(). If this is false
113  * (the default), the interval must always be explicitly finished or paused.
114  */
115 INLINE void CInterval::
116 set_auto_finish(bool auto_finish) {
117  _auto_finish = auto_finish;
118 }
119 
120 /**
121  * Returns the state of the 'auto_finish' flag. See set_auto_finish().
122  */
123 INLINE bool CInterval::
124 get_auto_finish() const {
125  return _auto_finish;
126 }
127 
128 /**
129  * Changes the state of the 'wants_t_callback' flag. If this is true, the
130  * interval will be returned by CIntervalManager::get_event() each time the
131  * interval's time value has been changed, regardless of whether it has any
132  * external events.
133  */
134 INLINE void CInterval::
135 set_wants_t_callback(bool wants_t_callback) {
136  _wants_t_callback = wants_t_callback;
137  _last_t_callback = -1.0;
138 }
139 
140 /**
141  * Returns the state of the 'wants_t_callback' flag. See
142  * set_wants_t_callback().
143  */
144 INLINE bool CInterval::
146  return _wants_t_callback;
147 }
148 
149 /**
150  * Indicates the CIntervalManager object which will be responsible for playing
151  * this interval. This defaults to the global CIntervalManager; you should
152  * need to change this only if you have special requirements for playing this
153  * interval.
154  */
155 INLINE void CInterval::
156 set_manager(CIntervalManager *manager) {
157  _manager = manager;
158 }
159 
160 /**
161  * Returns the CIntervalManager object which will be responsible for playing
162  * this interval. Note that this can only return a C++ object; if the
163  * particular CIntervalManager object has been extended in the scripting
164  * language, this will return the encapsulated C++ object, not the full
165  * extended object.
166  */
167 INLINE CIntervalManager *CInterval::
168 get_manager() const {
169  return _manager;
170 }
171 
172 /**
173  * Returns true if the wants_t_callback() flag is true and the interval's t
174  * value has changed since the last call to check_t_callback(), false
175  * otherwise.
176  */
177 INLINE bool CInterval::
179  if (get_wants_t_callback() && get_t() != _last_t_callback) {
180  _last_t_callback = get_t();
181  return true;
182  }
183  return false;
184 }
185 
186 /**
187  * Calls do_recompute() if the dirty flag has been set.
188  */
189 INLINE void CInterval::
190 recompute() const {
191  if (_dirty) {
192  ((CInterval *)this)->do_recompute();
193  }
194 }
195 
196 /**
197  * Issues a warning if our internal state is not in one of the stopped states.
198  */
199 INLINE void CInterval::
200 check_stopped(TypeHandle type, const char *method_name) const {
201  if (_state == S_started) {
202  interval_cat.warning()
203  << type.get_name() << "::" << method_name << "() called for "
204  << get_name() << " in state " << _state << ".\n";
205  nassertv(!verify_intervals);
206  }
207 }
208 
209 /**
210  * Issues a warning if our internal state is not in one of the started states.
211  */
212 INLINE void CInterval::
213 check_started(TypeHandle type, const char *method_name) const {
214  if (_state != S_started && _state != S_paused) {
215  interval_cat.warning()
216  << type.get_name() << "::" << method_name << "() called for "
217  << get_name() << " in state " << _state << ".\n";
218  nassertv(!verify_intervals);
219  }
220 }
221 
222 INLINE std::ostream &
223 operator << (std::ostream &out, const CInterval &ival) {
224  ival.output(out);
225  return out;
226 }
set_done_event
Sets the event that is generated whenever the interval reaches its final state, whether it is explici...
Definition: cInterval.h:128
set_auto_pause
Changes the state of the 'auto_pause' flag.
Definition: cInterval.h:130
The base class for timeline components.
Definition: cInterval.h:35
bool get_wants_t_callback() const
Returns the state of the 'wants_t_callback' flag.
Definition: cInterval.I:145
get_name
Returns the interval's name.
Definition: cInterval.h:123
get_name
Returns the name of the type.
Definition: typeHandle.h:136
set_auto_finish
Changes the state of the 'auto_finish' flag.
Definition: cInterval.h:131
get_t
Returns the current time of the interval: the last value of t passed to priv_initialize(),...
Definition: cInterval.h:129
This object holds a number of currently-playing intervals and is responsible for advancing them each ...
void set_wants_t_callback(bool wants_t_callback)
Changes the state of the 'wants_t_callback' flag.
Definition: cInterval.I:135
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
bool check_t_callback()
Returns true if the wants_t_callback() flag is true and the interval's t value has changed since the ...
Definition: cInterval.I:178
set_manager
Indicates the CIntervalManager object which will be responsible for playing this interval.
Definition: cInterval.h:132