shithub: cstory

Download patch

ref: b2eae2b262371db954fcc1e6d77486a94021b324
parent: 72ca3bb20732e83543cad5b944cea02958796200
author: Jacob Moody <moody@posixcafe.org>
date: Thu Dec 21 13:12:26 EST 2023

redo how we maintain frame limit

this greatly reduces our time spent in npe_nanosec

--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -64,19 +64,20 @@
 	// TODO - Not the original variable names
 	static unsigned long timePrev;
 	static unsigned long timeNow;
+	long x;
 
-	while (TRUE)
-	{
-		if (!SystemTask())
-			return FALSE;
+	if (!SystemTask())
+		return FALSE;
 
-		// Framerate limiter
-		timeNow = Backend_GetTicks();
+	// Framerate limiter
+	timeNow = Backend_GetTicks();
 
-		if (timeNow >= timePrev + 20)
-			break;
+	x = timeNow - (long)(timePrev + 20);
 
-		Backend_Delay(1);
+	// Running fast
+	if (x < 0){
+		x *= -1;
+		Backend_Delay(x);
 	}
 
 	if (timeNow >= timePrev + 100)