My Project
Loading...
Searching...
No Matches
CPrecisionClock.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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.3.0
41*/
42//==============================================================================
43
44//------------------------------------------------------------------------------
45#ifndef CPrecisionClockH
46#define CPrecisionClockH
47//------------------------------------------------------------------------------
48#include "system/CGlobals.h"
49//------------------------------------------------------------------------------
50
51//------------------------------------------------------------------------------
52namespace chai3d {
53//------------------------------------------------------------------------------
54
55//==============================================================================
63//==============================================================================
64
65//==============================================================================
83//==============================================================================
84
86{
87 //--------------------------------------------------------------------------
88 // CONSTRUCTOR & DESTRUCTOR:
89 //--------------------------------------------------------------------------
90
91public:
92
95
97 virtual ~cPrecisionClock() {};
98
99
100 //--------------------------------------------------------------------------
101 // PUBLIC METHODS:
102 //--------------------------------------------------------------------------
103
104public:
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
141protected:
142
144 static void initialize();
145
146
147 //--------------------------------------------------------------------------
148 // PROTECTED MEMBERS:
149 //--------------------------------------------------------------------------
150
151protected:
152
153#if defined(WIN32) | defined(WIN64)
155 static LARGE_INTEGER m_freq;
156#endif
157
159 static bool m_highres;
160
162 static bool m_initialized;
163
166
169
172
175
177 bool m_on;
178};
179
180//------------------------------------------------------------------------------
181} // namespace chai3d
182//------------------------------------------------------------------------------
183
184//------------------------------------------------------------------------------
185#endif
186//------------------------------------------------------------------------------
Implements option settings for CHAI3D.
This class implements a high precision clock.
Definition CPrecisionClock.h:86
static bool m_initialized
If true, then static members of cPrecisionClock have been initialized.
Definition CPrecisionClock.h:162
static void initialize()
This method initializes all static variables of cPrecisionClock.
Definition CPrecisionClock.cpp:94
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
virtual ~cPrecisionClock()
Destructor of cPrecisionClock.
Definition CPrecisionClock.h:97
static LARGE_INTEGER m_freq
Stores information about CPU high precision clock.
Definition CPrecisionClock.h:155
double m_timeAccumulated
Time accumulated between previous calls to start() and stop().
Definition CPrecisionClock.h:165
double start(bool a_resetClock=false)
This method starts the clock with optional reset.
Definition CPrecisionClock.cpp:145
double m_timeStart
CPU time in seconds when clock was started.
Definition CPrecisionClock.h:168
double stop()
This method stops the clock and return the elapsed time.
Definition CPrecisionClock.cpp:169
double getTimeoutPeriodSeconds() const
This method reads the programmed timeout period is seconds.
Definition CPrecisionClock.h:125
double m_timeoutPeriod
Timeout period in seconds.
Definition CPrecisionClock.h:171
bool timeoutOccurred() const
This method returns true if timeout has occurred, otherwise return false.
Definition CPrecisionClock.cpp:204
bool highResolution() const
This method returns true if the high resolution CPU clock is available on this computer,...
Definition CPrecisionClock.h:131
static double getCPUTimeSeconds()
This method returns the raw CPU time in seconds.
Definition CPrecisionClock.cpp:243
double getCurrentTimeSeconds() const
This method returns the current clock time in seconds.
Definition CPrecisionClock.cpp:225
cPrecisionClock()
Constructor of cPrecisionClock.
Definition CPrecisionClock.cpp:67
static bool m_highres
If true, then high precision CPU clock is available.
Definition CPrecisionClock.h:159
void reset(const double a_currentTime=0.0)
This method resets the clock.
Definition CPrecisionClock.cpp:124
bool m_on
If true, then clock is currently ON.
Definition CPrecisionClock.h:177
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:191
double m_timeoutStart
Clock time in seconds when timer was started.
Definition CPrecisionClock.h:174
Definition CAudioBuffer.cpp:57