From dc17d30d9248938e94d77780c206644ce9bb4e08 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 5 May 2014 13:44:44 +0000 Subject: Fix compilation on old glib. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5396 a436a847-0d15-0410-975c-d299462d15a1 --- src/Canvas.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Canvas.cpp b/src/Canvas.cpp index 4478b59..47b0013 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -788,6 +788,18 @@ apply_force(GanvNode* a, GanvNode* b, const Vector& f) b->impl->force = vec_sub(b->impl->force, f); } +inline uint64_t +get_monotonic_time() +{ +#if GLIB_CHECK_VERSION(2, 28, 0) + return g_get_monotonic_time(); +#else + GTimeVal time; + g_get_current_time(&time); + return time.tv_sec + time.tv_usec; +#endif +} + gboolean GanvCanvasImpl::layout_iteration() { @@ -802,7 +814,7 @@ GanvCanvasImpl::layout_iteration() static uint64_t prev = 0; // Previous iteration time - const uint64_t now = g_get_monotonic_time(); + const uint64_t now = get_monotonic_time(); const double time_to_run = std::min((now - prev) * T_PER_US, 10.0); prev = now; @@ -1614,14 +1626,7 @@ GanvCanvasImpl::on_animate_timeout(gpointer data) { GanvCanvasImpl* impl = (GanvCanvasImpl*)data; -#ifdef g_get_monotonic_time - // Only available in glib 2.28 - const double seconds = g_get_monotonic_time() / 1000000.0; -#else - GTimeVal time; - g_get_current_time(&time); - const double seconds = time.tv_sec + time.tv_usec / (double)G_USEC_PER_SEC; -#endif + const double seconds = get_monotonic_time() / 1000000.0; FOREACH_ITEM(impl->_selected_items, s) { ganv_node_tick(*s, seconds); -- cgit v1.2.1