src/context.c

changeset 165
590a9e822b6b
parent 154
4dff9cc488fe
--- a/src/context.c	Mon Jun 23 20:38:21 2025 +0200
+++ b/src/context.c	Mon Jun 23 21:07:31 2025 +0200
@@ -198,12 +198,22 @@
     }
 
     // compute frame time
+    // TODO: think about whether frame rate is actually a per-window thing
+    //       the answer is hopefully NO, because that would mean behaviors are also a per-window thing
     uint64_t frame_nanos, ns;
     do {
         ns = asc_nanos();
         frame_nanos = ns - asc_context.total_nanos;
     } while (frame_nanos == 0);
     asc_context.frame_nanos = frame_nanos;
+    unsigned long long fps_1k = asc_seconds(1000) / frame_nanos;
+    asc_context.frame_rate = (float)fps_1k / 1000.f;
+    if (asc_context.frame_rate < 5) {
+        // effectively stop the world when the frame rate drops too low
+        asc_context.frame_factor = 0;
+    } else {
+        asc_context.frame_factor = 1.f / asc_context.frame_rate;
+    }
     asc_context.total_nanos = ns;
 
     // sync the windows

mercurial