00001 // Filename: cInterval.I 00002 // Created by: drose (27Aug02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: CInterval::get_name 00018 // Access: Published 00019 // Description: Returns the interval's name. 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE const string &CInterval:: 00022 get_name() const { 00023 return _name; 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: CInterval::get_duration 00028 // Access: Published 00029 // Description: Returns the duration of the interval in seconds. 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE double CInterval:: 00032 get_duration() const { 00033 recompute(); 00034 return _duration; 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: CInterval::get_open_ended 00039 // Access: Published 00040 // Description: Returns the state of the "open_ended" flag. This is 00041 // primarily intended for instantaneous intervals like 00042 // FunctionIntervals; it indicates true if the interval 00043 // has some lasting effect that should be applied even 00044 // if the interval doesn't get started until after its 00045 // finish time, or false if the interval is a transitive 00046 // thing that doesn't need to be called late. 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE bool CInterval:: 00049 get_open_ended() const { 00050 return _open_ended; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: CInterval::get_state 00055 // Access: Published 00056 // Description: Indicates the state the interval believes it is in: 00057 // whether it has been started, is currently in the 00058 // middle, or has been finalized. 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE CInterval::State CInterval:: 00061 get_state() const { 00062 return _state; 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: CInterval::is_stopped 00067 // Access: Published 00068 // Description: Returns true if the interval is in either its initial 00069 // or final states (but not in a running or paused 00070 // state). 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE bool CInterval:: 00073 is_stopped() const { 00074 return (_state == S_initial || _state == S_final); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: CInterval::set_done_event 00079 // Access: Published 00080 // Description: Sets the event that is generated whenever the 00081 // interval reaches its final state, whether it is 00082 // explicitly finished or whether it gets there on its 00083 // own. 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE void CInterval:: 00086 set_done_event(const string &event) { 00087 _done_event = event; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: CInterval::get_done_event 00092 // Access: Published 00093 // Description: Returns the event that is generated whenever the 00094 // interval reaches its final state, whether it is 00095 // explicitly finished or whether it gets there on its 00096 // own. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE const string &CInterval:: 00099 get_done_event() const { 00100 return _done_event; 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: CInterval::get_t 00105 // Access: Published 00106 // Description: Returns the current time of the interval: the last 00107 // value of t passed to priv_initialize(), priv_step(), or 00108 // priv_finalize(). 00109 //////////////////////////////////////////////////////////////////// 00110 INLINE double CInterval:: 00111 get_t() const { 00112 return _curr_t; 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: CInterval::set_auto_pause 00117 // Access: Published 00118 // Description: Changes the state of the 'auto_pause' flag. If 00119 // this is true, the interval may be arbitrarily 00120 // interrupted when the system needs to reset due to 00121 // some external event by calling 00122 // CIntervalManager::interrupt(). If this 00123 // is false (the default), the interval must always be 00124 // explicitly finished or paused. 00125 //////////////////////////////////////////////////////////////////// 00126 INLINE void CInterval:: 00127 set_auto_pause(bool auto_pause) { 00128 _auto_pause = auto_pause; 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: CInterval::get_auto_pause 00133 // Access: Published 00134 // Description: Returns the state of the 'auto_pause' flag. See 00135 // set_auto_pause(). 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE bool CInterval:: 00138 get_auto_pause() const { 00139 return _auto_pause; 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: CInterval::set_auto_finish 00144 // Access: Published 00145 // Description: Changes the state of the 'auto_finish' flag. If 00146 // this is true, the interval may be arbitrarily 00147 // finished when the system needs to reset due to 00148 // some external event by calling 00149 // CIntervalManager::interrupt(). If this 00150 // is false (the default), the interval must always be 00151 // explicitly finished or paused. 00152 //////////////////////////////////////////////////////////////////// 00153 INLINE void CInterval:: 00154 set_auto_finish(bool auto_finish) { 00155 _auto_finish = auto_finish; 00156 } 00157 00158 //////////////////////////////////////////////////////////////////// 00159 // Function: CInterval::get_auto_finish 00160 // Access: Published 00161 // Description: Returns the state of the 'auto_finish' flag. See 00162 // set_auto_finish(). 00163 //////////////////////////////////////////////////////////////////// 00164 INLINE bool CInterval:: 00165 get_auto_finish() const { 00166 return _auto_finish; 00167 } 00168 00169 //////////////////////////////////////////////////////////////////// 00170 // Function: CInterval::set_wants_t_callback 00171 // Access: Published 00172 // Description: Changes the state of the 'wants_t_callback' flag. If 00173 // this is true, the interval will be returned by 00174 // CIntervalManager::get_event() each time the 00175 // interval's time value has been changed, regardless of 00176 // whether it has any external events. 00177 //////////////////////////////////////////////////////////////////// 00178 INLINE void CInterval:: 00179 set_wants_t_callback(bool wants_t_callback) { 00180 _wants_t_callback = wants_t_callback; 00181 _last_t_callback = -1.0; 00182 } 00183 00184 //////////////////////////////////////////////////////////////////// 00185 // Function: CInterval::get_wants_t_callback 00186 // Access: Published 00187 // Description: Returns the state of the 'wants_t_callback' flag. 00188 // See set_wants_t_callback(). 00189 //////////////////////////////////////////////////////////////////// 00190 INLINE bool CInterval:: 00191 get_wants_t_callback() const { 00192 return _wants_t_callback; 00193 } 00194 00195 //////////////////////////////////////////////////////////////////// 00196 // Function: CInterval::set_manager 00197 // Access: Published 00198 // Description: Indicates the CIntervalManager object which will be 00199 // responsible for playing this interval. This defaults 00200 // to the global CIntervalManager; you should need to 00201 // change this only if you have special requirements for 00202 // playing this interval. 00203 //////////////////////////////////////////////////////////////////// 00204 INLINE void CInterval:: 00205 set_manager(CIntervalManager *manager) { 00206 _manager = manager; 00207 } 00208 00209 //////////////////////////////////////////////////////////////////// 00210 // Function: CInterval::get_manager 00211 // Access: Published 00212 // Description: Returns the CIntervalManager object which will be 00213 // responsible for playing this interval. Note that 00214 // this can only return a C++ object; if the particular 00215 // CIntervalManager object has been extended in the 00216 // scripting language, this will return the encapsulated 00217 // C++ object, not the full extended object. 00218 //////////////////////////////////////////////////////////////////// 00219 INLINE CIntervalManager *CInterval:: 00220 get_manager() const { 00221 return _manager; 00222 } 00223 00224 //////////////////////////////////////////////////////////////////// 00225 // Function: CInterval::check_t_callback 00226 // Access: Public 00227 // Description: Returns true if the wants_t_callback() flag is true 00228 // and the interval's t value has changed since the last 00229 // call to check_t_callback(), false otherwise. 00230 //////////////////////////////////////////////////////////////////// 00231 INLINE bool CInterval:: 00232 check_t_callback() { 00233 if (get_wants_t_callback() && get_t() != _last_t_callback) { 00234 _last_t_callback = get_t(); 00235 return true; 00236 } 00237 return false; 00238 } 00239 00240 //////////////////////////////////////////////////////////////////// 00241 // Function: CInterval::recompute 00242 // Access: Protected 00243 // Description: Calls do_recompute() if the dirty flag has been set. 00244 //////////////////////////////////////////////////////////////////// 00245 INLINE void CInterval:: 00246 recompute() const { 00247 if (_dirty) { 00248 ((CInterval *)this)->do_recompute(); 00249 } 00250 } 00251 00252 //////////////////////////////////////////////////////////////////// 00253 // Function: CInterval::check_stopped 00254 // Access: Protected 00255 // Description: Issues a warning if our internal state is not in 00256 // one of the stopped states. 00257 //////////////////////////////////////////////////////////////////// 00258 INLINE void CInterval:: 00259 check_stopped(TypeHandle type, const char *method_name) const { 00260 if (_state == S_started) { 00261 interval_cat.warning() 00262 << type.get_name() << "::" << method_name << "() called for " 00263 << get_name() << " in state " << _state << ".\n"; 00264 nassertv(!verify_intervals); 00265 } 00266 } 00267 00268 //////////////////////////////////////////////////////////////////// 00269 // Function: CInterval::check_started 00270 // Access: Protected 00271 // Description: Issues a warning if our internal state is not in 00272 // one of the started states. 00273 //////////////////////////////////////////////////////////////////// 00274 INLINE void CInterval:: 00275 check_started(TypeHandle type, const char *method_name) const { 00276 if (_state != S_started && _state != S_paused) { 00277 interval_cat.warning() 00278 << type.get_name() << "::" << method_name << "() called for " 00279 << get_name() << " in state " << _state << ".\n"; 00280 nassertv(!verify_intervals); 00281 } 00282 } 00283 00284 INLINE ostream & 00285 operator << (ostream &out, const CInterval &ival) { 00286 ival.output(out); 00287 return out; 00288 } 00289