shithub: treason

Download patch

ref: 70fe76be55761fdd7905f1b28613e0395243baa6
parent: 18892475cfa24adbe79de7cea5e7063876e96b9b
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Sep 21 12:03:41 EDT 2020

add optional stupid framedrop via -D cmd line arg

--- a/main.c
+++ b/main.c
@@ -20,6 +20,7 @@
 static char info[256];
 static int showinfo;
 static uvlong delay;
+static int framedrop;
 
 static void
 audioproc(void *x)
@@ -52,6 +53,13 @@
 	uvlong x, end, left;
 	Rectangle r, clip;
 
+	if(lastframe == 0)
+		lastframe = nanosec();
+
+	end = lastframe + f->dt - delay;
+	if(framedrop && delay > 0 && nanosec() >= end+delay)
+		goto drop;
+
 	lockdisplay(display);
 
 	if(curim != nil && (Dx(curim->r) != f->w || Dy(curim->r) != f->h)){
@@ -63,10 +71,6 @@
 		curim = allocimage(display, r, RGB24, 0, DNofill);
 	loadimage(curim, r, f->rgb, f->w*f->h*3);
 
-	if(lastframe == 0)
-		lastframe = nanosec();
-
-	end = lastframe + f->dt - delay;
 	while(1){
 		x = nanosec();
 		if(x >= end)
@@ -95,10 +99,12 @@
 		stringbg(screen, screen->r.min, display->white, ZP, font, info, display->black, ZP);
 	flushimage(display, 1);
 	unlockdisplay(display);
+
+	delay = nanosec() - x;
+drop:
 	if(audiosync != nil)
 		sendp(audiosync, nil);
 
-	delay = nanosec() - x;
 	lastframe += f->dt;
 
 	free(f);
@@ -151,6 +157,9 @@
 			usage();
 		}
 		audio = EARGF(usage());
+		break;
+	case 'D':
+		framedrop++;
 		break;
 	case 'd':
 		debug++;