Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

wintimer.cpp

Go to the documentation of this file.
00001 // wintimer.h
00002 // 
00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #include <windows.h>
00011 #include "timer.h"
00012 
00013 class WindowsTimer : public Timer
00014 {
00015 public:
00016     WindowsTimer();
00017     ~WindowsTimer();
00018     double getTime() const;
00019     void reset();
00020 
00021 private:
00022     LARGE_INTEGER freq;
00023     LARGE_INTEGER start;
00024 };
00025 
00026 
00027 WindowsTimer::WindowsTimer()
00028 {
00029     QueryPerformanceFrequency(&freq);
00030     reset();
00031 }
00032 
00033 WindowsTimer::~WindowsTimer()
00034 {
00035 }
00036 
00037 double WindowsTimer::getTime() const
00038 {
00039     LARGE_INTEGER t;
00040     QueryPerformanceCounter(&t);
00041     return (double) (t.QuadPart - start.QuadPart) / (double) freq.QuadPart;
00042 }
00043 
00044 void WindowsTimer::reset()
00045 {
00046     QueryPerformanceCounter(&start);
00047 }
00048 
00049 Timer* CreateTimer()
00050 {
00051     return new WindowsTimer();
00052 }

Generated on Sat Jan 14 22:30:32 2006 for Celestia by  doxygen 1.4.1