commit 72a6b8a
Devine Lu Linvega
·
2025-01-24 17:18:01 +0000 UTC
parent 52abd5a
(screen.c) Precalculate palette on change
2 files changed,
+7,
-8
+6,
-7
1@@ -50,15 +50,17 @@ screen_change(int x1, int y1, int x2, int y2)
2 void
3 screen_palette(void)
4 {
5- int i, shift;
6+ int i, shift, colors[4];
7 for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) {
8 Uint8
9 r = (uxn.dev[0x8 + i / 2] >> shift) & 0xf,
10 g = (uxn.dev[0xa + i / 2] >> shift) & 0xf,
11 b = (uxn.dev[0xc + i / 2] >> shift) & 0xf;
12- uxn_screen.palette[i] = 0x0f000000 | r << 16 | g << 8 | b;
13- uxn_screen.palette[i] |= uxn_screen.palette[i] << 4;
14+ colors[i] = 0x0f000000 | r << 16 | g << 8 | b;
15+ colors[i] |= colors[i] << 4;
16 }
17+ for(i = 0; i < 16; i++)
18+ uxn_screen.palette[i] = colors[(i >> 2) ? (i >> 2) : (i & 3)];
19 screen_change(0, 0, uxn_screen.width, uxn_screen.height);
20 }
21
22@@ -92,13 +94,10 @@ void
23 screen_redraw(void)
24 {
25 int i, x, y, k, l;
26- Uint32 palette[16];
27- for(i = 0; i < 16; i++)
28- palette[i] = uxn_screen.palette[(i >> 2) ? (i >> 2) : (i & 3)];
29 for(y = uxn_screen.y1; y < uxn_screen.y2; y++) {
30 int ys = y * uxn_screen.scale;
31 for(x = uxn_screen.x1, i = MAR(x) + MAR(y) * MAR2(uxn_screen.width); x < uxn_screen.x2; x++, i++) {
32- int c = palette[uxn_screen.fg[i] << 2 | uxn_screen.bg[i]];
33+ int c = uxn_screen.palette[uxn_screen.fg[i] << 2 | uxn_screen.bg[i]];
34 for(k = 0; k < uxn_screen.scale; k++) {
35 int oo = ((ys + k) * uxn_screen.width + x) * uxn_screen.scale;
36 for(l = 0; l < uxn_screen.scale; l++)
+1,
-1
1@@ -11,7 +11,7 @@ WITH REGARD TO THIS SOFTWARE.
2
3 typedef struct UxnScreen {
4 int width, height, vector, x1, y1, x2, y2, scale;
5- Uint32 palette[4], *pixels;
6+ Uint32 palette[16], *pixels;
7 Uint8 *fg, *bg;
8 } UxnScreen;
9