1 // wintimer.h 2 // 3 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net> 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 10 #include <windows.h> 11 #include "timer.h" 12 13 class WindowsTimer : public Timer 14 { 15 public: 16 WindowsTimer(); 17 ~WindowsTimer(); 18 double getTime() const; 19 void reset(); 20 21 private: 22 LARGE_INTEGER freq; 23 LARGE_INTEGER start; 24 }; 25 26 WindowsTimer()27WindowsTimer::WindowsTimer() 28 { 29 QueryPerformanceFrequency(&freq); 30 reset(); 31 } 32 ~WindowsTimer()33WindowsTimer::~WindowsTimer() 34 { 35 } 36 getTime() const37double WindowsTimer::getTime() const 38 { 39 LARGE_INTEGER t; 40 QueryPerformanceCounter(&t); 41 return (double) (t.QuadPart - start.QuadPart) / (double) freq.QuadPart; 42 } 43 reset()44void WindowsTimer::reset() 45 { 46 QueryPerformanceCounter(&start); 47 } 48 CreateTimer()49Timer* CreateTimer() 50 { 51 return new WindowsTimer(); 52 } 53