Bubba-3D  0.9.0
Awesome game engine!
Timer.cpp
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 
18 #include "timer.h"
19 
20 namespace utils {
21 
22 void Timer::start() {
23 #ifdef __linux__
24  gettimeofday(&tStart, nullptr);
25 #endif
26 #ifdef _WIN32
27  tStart = high_resolution_clock::now();
28 #endif
29 }
30 
31 void Timer::stop() {
32 #ifdef __linux__
33  gettimeofday(&tEnd, nullptr);
34 #endif
35 
36 #ifdef _WIN32
37  tEnd = high_resolution_clock::now();
38 #endif
39 }
40 
41 double Timer::getElapsedTime() {
42  double elapsedTime;
43 
44 #ifdef __linux__
45  elapsedTime = (tEnd.tv_sec - tStart.tv_sec) * 1000.0;
46  elapsedTime += (tEnd.tv_usec - tStart.tv_usec) / 1000.0;
47 #endif
48 
49 #ifdef _WIN32
50  duration<double> time_span = duration_cast<duration<double>>(tEnd - tStart);
51  elapsedTime = time_span.count() * 1000;
52 #endif
53 
54  return elapsedTime;
55 }
56 
57 }
Definition: timer.h:29