commit 1742132

Devine Lu Linvega  ·  2025-12-30 21:35:16 +0000 UTC
parent d83c55a
Unrolled sprite loops
1 files changed,  +26, -13
+26, -13
 1@@ -570,6 +570,15 @@ screen_draw_pixel(void)
 2 	}
 3 }
 4 
 5+/* clang-format off */
 6+
 7+#define o1BPP(n) { const int qx = qfx - n * fx; dst[n] = (dst[n] & layer_mask) | table[(ch1 >> qx) & 1]; }
 8+#define a1BPP(n) { const int qx = qfx - n * fx; const int color = (ch1 >> qx) & 1; if(color) dst[n] = (dst[n] & layer_mask) | table[color]; }
 9+#define o2BPP(n) { const int qx = qfx - n * fx; dst[n] = (dst[n] & layer_mask) | table[((ch1 >> qx) & 1) | ((ch2 >> qx) & 2)]; }
10+#define a2BPP(n) { const int qx = qfx - n * fx; const int color = ((ch1 >> qx) & 1) | ((ch2 >> qx) & 2); if(color) dst[n] = (dst[n] & layer_mask) | table[color]; }
11+
12+/* clang-format on */
13+
14 static void
15 screen_draw_sprite(void)
16 {
17@@ -580,7 +589,7 @@ screen_draw_sprite(void)
18 	const int fx = ctrl & 0x10 ? -1 : 1, fy = ctrl & 0x20 ? -1 : 1;
19 	const int qfx = fx > 0 ? 7 : 0, qfy = fy < 0 ? 7 : 0;
20 	const int dxy = fy * rDX, dyx = fx * rDY;
21-	int i, x1, x2, y1, y2, ax, ay, bx, by, qx, qy, x = rX, y = rY, layer_mask;
22+	int i, x1, x2, y1, y2, ay, by, qy, x = rX, y = rY, layer_mask;
23 	if(ctrl & 0x40)
24 		layer_mask = 0x3, table = blending[blend][1];
25 	else
26@@ -594,12 +603,14 @@ screen_draw_sprite(void)
27 				const Uint16 xmar = x + 8, ymar = y + 8;
28 				for(ay = ymar * screen_wmar2, by = ymar2 * screen_wmar2, qy = qfy; ay < by; ay += screen_wmar2, qy += fy) {
29 					const int ch1 = sprite[qy], ch2 = sprite[qy + 8] << 1;
30-					Uint8 *dst = screen_layers + (xmar + ay);
31-					Uint8 *end = screen_layers + (xmar2 + ay);
32-					for(qx = qfx; dst < end; qx -= fx, dst++) {
33-						const int color = ((ch1 >> qx) & 1) | ((ch2 >> qx) & 2);
34-						if(opaque || color)
35-							*dst = (*dst & layer_mask) | table[color];
36+					Uint8 *dst = &screen_layers[xmar + ay];
37+					Uint8 *end = &screen_layers[xmar2 + ay];
38+					if(end == dst + 8) {
39+						if(opaque) {
40+							o2BPP(0) o2BPP(1) o2BPP(2) o2BPP(3) o2BPP(4) o2BPP(5) o2BPP(6) o2BPP(7)
41+						} else {
42+							a2BPP(0) a2BPP(1) a2BPP(2) a2BPP(3) a2BPP(4) a2BPP(5) a2BPP(6) a2BPP(7)
43+						}
44 					}
45 				}
46 			}
47@@ -613,12 +624,14 @@ screen_draw_sprite(void)
48 				const Uint16 xmar = x + 8, ymar = y + 8;
49 				for(ay = ymar * screen_wmar2, by = ymar2 * screen_wmar2, qy = qfy; ay < by; ay += screen_wmar2, qy += fy) {
50 					const int ch1 = sprite[qy];
51-					Uint8 *dst = screen_layers + (xmar + ay);
52-					Uint8 *end = screen_layers + (xmar2 + ay);
53-					for(qx = qfx; dst < end; qx -= fx, dst++) {
54-						const int color = (ch1 >> qx) & 1;
55-						if(opaque || color)
56-							*dst = (*dst & layer_mask) | table[color];
57+					Uint8 *dst = &screen_layers[xmar + ay];
58+					Uint8 *end = &screen_layers[xmar2 + ay];
59+					if(end == dst + 8) {
60+						if(opaque) {
61+							o1BPP(0) o1BPP(1) o1BPP(2) o1BPP(3) o1BPP(4) o1BPP(5) o1BPP(6) o1BPP(7)
62+						} else {
63+							a1BPP(0) a1BPP(1) a1BPP(2) a1BPP(3) a1BPP(4) a1BPP(5) a1BPP(6) a1BPP(7)
64+						}
65 					}
66 				}
67 			}