Panda3D
trueClock.I
1 // Filename: trueClock.I
2 // Created by: drose (04Jul00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 #if defined(WIN32_VC) || defined(WIN64_VC)
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: TrueClock::get_short_time, Win32 implementation
20 // Access: Published
21 // Description:
22 ////////////////////////////////////////////////////////////////////
23 INLINE double TrueClock::
24 get_short_time() {
25  bool is_paranoid_clock = get_paranoid_clock();
26 
27  if (is_paranoid_clock) {
28  _lock.acquire();
29  }
30 
31  double time = get_short_raw_time();
32 
33  if (is_paranoid_clock) {
34  // Check for rollforwards, rollbacks, and compensate for Speed
35  // Gear type programs by verifying against the time of day clock.
36  time = correct_time(time);
37  _lock.release();
38  }
39 
40  return time;
41 }
42 
43 #else // WIN32_VC
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: TrueClock::get_short_time, Posix implementation
47 // Access: Published
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 INLINE double TrueClock::
51 get_short_time() {
52  return get_short_raw_time();
53 }
54 
55 #endif // WIN32_VC
56 
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: TrueClock::get_error_count
60 // Access: Published
61 // Description: Returns the number of clock errors that have
62 // been detected. Each time a clock error is detected,
63 // in which the value returned by either of the above
64 // methods is suspect, the value returned by this method
65 // will be incremented. Applications can monitor this
66 // value and react, for instance, by resynchronizing
67 // their clocks each time this value changes.
68 ////////////////////////////////////////////////////////////////////
69 INLINE int TrueClock::
70 get_error_count() const {
71  return _error_count;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: TrueClock::get_global_ptr
76 // Access: Published, Static
77 // Description: Returns a pointer to the one TrueClock object in
78 // the world.
79 ////////////////////////////////////////////////////////////////////
80 INLINE TrueClock *TrueClock::
82  if (_global_ptr == (TrueClock *)NULL) {
83  _global_ptr = new TrueClock;
84  }
85  return _global_ptr;
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: TrueClock::Destructor
90 // Access: Protected
91 // Description: A protected destructor because no one should try to
92 // delete the global TrueClock.
93 ////////////////////////////////////////////////////////////////////
94 INLINE TrueClock::
95 ~TrueClock() {
96 }
static TrueClock * get_global_ptr()
Returns a pointer to the one TrueClock object in the world.
Definition: trueClock.I:81
An interface to whatever real-time clock we might have available in the current environment.
Definition: trueClock.h:38
int get_error_count() const
Returns the number of clock errors that have been detected.
Definition: trueClock.I:70