Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UPrecisionTimer.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2014 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef UPRECISION_TIMER_H
22 #define UPRECISION_TIMER_H
23 
24 #ifdef _WIN32
25 #ifndef WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN
27 #endif
28 #include <windows.h>
29 
30 namespace OpenSkyNet {
31  namespace Utils {
32  class PrecisionTimer {
33  LARGE_INTEGER _freq, _begin, _end, _stamp;
34  public:
35  PrecisionTimer() { QueryPerformanceFrequency(&_freq); }
36 
37  inline void start() { QueryPerformanceCounter(&_begin); }
38 
39  inline double stop() {
40  QueryPerformanceCounter(&_end);
41  //return seconds passed
42  return (static_cast<double>(_end.QuadPart - _begin.QuadPart) / _freq.QuadPart);
43  }
44 
45  inline double stamp() {
46  QueryPerformanceCounter(&_stamp);
47  //return in seconds
48  return (static_cast<double>(_stamp.QuadPart) / _freq.QuadPart);
49  }
50  };
51  }
52 }
53 #else
54 #include <sys/time.h>
55 
56 namespace OpenSkyNet {
57  namespace Utils {
59  timeval _begin, _end, _stamp;
60  public:
61  inline void start() { gettimeofday(&_begin, 0); }
62 
63  inline double stop() {
64  gettimeofday(&_end, 0);
65  //return seconds passed
66  double t1 = static_cast<double>(_begin.tv_sec + static_cast<double>(_begin.tv_usec)/(1000000));
67  double t2 = static_cast<double>(_end.tv_sec + static_cast<double>(_end.tv_usec)/(1000000));
68  return t2 - t1;
69  }
70 
71  inline double stamp() {
72  gettimeofday(&_stamp, 0);
73  //return in seconds
74  return static_cast<double>(_stamp.tv_sec + static_cast<double>(_stamp.tv_usec)/(1000000));
75  }
76  };
77  }
78 }
79 #endif
80 
81 #endif //UPRECISION_TIMER_H
void start()
Definition: UPrecisionTimer.h:61
double stop()
Definition: UPrecisionTimer.h:63
double stamp()
Definition: UPrecisionTimer.h:71
Definition: UPrecisionTimer.h:58