Panda3D

Loading...
Searching...
No Matches
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 */
17INLINE const std::string &CInterval::
18 get_name() const {
19 return _name;
20}
21
22/**
23 * Returns the duration of the interval in seconds.
24 */
25INLINE 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 */
38INLINE 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 */
47INLINE 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 */
56INLINE 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 */
66INLINE 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 */
76INLINE 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 */
85INLINE 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 */
96INLINE 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 */
104INLINE 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 */
115INLINE 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 */
123INLINE 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 */
134INLINE 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 */
144INLINE bool CInterval::
145 get_wants_t_callback() const {
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 */
155INLINE 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 */
167INLINE 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 */
177INLINE bool CInterval::
178 check_t_callback() {
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 */
189INLINE void CInterval::
190recompute() 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 */
199INLINE void CInterval::
200check_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 */
212INLINE void CInterval::
213check_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
222INLINE std::ostream &
223operator << (std::ostream &out, const CInterval &ival) {
224 ival.output(out);
225 return out;
226}
CIntervalManager
This object holds a number of currently-playing intervals and is responsible for advancing them each ...
Definition cIntervalManager.h:39
CInterval
The base class for timeline components.
Definition cInterval.h:36
CInterval::check_t_callback
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
CInterval::get_manager
get_manager
Returns the CIntervalManager object which will be responsible for playing this interval.
Definition cInterval.h:135
CInterval::get_wants_t_callback
bool get_wants_t_callback() const
Returns the state of the 'wants_t_callback' flag.
Definition cInterval.I:145
CInterval::set_wants_t_callback
void set_wants_t_callback(bool wants_t_callback)
Changes the state of the 'wants_t_callback' flag.
Definition cInterval.I:135
CInterval::set_manager
set_manager
Indicates the CIntervalManager object which will be responsible for playing this interval.
Definition cInterval.h:135
CInterval::get_name
get_name
Returns the interval's name.
Definition cInterval.h:126
CInterval::get_auto_pause
get_auto_pause
Returns the state of the 'auto_pause' flag.
Definition cInterval.h:133
CInterval::get_duration
get_duration
Returns the duration of the interval in seconds.
Definition cInterval.h:127
CInterval::is_stopped
is_stopped
Returns true if the interval is in either its initial or final states (but not in a running or paused...
Definition cInterval.h:130
CInterval::set_done_event
set_done_event
Sets the event that is generated whenever the interval reaches its final state, whether it is explici...
Definition cInterval.h:131
CInterval::set_auto_pause
set_auto_pause
Changes the state of the 'auto_pause' flag.
Definition cInterval.h:133
CInterval::get_open_ended
get_open_ended
Returns the state of the "open_ended" flag.
Definition cInterval.h:128
CInterval::get_state
get_state
Indicates the state the interval believes it is in: whether it has been started, is currently in the ...
Definition cInterval.h:129
CInterval::get_done_event
get_done_event
Returns the event that is generated whenever the interval reaches its final state,...
Definition cInterval.h:131
CInterval::get_t
get_t
Returns the current time of the interval: the last value of t passed to priv_initialize(),...
Definition cInterval.h:132
CInterval::set_auto_finish
set_auto_finish
Changes the state of the 'auto_finish' flag.
Definition cInterval.h:134
CInterval::get_auto_finish
get_auto_finish
Returns the state of the 'auto_finish' flag.
Definition cInterval.h:134
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypeHandle::get_name
get_name
Returns the name of the type.
Definition typeHandle.h:136