| 9 | bool usePerformance = false; |
| 10 | double performanceBase = 0; |
| 11 | double GetSystemTimer() |
| 12 | { |
| 13 | if( !timerInitialized ) |
| 14 | { |
| 15 | // We need to know how often the clock is updated |
| 16 | __int64 tps; |
| 17 | if( !QueryPerformanceFrequency((LARGE_INTEGER *)&tps) ) |
| 18 | usePerformance = false; |
| 19 | else |
| 20 | { |
| 21 | usePerformance = true; |
| 22 | ticksPerSecond = (double)tps; |
| 23 | |
| 24 | __int64 ticks; |
| 25 | QueryPerformanceCounter((LARGE_INTEGER *)&ticks); |
| 26 | performanceBase = (double)ticks/ticksPerSecond; |
| 27 | } |
| 28 | |
| 29 | timerInitialized = true; |
| 30 | } |
| 31 | |
| 32 | if( usePerformance ) |
| 33 | { |
| 34 | __int64 ticks; |
| 35 | QueryPerformanceCounter((LARGE_INTEGER *)&ticks); |
| 36 | |
| 37 | double t = (double)ticks/ticksPerSecond - performanceBase; |
| 38 | |
| 39 | // We need to calibrate the performance timer as it is known to jump from time to time |
| 40 | double t2 = (double)timeGetTime()/1000.0; |
| 41 | if( fabs(t-t2) > 0.1 ) |
| 42 | { |
| 43 | performanceBase += t - t2; |
| 44 | t = t2; |
| 45 | } |
| 46 | |
| 47 | return t; |
| 48 | } |
| 49 | else |
| 50 | return (double)timeGetTime()/1000.0; |
| 51 | } |
| 52 | |