CPrecisionClock.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 2048 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CPrecisionClockH
46 #define CPrecisionClockH
47 //------------------------------------------------------------------------------
48 #include "system/CGlobals.h"
49 //------------------------------------------------------------------------------
50 
51 //------------------------------------------------------------------------------
52 namespace chai3d {
53 //------------------------------------------------------------------------------
54 
55 //==============================================================================
63 //==============================================================================
64 
65 //==============================================================================
83 //==============================================================================
84 
86 {
87  //--------------------------------------------------------------------------
88  // CONSTRUCTOR & DESTRUCTOR:
89  //--------------------------------------------------------------------------
90 
91 public:
92 
95 
97  virtual ~cPrecisionClock() {};
98 
99 
100  //--------------------------------------------------------------------------
101  // PUBLIC METHODS:
102  //--------------------------------------------------------------------------
103 
104 public:
105 
107  void reset(const double a_currentTime = 0.0);
108 
110  double start(bool a_resetClock = false);
111 
113  double stop();
114 
116  bool on() const { return (m_on); };
117 
119  double getCurrentTimeSeconds() const;
120 
122  void setTimeoutPeriodSeconds(const double a_timeoutPeriod);
123 
125  double getTimeoutPeriodSeconds() const { return (m_timeoutPeriod); }
126 
128  bool timeoutOccurred() const ;
129 
131  bool highResolution() const { return (m_highres); };
132 
134  static double getCPUTimeSeconds();
135 
136 
137  //--------------------------------------------------------------------------
138  // PROTECTED METHODS:
139  //--------------------------------------------------------------------------
140 
141 protected:
142 
144  static void initialize();
145 
146 
147  //--------------------------------------------------------------------------
148  // PROTECTED MEMBERS:
149  //--------------------------------------------------------------------------
150 
151 protected:
152 
153 #if defined(WIN32) | defined(WIN64)
154  static LARGE_INTEGER m_freq;
156 #endif
157 
159  static bool m_highres;
160 
162  static bool m_initialized;
163 
166 
168  double m_timeStart;
169 
172 
175 
177  bool m_on;
178 };
179 
180 //------------------------------------------------------------------------------
181 } // namespace chai3d
182 //------------------------------------------------------------------------------
183 
184 //------------------------------------------------------------------------------
185 #endif
186 //------------------------------------------------------------------------------
bool on() const
This method returns true if the clock is running (ON), otherwise false if the clock is paused (OFF)...
Definition: CPrecisionClock.h:116
static LARGE_INTEGER m_freq
Stores information about CPU high precision clock.
Definition: CPrecisionClock.h:155
This class implements a high precision clock.
Definition: CPrecisionClock.h:85
bool timeoutOccurred() const
This method returns true if timeout has occurred, otherwise return false.
Definition: CPrecisionClock.cpp:202
static double getCPUTimeSeconds()
This method returns the raw CPU time in seconds.
Definition: CPrecisionClock.cpp:241
static bool m_initialized
If true, then static members of cPrecisionClock have been initialized.
Definition: CPrecisionClock.h:162
bool m_on
If true, then clock is currently ON.
Definition: CPrecisionClock.h:177
double start(bool a_resetClock=false)
This method starts the clock with optional reset.
Definition: CPrecisionClock.cpp:143
bool highResolution() const
This method returns true if the high resolution CPU clock is available on this computer, false. otherwise.
Definition: CPrecisionClock.h:131
void reset(const double a_currentTime=0.0)
This method resets the clock.
Definition: CPrecisionClock.cpp:122
Implements option settings for CHAI3D.
double stop()
This method stops the clock and return the elapsed time.
Definition: CPrecisionClock.cpp:167
double m_timeoutStart
Clock time in seconds when timer was started.
Definition: CPrecisionClock.h:174
double getTimeoutPeriodSeconds() const
This method reads the programmed timeout period is seconds.
Definition: CPrecisionClock.h:125
double getCurrentTimeSeconds() const
This method returns the current clock time in seconds.
Definition: CPrecisionClock.cpp:223
static void initialize()
This method initializes all static variables of cPrecisionClock.
Definition: CPrecisionClock.cpp:92
cPrecisionClock()
Constructor of cPrecisionClock.
Definition: CPrecisionClock.cpp:65
double m_timeStart
CPU time in seconds when clock was started.
Definition: CPrecisionClock.h:168
Definition: CAudioBuffer.cpp:56
void setTimeoutPeriodSeconds(const double a_timeoutPeriod)
This method sets the period in seconds before a timeout occurs (you need to poll for this)...
Definition: CPrecisionClock.cpp:189
static bool m_highres
If true, then high precision CPU clock is available.
Definition: CPrecisionClock.h:159
double m_timeoutPeriod
Timeout period in seconds.
Definition: CPrecisionClock.h:171
double m_timeAccumulated
Time accumulated between previous calls to start() and stop().
Definition: CPrecisionClock.h:165
virtual ~cPrecisionClock()
Destructor of cPrecisionClock.
Definition: CPrecisionClock.h:97