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

panda/src/express/clockObject.I

Go to the documentation of this file.
00001 // Filename: clockObject.I
00002 // Created by:  drose (17Feb00)
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 //     Function: ClockObject::Destructor
00021 //       Access: Published
00022 //  Description:
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE ClockObject::
00025 ~ClockObject() {
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: ClockObject::set_mode
00030 //       Access: Published
00031 //  Description: Changes the mode of the clock, e.g. from normal
00032 //               (real-time) to non-real-time.  In non-real-time mode,
00033 //               tick() will add the value of dt to the value returned
00034 //               by get_frame_time(), regardless of how much time has
00035 //               actually passed.  In normal, real-time mode, tick()
00036 //               will set the value returned by get_frame_time() to
00037 //               the current real time.
00038 ////////////////////////////////////////////////////////////////////
00039 INLINE void ClockObject::
00040 set_mode(ClockObject::Mode mode) {
00041   _mode = mode;
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: ClockObject::get_mode
00046 //       Access: Published
00047 //  Description: Returns the current mode of the clock.  See
00048 //               set_mode().
00049 ////////////////////////////////////////////////////////////////////
00050 INLINE ClockObject::Mode ClockObject::
00051 get_mode() const {
00052   return _mode;
00053 }
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //     Function: ClockObject::get_frame_time
00057 //       Access: Published
00058 //  Description: Returns the time in seconds as of the last time
00059 //               tick() was called (typically, this will be as of the
00060 //               start of the current frame).
00061 //
00062 //               This is generally the kind of time you want to ask
00063 //               for in most rendering and animation contexts, since
00064 //               it's important that all of the animation for a given
00065 //               frame remains in sync with each other.
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE double ClockObject::
00068 get_frame_time() const {
00069   return _reported_frame_time;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: ClockObject::get_real_time
00074 //       Access: Published
00075 //  Description: Returns the actual number of seconds elapsed since
00076 //               the ClockObject was created, or since it was last
00077 //               reset.  This is useful for doing real timing
00078 //               measurements, e.g. for performance statistics.
00079 //
00080 //               This returns the most precise timer we have for short
00081 //               time intervals, but it may tend to drift over the
00082 //               long haul.  If more accurate timekeeping is needed
00083 //               over a long period of time, use get_long_time()
00084 //               instead.
00085 ////////////////////////////////////////////////////////////////////
00086 INLINE double ClockObject::
00087 get_real_time() const {
00088   return (_true_clock->get_short_time() - _start_short_time);
00089 }
00090 
00091 ////////////////////////////////////////////////////////////////////
00092 //     Function: ClockObject::get_long_time
00093 //       Access: Published
00094 //  Description: Returns the actual number of seconds elapsed since
00095 //               the ClockObject was created, or since it was last
00096 //               reset.
00097 //
00098 //               This is similar to get_real_time(), except that it
00099 //               uses the most accurate counter we have over a long
00100 //               period of time, and so it is less likely to drift.
00101 //               However, it may not be very precise for measuring
00102 //               short intervals.  On Windows, for instace, this is
00103 //               only accurate to within about 55 milliseconds.
00104 ////////////////////////////////////////////////////////////////////
00105 INLINE double ClockObject::
00106 get_long_time() const {
00107   return (_true_clock->get_long_time() - _start_long_time);
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: ClockObject::reset
00112 //       Access: Published
00113 //  Description: Simultaneously resets both the time and the frame
00114 //               count to zero.
00115 ////////////////////////////////////////////////////////////////////
00116 INLINE void ClockObject::
00117 reset() {
00118   set_real_time(0.0);
00119   set_frame_time(0.0);
00120   set_frame_count(0);
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: ClockObject::get_frame_count
00125 //       Access: Published
00126 //  Description: Returns the number of times tick() has been called
00127 //               since the ClockObject was created, or since it was
00128 //               last reset.  This is generally the number of frames
00129 //               that have been rendered.
00130 ////////////////////////////////////////////////////////////////////
00131 INLINE int ClockObject::
00132 get_frame_count() const {
00133   return _frame_count;
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: ClockObject::get_frame_rate
00138 //       Access: Published
00139 //  Description: Returns the average frame rate since the last reset.
00140 //               This is simply the total number of frames divided by
00141 //               the total elapsed time.
00142 ////////////////////////////////////////////////////////////////////
00143 INLINE double ClockObject::
00144 get_frame_rate() const {
00145   return (double)get_frame_count() / get_frame_time();
00146 }
00147 
00148 ////////////////////////////////////////////////////////////////////
00149 //     Function: ClockObject::get_dt
00150 //       Access: Published
00151 //  Description: Returns the elapsed time for the previous frame: the
00152 //               number of seconds elapsed between the last two calls
00153 //               to tick().
00154 ////////////////////////////////////////////////////////////////////
00155 INLINE double ClockObject::
00156 get_dt() const {
00157   return _dt;
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: ClockObject::set_dt
00162 //       Access: Published
00163 //  Description: In non-real-time mode, sets the number of seconds
00164 //               that should appear to elapse between frames.
00165 ////////////////////////////////////////////////////////////////////
00166 INLINE void ClockObject::
00167 set_dt(double dt) {
00168   if (_mode != M_non_real_time) {
00169     express_cat.error()
00170       << "ClockObject cannot set dt in real-time mode." << endl;
00171     return;
00172   }
00173 
00174   _dt = dt;
00175 }
00176 
00177 ////////////////////////////////////////////////////////////////////
00178 //     Function: ClockObject::get_max_dt
00179 //       Access: Published
00180 //  Description: Returns the current maximum allowable time elapsed
00181 //               between any two frames.  See set_max_dt().
00182 ////////////////////////////////////////////////////////////////////
00183 INLINE double ClockObject::
00184 get_max_dt() const {
00185   return _max_dt;
00186 }
00187 
00188 ////////////////////////////////////////////////////////////////////
00189 //     Function: ClockObject::set_max_dt
00190 //       Access: Published
00191 //  Description: Sets a limit on the value returned by get_dt().  If
00192 //               this value is less than zero, no limit is imposed;
00193 //               otherwise, this is the maximum value that will ever
00194 //               be returned by get_dt(), regardless of how much time
00195 //               has actually elapsed between frames.
00196 //
00197 //               This limit is only imposed in real-time mode; in
00198 //               non-real-time mode, the dt is fixed anyway and max_dt
00199 //               is ignored.
00200 //
00201 //               This is generally used to guarantee reasonable
00202 //               behavior even in the presence of a very slow or
00203 //               chuggy frame rame.
00204 ////////////////////////////////////////////////////////////////////
00205 INLINE void ClockObject::
00206 set_max_dt(double max_dt) {
00207   _max_dt = max_dt;
00208 }
00209 
00210 ////////////////////////////////////////////////////////////////////
00211 //     Function: ClockObject::get_global_clock
00212 //       Access: Published
00213 //  Description: Returns a pointer to the global ClockObject.  This is
00214 //               the ClockObject that most code should use for
00215 //               handling scene graph rendering and animation.
00216 ////////////////////////////////////////////////////////////////////
00217 INLINE ClockObject *ClockObject::
00218 get_global_clock() {
00219   if (_global_clock == (ClockObject *)NULL) {
00220     _global_clock = new ClockObject;
00221   }
00222   return _global_clock;
00223 }
00224 
00225 ////////////////////////////////////////////////////////////////////
00226 //     Function: TimeVal::contructor
00227 //       Access: Published
00228 //  Description:
00229 ////////////////////////////////////////////////////////////////////
00230 INLINE TimeVal::
00231 TimeVal(void) {
00232 }
00233 
00234 ////////////////////////////////////////////////////////////////////
00235 //     Function: TimeVal::get_sec
00236 //       Access: Published
00237 //  Description:
00238 ////////////////////////////////////////////////////////////////////
00239 INLINE ulong TimeVal::
00240 get_sec(void) const {
00241   return tv[0];
00242 }
00243 
00244 ////////////////////////////////////////////////////////////////////
00245 //     Function: TimeVal::get_usec
00246 //       Access: Published
00247 //  Description:
00248 ////////////////////////////////////////////////////////////////////
00249 INLINE ulong TimeVal::
00250 get_usec(void) const {
00251   return tv[1];
00252 }

Generated on Fri May 2 00:38:19 2003 for Panda by doxygen1.3