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