b2Timer.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2011 Erin Catto http://box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 
19 #include <Box2D/Common/b2Timer.h>
20 
21 #if defined(_WIN32)
22 
23 float64 b2Timer::s_invFrequency = 0.0f;
24 
25 #define WIN32_LEAN_AND_MEAN
26 #include <windows.h>
27 
29 {
30  LARGE_INTEGER largeInteger;
31 
32  if (s_invFrequency == 0.0f)
33  {
34  QueryPerformanceFrequency(&largeInteger);
35  s_invFrequency = float64(largeInteger.QuadPart);
36  if (s_invFrequency > 0.0f)
37  {
38  s_invFrequency = 1000.0f / s_invFrequency;
39  }
40  }
41 
42  QueryPerformanceCounter(&largeInteger);
43  m_start = float64(largeInteger.QuadPart);
44 }
45 
46 void b2Timer::Reset()
47 {
48  LARGE_INTEGER largeInteger;
49  QueryPerformanceCounter(&largeInteger);
50  m_start = float64(largeInteger.QuadPart);
51 }
52 
54 {
55  LARGE_INTEGER largeInteger;
56  QueryPerformanceCounter(&largeInteger);
57  float64 count = float64(largeInteger.QuadPart);
58  float32 ms = float32(s_invFrequency * (count - m_start));
59  return ms;
60 }
61 
62 #elif defined(__linux__) || defined (__APPLE__)
63 
64 #include <sys/time.h>
65 
67 {
68  Reset();
69 }
70 
71 void b2Timer::Reset()
72 {
73  timeval t;
74  gettimeofday(&t, 0);
75  m_start_sec = t.tv_sec;
76  m_start_usec = t.tv_usec;
77 }
78 
80 {
81  timeval t;
82  gettimeofday(&t, 0);
83  return 1000.0f * (t.tv_sec - m_start_sec) + 0.001f * (t.tv_usec - m_start_usec);
84 }
85 
86 #else
87 
89 {
90 }
91 
93 {
94 }
95 
97 {
98  return 0.0f;
99 }
100 
101 #endif
float32 GetMilliseconds() const
Get the time since construction or the last reset.
Definition: b2Timer.cpp:96
b2Timer()
Constructor.
Definition: b2Timer.cpp:88
void Reset()
Reset the timer.
Definition: b2Timer.cpp:92
double float64
Definition: b2Settings.h:36
float float32
Definition: b2Settings.h:35


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40