commit 7ce2996

Devie Lu Linvega  ·  2025-12-14 17:19:38 +0000 UTC
parent d40f67d
Faster drawing
1 files changed,  +15, -9
+15, -9
 1@@ -409,7 +409,7 @@ console_input(int c, unsigned int type)
 2 #define MAR2(x) (x + 0x10)
 3 
 4 typedef struct UxnScreen {
 5-	int width, height, zoom, resized, x1, y1, x2, y2;
 6+	int width, height, zoom, resized, x1, y1, x2, y2, redraw;
 7 	unsigned int palette[16], *pixels;
 8 	Uint8 *bg;
 9 } UxnScreen;
10@@ -472,7 +472,7 @@ screen_palette(void)
11 	}
12 	for(i = 0; i < 16; i++)
13 		uxn_screen.palette[i] = colors[(i >> 2) ? (i >> 2) : (i & 3)];
14-	screen_change(0, 0, uxn_screen.width, uxn_screen.height);
15+	uxn_screen.redraw = 1;
16 }
17 
18 static void
19@@ -487,7 +487,7 @@ screen_apply(int width, int height)
20 	uxn_screen.bg = realloc(uxn_screen.bg, length);
21 	memset(uxn_screen.bg, 0, length);
22 	uxn_screen.width = width, uxn_screen.height = height, uxn_screen.resized = 1;
23-	screen_change(0, 0, width, height);
24+	uxn_screen.redraw = 1;
25 }
26 
27 static void
28@@ -531,7 +531,7 @@ screen_draw_pixel(void)
29 			y1 = 0, y2 = rY;
30 		else
31 			y1 = rY, y2 = uxn_screen.height;
32-		screen_change(x1, y1, x2, y2);
33+		uxn_screen.redraw = 1;
34 		x1 = MAR(x1), y1 = MAR(y1);
35 		hor = MAR(x2) - x1, ver = MAR(y2) - y1;
36 		for(ay = y1 * len, by = ay + ver * len; ay < by; ay += len)
37@@ -547,7 +547,7 @@ screen_draw_pixel(void)
38 			const int src = uxn_screen.bg[ax];
39 			uxn_screen.bg[ax] = above ? (src & 0x3) | color : (src & 0xc) | color;
40 		}
41-		screen_change(rX, rY, rX + 1, rY + 1);
42+		if(!uxn_screen.redraw) screen_change(rX, rY, rX + 1, rY + 1);
43 		if(rMX) rX++;
44 		if(rMY) rY++;
45 	}
46@@ -616,7 +616,7 @@ screen_draw_sprite(void)
47 		y1 = y, y2 = rY;
48 	else
49 		y1 = rY, y2 = y;
50-	screen_change(x1 - 8, y1 - 8, x2 + 8, y2 + 8);
51+	if(!uxn_screen.redraw) screen_change(x1 - 8, y1 - 8, x2 + 8, y2 + 8);
52 	if(rMX) rX += rDX * fx;
53 	if(rMY) rY += rDY * fy;
54 }
55@@ -1160,7 +1160,7 @@ emu_event(void)
56 	XNextEvent(display, &ev);
57 	switch(ev.type) {
58 	case Expose:
59-		screen_change(0, 0, 9000, 9000);
60+		uxn_screen.redraw = 1;
61 		break;
62 	case ClientMessage:
63 		dev[0x0f] = 0x80;
64@@ -1231,7 +1231,13 @@ emu_run(void)
65 				uxn_eval(screen_vector);
66 			if(uxn_screen.resized)
67 				emu_resize(), uxn_screen.resized = 0;
68-			if(uxn_screen.x2 && uxn_screen.y2 && screen_changed())
69+			if(uxn_screen.redraw) {
70+				uxn_screen.x1 = 0;
71+				uxn_screen.y1 = 0;
72+				uxn_screen.x2 = uxn_screen.width;
73+				uxn_screen.y2 = uxn_screen.height;
74+				emu_repaint();
75+			} else if(uxn_screen.x2 && uxn_screen.y2 && screen_changed())
76 				emu_repaint();
77 		}
78 		has_input = fds[2].revents & POLLIN;
79@@ -1255,7 +1261,7 @@ main(int argc, char **argv)
80 {
81 	int i = 1;
82 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
83-		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 18 Oct 2025.\n");
84+		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 14 Dec 2025.\n");
85 	else if(argc == 1)
86 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
87 	else if(!system_boot(argv[i++], argc > 2))