[retro-gtk/wip/aplazas/microseconds] very dirty fluidity fix test



commit 2464eb11596b62b44ab6c95deb13ab00c6edf048
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Apr 12 16:58:05 2018 +0200

    very dirty fluidity fix test

 retro-gtk/retro-main-loop.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/retro-gtk/retro-main-loop.c b/retro-gtk/retro-main-loop.c
index 409a989..2d021d6 100644
--- a/retro-gtk/retro-main-loop.c
+++ b/retro-gtk/retro-main-loop.c
@@ -179,6 +179,14 @@ retro_main_loop_init (RetroMainLoop *self)
                            0);
 }
 
+static gint64 interval, last;
+
+static guint
+retro_timeout_add (guint64        interval,
+                   GSourceFunc    function,
+                   gpointer       data,
+                   GDestroyNotify notify);
+
 static gboolean
 retro_main_loop_run (RetroMainLoop *self)
 {
@@ -187,9 +195,22 @@ retro_main_loop_run (RetroMainLoop *self)
   if (self->core == NULL || self->loop < 0)
     return FALSE;
 
+  gint64 now = g_get_monotonic_time ();
+  gint64 actual = now - last;
+  gint64 diff = actual - interval;
+  last = now;
+  /* g_message ("expected %ld actual %ld diff %ld", interval, actual, diff); */
+
   retro_core_run (self->core);
 
-  return TRUE;
+  self->loop = retro_timeout_add (interval - diff,
+                                  (GSourceFunc) retro_main_loop_run,
+                                  g_object_ref (self),
+                                  g_object_unref);
+
+  return FALSE;
+
+  /* return TRUE; */
 }
 
 static void
@@ -378,6 +399,7 @@ retro_main_loop_start (RetroMainLoop *self)
 
   // TODO What if fps <= 0?
   fps = retro_core_get_frames_per_second (self->core);
+  interval = (1000000 / (fps * self->speed_rate));
   self->loop = retro_timeout_add ((guint64) (1000000 / (fps * self->speed_rate)),
                                   (GSourceFunc) retro_main_loop_run,
                                   g_object_ref (self),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]