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

panda/src/express/clockObject.h

Go to the documentation of this file.
00001 // Filename: clockObject.h
00002 // Created by:  drose (19Feb99)
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 #ifndef CLOCKOBJECT_H
00020 #define CLOCKOBJECT_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "trueClock.h"
00025 #include "config_express.h"
00026 
00027 class EXPCL_PANDAEXPRESS TimeVal {
00028 PUBLISHED:
00029   INLINE TimeVal(void);
00030   INLINE ulong get_sec(void) const;
00031   INLINE ulong get_usec(void) const;
00032   ulong tv[2];
00033 };
00034 
00035 BEGIN_PUBLISH
00036 
00037 EXPCL_PANDAEXPRESS void get_time_of_day(TimeVal &tv);
00038 
00039 END_PUBLISH
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //       Class : ClockObject
00043 // Description : A ClockObject keeps track of elapsed real time and
00044 //               discrete time.  It can run in two modes: In normal
00045 //               mode, get_frame_time() returns the time as of the
00046 //               last time tick() was called.  This is the "discrete"
00047 //               time, and is usually used to get the time as of, for
00048 //               instance, the beginning of the current frame.  In
00049 //               non-real-time mode, get_frame_time() returns a
00050 //               constant increment since the last time tick() was
00051 //               called; this is useful when it is desirable to fake
00052 //               the clock out, for instance for non-real-time
00053 //               animation rendering.
00054 //
00055 //               In both modes, get_real_time() always returns the
00056 //               elapsed real time in seconds since the ClockObject
00057 //               was constructed, or since it was last reset.
00058 //
00059 //               You can create your own ClockObject whenever you want
00060 //               to have your own local timer.  There is also a
00061 //               default, global ClockObject intended to represent
00062 //               global time for the application; this is normally set
00063 //               up to tick every frame so that its get_frame_time()
00064 //               will return the time for the current frame.
00065 ////////////////////////////////////////////////////////////////////
00066 class EXPCL_PANDAEXPRESS ClockObject {
00067 PUBLISHED:
00068   enum Mode {
00069     M_normal,
00070     M_non_real_time,
00071   };
00072 
00073   ClockObject();
00074   INLINE ~ClockObject();
00075 
00076   INLINE void set_mode(Mode mode);
00077   INLINE Mode get_mode() const;
00078 
00079   INLINE double get_frame_time() const;
00080   INLINE double get_real_time() const;
00081   INLINE double get_long_time() const;
00082 
00083   INLINE void reset();
00084   void set_real_time(double time);
00085   void set_frame_time(double time);
00086   void set_frame_count(int frame_count);
00087 
00088   INLINE int get_frame_count() const;
00089   INLINE double get_frame_rate() const;
00090 
00091   INLINE double get_dt() const;
00092   INLINE void set_dt(double dt);
00093 
00094   INLINE double get_max_dt() const;
00095   INLINE void set_max_dt(double max_dt);
00096 
00097   void tick();
00098   void sync_frame_time();
00099 
00100   INLINE static ClockObject *get_global_clock();
00101 
00102 private:
00103   TrueClock *_true_clock;
00104   Mode _mode;
00105   double _start_short_time;
00106   double _start_long_time;
00107   int _frame_count;
00108   double _actual_frame_time;
00109   double _reported_frame_time;
00110   double _dt;
00111   double _max_dt;
00112 
00113   static ClockObject *_global_clock;
00114 };
00115 
00116 #include "clockObject.I"
00117 
00118 #endif
00119 

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