Warning, file /education/gcompris/external/qml-box2d/Box2D/Common/b2Timer.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (c) 2011 Erin Catto http://box2d.org 0003 * 0004 * This software is provided 'as-is', without any express or implied 0005 * warranty. In no event will the authors be held liable for any damages 0006 * arising from the use of this software. 0007 * Permission is granted to anyone to use this software for any purpose, 0008 * including commercial applications, and to alter it and redistribute it 0009 * freely, subject to the following restrictions: 0010 * 1. The origin of this software must not be misrepresented; you must not 0011 * claim that you wrote the original software. If you use this software 0012 * in a product, an acknowledgment in the product documentation would be 0013 * appreciated but is not required. 0014 * 2. Altered source versions must be plainly marked as such, and must not be 0015 * misrepresented as being the original software. 0016 * 3. This notice may not be removed or altered from any source distribution. 0017 */ 0018 0019 #include <Box2D/Common/b2Timer.h> 0020 0021 #if defined(_WIN32) 0022 0023 float64 b2Timer::s_invFrequency = 0.0f; 0024 0025 #define WIN32_LEAN_AND_MEAN 0026 #include <windows.h> 0027 0028 b2Timer::b2Timer() 0029 { 0030 LARGE_INTEGER largeInteger; 0031 0032 if (s_invFrequency == 0.0f) 0033 { 0034 QueryPerformanceFrequency(&largeInteger); 0035 s_invFrequency = float64(largeInteger.QuadPart); 0036 if (s_invFrequency > 0.0f) 0037 { 0038 s_invFrequency = 1000.0f / s_invFrequency; 0039 } 0040 } 0041 0042 QueryPerformanceCounter(&largeInteger); 0043 m_start = float64(largeInteger.QuadPart); 0044 } 0045 0046 void b2Timer::Reset() 0047 { 0048 LARGE_INTEGER largeInteger; 0049 QueryPerformanceCounter(&largeInteger); 0050 m_start = float64(largeInteger.QuadPart); 0051 } 0052 0053 float32 b2Timer::GetMilliseconds() const 0054 { 0055 LARGE_INTEGER largeInteger; 0056 QueryPerformanceCounter(&largeInteger); 0057 float64 count = float64(largeInteger.QuadPart); 0058 float32 ms = float32(s_invFrequency * (count - m_start)); 0059 return ms; 0060 } 0061 0062 #elif defined(__linux__) || defined (__APPLE__) 0063 0064 #include <sys/time.h> 0065 0066 b2Timer::b2Timer() 0067 { 0068 Reset(); 0069 } 0070 0071 void b2Timer::Reset() 0072 { 0073 timeval t; 0074 gettimeofday(&t, 0); 0075 m_start_sec = t.tv_sec; 0076 m_start_usec = t.tv_usec; 0077 } 0078 0079 float32 b2Timer::GetMilliseconds() const 0080 { 0081 timeval t; 0082 gettimeofday(&t, 0); 0083 return 1000.0f * (t.tv_sec - m_start_sec) + 0.001f * (t.tv_usec - m_start_usec); 0084 } 0085 0086 #else 0087 0088 b2Timer::b2Timer() 0089 { 0090 } 0091 0092 void b2Timer::Reset() 0093 { 0094 } 0095 0096 float32 b2Timer::GetMilliseconds() const 0097 { 0098 return 0.0f; 0099 } 0100 0101 #endif