| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "embedders/openglui/common/timer.h" | 5 #include "embedders/openglui/common/timer.h" |
| 6 | 6 |
| 7 #define NANO (+1.0E-9) | 7 #define NANO (+1.0E-9) |
| 8 | 8 |
| 9 #ifdef __MACH__ | 9 #ifdef __MACH__ |
| 10 #include <mach/mach.h> | 10 #include <mach/mach.h> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 gettimeofday(&now, NULL); | 36 gettimeofday(&now, NULL); |
| 37 t->tv_sec = now.tv_sec; | 37 t->tv_sec = now.tv_sec; |
| 38 t->tv_nsec = now.tv_usec * 1000; | 38 t->tv_nsec = now.tv_usec * 1000; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 Timer::Timer() : elapsed_(0.0f), last_time_(0.0) { | 43 Timer::Timer() : elapsed_(0.0f), last_time_(0.0) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 void Timer::reset() { | 46 void Timer::Reset() { |
| 47 elapsed_ = 0.0f; | 47 elapsed_ = 0.0f; |
| 48 last_time_ = now(); | 48 last_time_ = Now(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void Timer::update() { | 51 void Timer::Update() { |
| 52 double current = now(); | 52 double current = Now(); |
| 53 elapsed_ = (current - last_time_); | 53 elapsed_ = (current - last_time_); |
| 54 last_time_ = current; | 54 last_time_ = current; |
| 55 } | 55 } |
| 56 | 56 |
| 57 double Timer::now() { | 57 double Timer::Now() { |
| 58 timespec timeval; | 58 timespec timeval; |
| 59 clock_gettime(CLOCK_MONOTONIC, &timeval); | 59 clock_gettime(CLOCK_MONOTONIC, &timeval); |
| 60 return timeval.tv_sec + (timeval.tv_nsec * NANO); | 60 return timeval.tv_sec + (timeval.tv_nsec * NANO); |
| 61 } | 61 } |
| 62 | 62 |
| 63 float Timer::elapsed() { | 63 float Timer::Elapsed() { |
| 64 return elapsed_; | 64 return elapsed_; |
| 65 } | 65 } |
| 66 | 66 |
| OLD | NEW |