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/pugl_win.c | |
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/pugl_win.c')
-rw-r--r-- | pugl/pugl_win.c | 15 |
1 files changed, 9 insertions, 6 deletions
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 |