aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pugl/detail/implementation.c3
-rw-r--r--pugl/detail/mac.m4
-rw-r--r--pugl/detail/types.h2
-rw-r--r--pugl/detail/win.c6
-rw-r--r--pugl/detail/x11.c4
-rw-r--r--pugl/pugl.h20
-rw-r--r--test/pugl_cairo_test.c13
-rw-r--r--test/pugl_test.c8
-rw-r--r--test/test_utils.h8
9 files changed, 36 insertions, 32 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index 29daf15..6ec19c2 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -67,6 +67,8 @@ puglNewWorld(void)
return NULL;
}
+ world->startTime = puglGetTime(world);
+
return world;
}
@@ -90,7 +92,6 @@ puglNewView(PuglWorld* const world)
view->world = world;
view->width = 640;
view->height = 480;
- view->start_time = puglGetTime(view);
puglSetDefaultHints(view->hints);
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index 23344ed..527724d 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -868,9 +868,9 @@ puglGetProcAddress(const char *name)
}
double
-puglGetTime(PuglView* view)
+puglGetTime(const PuglWorld* world)
{
- return (mach_absolute_time() / 1e9) - view->start_time;
+ return (mach_absolute_time() / 1e9) - world->startTime;
}
void
diff --git a/pugl/detail/types.h b/pugl/detail/types.h
index fdfb0f6..e279833 100644
--- a/pugl/detail/types.h
+++ b/pugl/detail/types.h
@@ -54,7 +54,6 @@ struct PuglViewImpl {
PuglEventFunc eventFunc;
char* windowClass;
PuglNativeWindow parent;
- double start_time;
uintptr_t transient_parent;
PuglHints hints;
int width;
@@ -71,6 +70,7 @@ struct PuglViewImpl {
/** Cross-platform world definition. */
struct PuglWorldImpl {
PuglWorldInternals* impl;
+ double startTime;
size_t numViews;
PuglView** views;
};
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 804c883..6a0825a 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -704,12 +704,12 @@ wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
}
double
-puglGetTime(PuglView* view)
+puglGetTime(const PuglWorld* world)
{
LARGE_INTEGER count;
QueryPerformanceCounter(&count);
- return ((double)count.QuadPart / view->world->impl->timerFrequency -
- view->start_time);
+ return ((double)count.QuadPart / world->impl->timerFrequency -
+ world->startTime);
}
void
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index e0b3dea..d54f1bf 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -600,11 +600,11 @@ puglProcessEvents(PuglView* view)
}
double
-puglGetTime(PuglView* view)
+puglGetTime(const PuglWorld* world)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- return ((double)ts.tv_sec + ts.tv_nsec / 1000000000.0) - view->start_time;
+ return ((double)ts.tv_sec + ts.tv_nsec / 1000000000.0) - world->startTime;
}
void
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 0dc5fc3..e7c7333 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -446,6 +446,16 @@ PUGL_API void
puglFreeWorld(PuglWorld* world);
/**
+ Return the time in seconds.
+
+ This is a monotonically increasing clock with high resolution. The returned
+ time is only useful to compare against other times returned by this
+ function, its absolute value has no meaning.
+*/
+PUGL_API double
+puglGetTime(const PuglWorld* world);
+
+/**
@}
@name Initialization
Configuration functions which must be called before creating a window.
@@ -748,16 +758,6 @@ PUGL_API PuglGlFunc
puglGetProcAddress(const char* name);
/**
- Return the time in seconds.
-
- This is a monotonically increasing clock with high resolution. The returned
- time is only useful to compare against other times returned by this
- function, its absolute value has no meaning.
-*/
-PUGL_API double
-puglGetTime(PuglView* view);
-
-/**
Request a redisplay on the next call to puglProcessEvents().
*/
PUGL_API void
diff --git a/test/pugl_cairo_test.c b/test/pugl_cairo_test.c
index 3cdf904..7779069 100644
--- a/test/pugl_cairo_test.c
+++ b/test/pugl_cairo_test.c
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <string.h>
+static PuglWorld* world = NULL;
+
static bool continuous = false;
static int quit = 0;
static bool entered = false;
@@ -130,7 +132,7 @@ onDisplay(PuglView* view)
// Draw button
for (Button* b = buttons; b->label; ++b) {
- buttonDraw(cr, b, continuous ? puglGetTime(view) : 0.0);
+ buttonDraw(cr, b, continuous ? puglGetTime(world) : 0.0);
}
++framesDrawn;
@@ -202,8 +204,9 @@ main(int argc, char** argv)
}
}
- PuglWorld* world = puglNewWorld();
- PuglView* view = puglNewView(world);
+ world = puglNewWorld();
+
+ PuglView* view = puglNewView(world);
puglInitWindowClass(view, "PuglCairoTest");
puglInitWindowSize(view, 512, 512);
puglInitWindowMinSize(view, 256, 256);
@@ -219,7 +222,7 @@ main(int argc, char** argv)
puglShowWindow(view);
- PuglFpsPrinter fpsPrinter = { puglGetTime(view) };
+ PuglFpsPrinter fpsPrinter = { puglGetTime(world) };
while (!quit) {
if (continuous) {
puglPostRedisplay(view);
@@ -230,7 +233,7 @@ main(int argc, char** argv)
puglProcessEvents(view);
if (continuous) {
- puglPrintFps(view, &fpsPrinter, &framesDrawn);
+ puglPrintFps(world, &fpsPrinter, &framesDrawn);
}
}
diff --git a/test/pugl_test.c b/test/pugl_test.c
index b012868..c4df272 100644
--- a/test/pugl_test.c
+++ b/test/pugl_test.c
@@ -70,7 +70,7 @@ onDisplay(PuglView* view)
{
PuglTestApp* app = (PuglTestApp*)puglGetHandle(view);
- const double thisTime = puglGetTime(view);
+ const double thisTime = puglGetTime(app->world);
if (app->continuous) {
const double dTime = thisTime - app->lastDrawTime;
app->xAngle = fmodf((float)(app->xAngle + dTime * 100.0f), 360.0f);
@@ -204,10 +204,10 @@ main(int argc, char** argv)
puglShowWindow(view);
- PuglFpsPrinter fpsPrinter = { puglGetTime(view) };
+ PuglFpsPrinter fpsPrinter = { puglGetTime(app.world) };
bool requestedAttention = false;
while (!app.quit) {
- const double thisTime = puglGetTime(view);
+ const double thisTime = puglGetTime(app.world);
if (app.continuous) {
puglPostRedisplay(view);
@@ -223,7 +223,7 @@ main(int argc, char** argv)
}
if (app.continuous) {
- puglPrintFps(view, &fpsPrinter, &app.framesDrawn);
+ puglPrintFps(app.world, &fpsPrinter, &app.framesDrawn);
}
}
diff --git a/test/test_utils.h b/test/test_utils.h
index 9738d96..12dbfaa 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -148,11 +148,11 @@ printEvent(const PuglEvent* event, const char* prefix)
}
static inline void
-puglPrintFps(PuglView* view,
- PuglFpsPrinter* printer,
- unsigned* const framesDrawn)
+puglPrintFps(const PuglWorld* world,
+ PuglFpsPrinter* printer,
+ unsigned* const framesDrawn)
{
- const double thisTime = puglGetTime(view);
+ const double thisTime = puglGetTime(world);
if (thisTime > printer->lastReportTime + 5) {
const double fps = *framesDrawn / (thisTime - printer->lastReportTime);
fprintf(stderr,