(screen) Only repaint changed pixels
This commit is contained in:
parent
a740105b76
commit
8f98281d89
|
@ -24,6 +24,15 @@ static Uint8 blending[4][16] = {
|
|||
{1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1},
|
||||
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
|
||||
|
||||
static void
|
||||
screen_change(UxnScreen *s, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2)
|
||||
{
|
||||
if(x1 < s->x1) s->x1 = x1;
|
||||
if(y1 < s->y1) s->y1 = y1;
|
||||
if(x2 > s->x2) s->x2 = x2;
|
||||
if(y2 > s->y2) s->y2 = y2;
|
||||
}
|
||||
|
||||
static void
|
||||
screen_fill(UxnScreen *s, Uint8 *pixels, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color)
|
||||
{
|
||||
|
@ -63,7 +72,7 @@ screen_palette(UxnScreen *p, Uint8 *addr)
|
|||
p->palette[i] = 0x0f000000 | r << 16 | g << 8 | b;
|
||||
p->palette[i] |= p->palette[i] << 4;
|
||||
}
|
||||
p->fg.changed = p->bg.changed = 1;
|
||||
screen_change(&uxn_screen, 0, 0, p->width, p->height);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -90,13 +99,19 @@ screen_resize(UxnScreen *p, Uint16 width, Uint16 height)
|
|||
void
|
||||
screen_redraw(UxnScreen *p)
|
||||
{
|
||||
Uint32 i, size = p->width * p->height, palette[16], *pixels = p->pixels;
|
||||
Uint32 i, x, y, w = p->width, palette[16], *pixels = p->pixels;
|
||||
Uint8 *fg = p->fg.pixels, *bg = p->bg.pixels;
|
||||
int x1 = p->x1, y1 = p->y1;
|
||||
int x2 = p->x2 > p->width ? p->width : p->x2, y2 = p->y2 > p->height ? p->height : p->y2;
|
||||
for(i = 0; i < 16; i++)
|
||||
palette[i] = p->palette[(i >> 2) ? (i >> 2) : (i & 3)];
|
||||
for(i = 0; i < size; i++)
|
||||
pixels[i] = palette[fg[i] << 2 | bg[i]];
|
||||
p->fg.changed = p->bg.changed = 0;
|
||||
for(y = y1; y < y2; y++)
|
||||
for(x = x1; x < x2; x++) {
|
||||
i = x + y * w;
|
||||
pixels[i] = palette[fg[i] << 2 | bg[i]];
|
||||
}
|
||||
p->x1 = p->y1 = 0xffff;
|
||||
p->x2 = p->y2 = 0;
|
||||
}
|
||||
|
||||
Uint8
|
||||
|
@ -134,7 +149,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
|||
if(ctrl & 0x10) x2 = x, x = 0;
|
||||
if(ctrl & 0x20) y2 = y, y = 0;
|
||||
screen_fill(&uxn_screen, layer->pixels, x, y, x2, y2, color);
|
||||
layer->changed = 1;
|
||||
screen_change(&uxn_screen, x, y, x2, y2);
|
||||
}
|
||||
/* pixel mode */
|
||||
else {
|
||||
|
@ -142,7 +157,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
|||
Uint16 height = uxn_screen.height;
|
||||
if(x < width && y < height)
|
||||
layer->pixels[x + y * width] = color;
|
||||
layer->changed = 1;
|
||||
screen_change(&uxn_screen, x, y, x + 1, y + 1);
|
||||
if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */
|
||||
if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */
|
||||
}
|
||||
|
@ -164,7 +179,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
|||
screen_blit(&uxn_screen, layer->pixels, x + dy * i, y + dx * i, ram, addr, ctrl & 0xf, ctrl & 0x10, ctrl & 0x20, twobpp);
|
||||
addr += (move & 0x04) << (1 + twobpp);
|
||||
}
|
||||
layer->changed = 1;
|
||||
screen_change(&uxn_screen, x, y, x + dy * length + 8, y + dx * length + 8);
|
||||
if(move & 0x1) POKE2(d + 0x8, x + dx); /* auto x+8 */
|
||||
if(move & 0x2) POKE2(d + 0xa, y + dy); /* auto y+8 */
|
||||
if(move & 0x4) POKE2(d + 0xc, addr); /* auto addr+length */
|
||||
|
|
|
@ -11,12 +11,12 @@ WITH REGARD TO THIS SOFTWARE.
|
|||
*/
|
||||
|
||||
typedef struct Layer {
|
||||
Uint8 *pixels, changed;
|
||||
Uint8 *pixels;
|
||||
} Layer;
|
||||
|
||||
typedef struct UxnScreen {
|
||||
Uint32 palette[4], *pixels;
|
||||
Uint16 width, height;
|
||||
Uint16 width, height, x1, y1, x2, y2;
|
||||
Layer fg, bg;
|
||||
} UxnScreen;
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
|
|||
system_cmd(u->ram, PEEK2(d + 2));
|
||||
break;
|
||||
case 0x5:
|
||||
if(PEEK2(d + 4)){
|
||||
if(PEEK2(d + 4)) {
|
||||
Uxn friend;
|
||||
uxn_boot(&friend, u->ram);
|
||||
uxn_eval(&friend, PEEK2(d + 4));
|
||||
|
|
|
@ -262,7 +262,7 @@ start(Uxn *u, char *rom, int queue)
|
|||
static void
|
||||
set_zoom(Uint8 z)
|
||||
{
|
||||
if (z >= 1) {
|
||||
if(z >= 1) {
|
||||
zoom = z;
|
||||
set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom);
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ run(Uxn *u)
|
|||
return 0;
|
||||
screen_vector = PEEK2(&u->dev[0x20]);
|
||||
uxn_eval(u, screen_vector);
|
||||
if(uxn_screen.fg.changed || uxn_screen.bg.changed)
|
||||
if(uxn_screen.x2)
|
||||
redraw();
|
||||
now = SDL_GetPerformanceCounter();
|
||||
if(screen_vector) {
|
||||
|
|
Loading…
Reference in New Issue