diff options
author | David Robillard <d@drobilla.net> | 2019-07-21 09:54:54 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-07-21 14:44:19 +0200 |
commit | 753af54d546963bd86c64ca3c5dde5cc8c92c4c8 (patch) | |
tree | 86109f79f8dda2394f43c5bb4aac044e19d5170a /pugl | |
parent | 5ba0ea7cd8cfec3f374f380a03e144e24f43a12c (diff) | |
download | pugl-753af54d546963bd86c64ca3c5dde5cc8c92c4c8.tar.gz pugl-753af54d546963bd86c64ca3c5dde5cc8c92c4c8.tar.bz2 pugl-753af54d546963bd86c64ca3c5dde5cc8c92c4c8.zip |
Make time start from approximately zero
Diffstat (limited to 'pugl')
-rw-r--r-- | pugl/pugl_internal.h | 11 | ||||
-rw-r--r-- | pugl/pugl_internal_types.h | 1 | ||||
-rw-r--r-- | pugl/pugl_osx.m | 2 | ||||
-rw-r--r-- | pugl/pugl_win.c | 15 | ||||
-rw-r--r-- | pugl/pugl_x11.c | 2 |
5 files changed, 18 insertions, 13 deletions
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h index 2860a7f..fea5959 100644 --- a/pugl/pugl_internal.h +++ b/pugl/pugl_internal.h @@ -61,11 +61,12 @@ puglInit(int* pargc, char** argv) return NULL; } - view->hints = puglDefaultHints(); - view->ctx_type = PUGL_GL; - view->impl = impl; - view->width = 640; - view->height = 480; + view->hints = puglDefaultHints(); + view->ctx_type = PUGL_GL; + view->impl = impl; + view->width = 640; + view->height = 480; + view->start_time = puglGetTime(view); return view; } diff --git a/pugl/pugl_internal_types.h b/pugl/pugl_internal_types.h index 19452cd..9e718ee 100644 --- a/pugl/pugl_internal_types.h +++ b/pugl/pugl_internal_types.h @@ -54,6 +54,7 @@ struct PuglViewImpl { char* windowClass; PuglNativeWindow parent; PuglContextType ctx_type; + double start_time; uintptr_t transient_parent; PuglHints hints; diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 519b7dd..1870207 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -743,7 +743,7 @@ puglGetTime(PuglView* view) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (double)ts.tv_sec + ts.tv_nsec / 1000000000.0; + return ((double)ts.tv_sec + ts.tv_nsec / 1000000000.0) - view->start_time; } void diff --git a/pugl/pugl_win.c b/pugl/pugl_win.c index e751df9..5f9d555 100644 --- a/pugl/pugl_win.c +++ b/pugl/pugl_win.c @@ -99,7 +99,13 @@ wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); PuglInternals* puglInitInternals(void) { - return (PuglInternals*)calloc(1, sizeof(PuglInternals)); + PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals)); + + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + impl->timerFrequency = (double)frequency.QuadPart; + + return impl; } void @@ -324,10 +330,6 @@ puglCreateWindow(PuglView* view, const char* title) wglSwapInterval(1); } - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); - impl->timerFrequency = (double)frequency.QuadPart; - SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view); return 0; @@ -770,7 +772,8 @@ puglGetTime(PuglView* view) { LARGE_INTEGER count; QueryPerformanceCounter(&count); - return (double)count.QuadPart / view->impl->timerFrequency; + const double now = (double)count.QuadPart / view->impl->timerFrequency; + return now - view->start_time; } void diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index d7db801..15142e1 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -524,7 +524,7 @@ puglGetTime(PuglView* view) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - return (double)ts.tv_sec + ts.tv_nsec / 1000000000.0; + return ((double)ts.tv_sec + ts.tv_nsec / 1000000000.0) - view->start_time; } void |