Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

direct/src/interval/cMetaInterval.I

Go to the documentation of this file.
00001 // Filename: cMetaInterval.I
00002 // Created by:  drose (27Aug02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: CMetaInterval::set_precision
00022 //       Access: Published
00023 //  Description: Indicates the precision with which time measurements
00024 //               are compared.  For numerical accuracy, all
00025 //               floating-point time values are converted to integer
00026 //               values internally by scaling by the precision factor.
00027 //               The larger the number given here, the smaller the
00028 //               delta of time that can be differentiated; the
00029 //               limit is the maximum integer that can be represented
00030 //               in the system.
00031 ////////////////////////////////////////////////////////////////////
00032 INLINE void CMetaInterval::
00033 set_precision(double precision) {
00034   _precision = precision;
00035   mark_dirty();
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: CMetaInterval::get_precision
00040 //       Access: Published
00041 //  Description: Returns the precision with which time measurements
00042 //               are compared.  See set_precision().
00043 ////////////////////////////////////////////////////////////////////
00044 INLINE double CMetaInterval::
00045 get_precision() const {
00046   return _precision;
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: CMetaInterval::get_num_defs
00051 //       Access: Published
00052 //  Description: Returns the number of interval and push/pop
00053 //               definitions that have been added to the meta
00054 //               interval.
00055 ////////////////////////////////////////////////////////////////////
00056 INLINE int CMetaInterval::
00057 get_num_defs() const {
00058   return (int)_defs.size();
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: CMetaInterval::get_def_type
00063 //       Access: Published
00064 //  Description: Returns the type of the nth interval definition that
00065 //               has been added.
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE CMetaInterval::DefType CMetaInterval::
00068 get_def_type(int n) const {
00069   nassertr(n >= 0 && n < (int)_defs.size(), DT_c_interval);
00070   return _defs[n]._type;
00071 }
00072 
00073 ////////////////////////////////////////////////////////////////////
00074 //     Function: CMetaInterval::get_c_interval
00075 //       Access: Published
00076 //  Description: Return the CInterval pointer associated with the nth
00077 //               interval definition.  It is only valid to call this
00078 //               if get_def_type(n) returns DT_c_interval.
00079 ////////////////////////////////////////////////////////////////////
00080 INLINE CInterval *CMetaInterval::
00081 get_c_interval(int n) const {
00082   nassertr(n >= 0 && n < (int)_defs.size(), NULL);
00083   nassertr(_defs[n]._type == DT_c_interval, NULL);
00084   return _defs[n]._c_interval;
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: CMetaInterval::get_ext_index
00089 //       Access: Published
00090 //  Description: Return the external interval index number associated
00091 //               with the nth interval definition.  It is only valid
00092 //               to call this if get_def_type(n) returns DT_ext_index.
00093 ////////////////////////////////////////////////////////////////////
00094 INLINE int CMetaInterval::
00095 get_ext_index(int n) const {
00096   nassertr(n >= 0 && n < (int)_defs.size(), -1);
00097   nassertr(_defs[n]._type == DT_ext_index, -1);
00098   return _defs[n]._ext_index;
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: CMetaInterval::is_event_ready
00103 //       Access: Published
00104 //  Description: Returns true if a recent call to priv_initialize(),
00105 //               priv_step(), or priv_finalize() has left some external
00106 //               intervals ready to play.  If this returns true, call
00107 //               get_event_index(), get_event_t(), and pop_event() to
00108 //               retrieve the relevant information.
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE bool CMetaInterval::
00111 is_event_ready() {
00112   return service_event_queue();
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: CMetaInterval::get_event_index
00117 //       Access: Published
00118 //  Description: If a previous call to is_event_ready() returned
00119 //               true, this returns the index number (added via
00120 //               add_event_index()) of the external interval that needs
00121 //               to be played.
00122 ////////////////////////////////////////////////////////////////////
00123 INLINE int CMetaInterval::
00124 get_event_index() const {
00125   nassertr(!_event_queue.empty(), -1);
00126   const EventQueueEntry &entry = _event_queue.front();
00127   const IntervalDef &def = _defs[entry._n];
00128   nassertr(def._type == DT_ext_index, -1);
00129   return def._ext_index;
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: CMetaInterval::get_event_t
00134 //       Access: Published
00135 //  Description: If a previous call to is_event_ready() returned
00136 //               true, this returns the t value that should be fed to
00137 //               the given interval.
00138 ////////////////////////////////////////////////////////////////////
00139 INLINE double CMetaInterval::
00140 get_event_t() const {
00141   nassertr(!_event_queue.empty(), 0.0f);
00142   return int_to_double_time(_event_queue.front()._time);
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: CMetaInterval::get_event_type
00147 //       Access: Published
00148 //  Description: If a previous call to is_event_ready() returned
00149 //               true, this returns the type of the event (initialize,
00150 //               step, finalize, etc.) for the given interval.
00151 ////////////////////////////////////////////////////////////////////
00152 INLINE CInterval::EventType CMetaInterval::
00153 get_event_type() const {
00154   nassertr(!_event_queue.empty(), ET_step);
00155   return _event_queue.front()._event_type;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: CMetaInterval::double_to_int_time
00160 //       Access: Private
00161 //  Description: Converts from an external double time value or offset
00162 //               in seconds to an internal integer value or offset.
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE int CMetaInterval::
00165 double_to_int_time(double t) const {
00166   // Use floor() just in case there are negative values involved.
00167   return (int)floor(t * _precision + 0.5);
00168 }
00169 
00170 ////////////////////////////////////////////////////////////////////
00171 //     Function: CMetaInterval::int_to_double_time
00172 //       Access: Private
00173 //  Description: Converts from an internal integer time value or
00174 //               offset to an external double time value or offset in
00175 //               seconds.
00176 ////////////////////////////////////////////////////////////////////
00177 INLINE double CMetaInterval::
00178 int_to_double_time(int time) const {
00179   return (double)time / _precision;
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: CMetaInterval::PlaybackEvent::Constructor
00184 //       Access: Public
00185 //  Description: 
00186 ////////////////////////////////////////////////////////////////////
00187 INLINE CMetaInterval::PlaybackEvent::
00188 PlaybackEvent(int time, int n, 
00189               CMetaInterval::PlaybackEventType type) :
00190   _time(time),
00191   _n(n),
00192   _type(type)
00193 {
00194   _begin_event = this;
00195 }
00196 
00197 ////////////////////////////////////////////////////////////////////
00198 //     Function: CMetaInterval::PlaybackEvent::Ordering operator
00199 //       Access: Public
00200 //  Description: 
00201 ////////////////////////////////////////////////////////////////////
00202 INLINE bool CMetaInterval::PlaybackEvent::
00203 operator < (const CMetaInterval::PlaybackEvent &other) const {
00204   return _time < other._time;
00205 }
00206 
00207 ////////////////////////////////////////////////////////////////////
00208 //     Function: CMetaInterval::EventQueueEntry::Constructor
00209 //       Access: Public
00210 //  Description: 
00211 ////////////////////////////////////////////////////////////////////
00212 INLINE CMetaInterval::EventQueueEntry::
00213 EventQueueEntry(int n, CInterval::EventType event_type, int time) :
00214   _n(n),
00215   _event_type(event_type),
00216   _time(time)
00217 {
00218 }

Generated on Fri May 2 01:37:53 2003 for Direct by doxygen1.3