summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat/timer.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-26 07:10:49 +0100
committerStanislaw Halik <sthalik@misaki.pl>2015-10-26 07:10:49 +0100
commit20f83ad3149237087d2d0a81a27e6d511a5e7973 (patch)
tree3aaf2bc964a026292451efaa553744165d3e1c93 /opentrack-compat/timer.hpp
parenta815d8dfe1b452e0cab9b588a9d4ec4650a5bdda (diff)
parent8f7e5c0441237a9c8c187f24a424f6c77c5e397e (diff)
Merge branch 'unstable' into trackhat
* unstable: main: use camera-based centering by default settings: clarify center method usage accela: fix typo win32: try win_key with modifier first shortcuts: remove obsolete code on win32 shortcuts: allow for numpad on win32 qfc: drop nan check pt: drop nan check shortcuts: allow for numlock on win32 accela: remove too many nan checks timer: guard against overflow on win32 accela: remove "done" logic timer: sprinkle some const shortcuts: allow for binding same key to multiple functions qfc: guard against unlikely division by zero cmake: update toolchain file
Diffstat (limited to 'opentrack-compat/timer.hpp')
-rw-r--r--opentrack-compat/timer.hpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/opentrack-compat/timer.hpp b/opentrack-compat/timer.hpp
index 8192aa83..f0741295 100644
--- a/opentrack-compat/timer.hpp
+++ b/opentrack-compat/timer.hpp
@@ -24,9 +24,7 @@ static inline void opentrack_clock_gettime(int, struct timespec* ts)
(void) QueryPerformanceCounter(&d);
- long long part = d.QuadPart;
- part *= 1000000000ULL;
- part /= freq.QuadPart;
+ long long part = d.QuadPart / ((long double)freq.QuadPart) * 1000000000.L;
ts->tv_sec = part / 1000000000ULL;
ts->tv_nsec = part % 1000000000ULL;
@@ -54,7 +52,7 @@ static inline void clock_gettime(int, struct timespec* ts)
class Timer {
private:
struct timespec state;
- long long conv(const struct timespec& cur)
+ long long conv(const struct timespec& cur) const
{
return (cur.tv_sec - state.tv_sec) * 1000000000LL + (cur.tv_nsec - state.tv_nsec);
}
@@ -65,12 +63,12 @@ public:
void start() {
(void) clock_gettime(CLOCK_MONOTONIC, &state);
}
- long long elapsed() {
+ long long elapsed() const {
struct timespec cur;
(void) clock_gettime(CLOCK_MONOTONIC, &cur);
return conv(cur);
}
- long elapsed_ms() {
+ long elapsed_ms() const {
return elapsed() / 1000000L;
}
};