mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-27 16:23:02 +00:00
ppu: keep track of modified rows and only redraw those in drawppu
This commit is contained in:
parent
b25e3e599d
commit
3c64c8c1a4
3 changed files with 25 additions and 12 deletions
|
@ -41,13 +41,11 @@ readpixel(Uint8 *sprite, Uint8 h, Uint8 v)
|
||||||
void
|
void
|
||||||
clear(Ppu *p)
|
clear(Ppu *p)
|
||||||
{
|
{
|
||||||
int i, sz = p->height * p->width, rows = sz / 4;
|
int sz = p->height * p->width, rows = sz / 4;
|
||||||
for(i = 0; i < sz; ++i)
|
memset(p->output, p->colors[0], sz);
|
||||||
p->output[i] = p->colors[0];
|
memset(p->fg, 0, rows);
|
||||||
for(i = 0; i < rows; i++) {
|
memset(p->bg, 0, rows);
|
||||||
p->fg[i] = 0;
|
memset(p->up, 0xff, p->ver);
|
||||||
p->bg[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -66,9 +64,12 @@ putcolors(Ppu *p, Uint8 *addr)
|
||||||
void
|
void
|
||||||
putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
|
putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
|
||||||
{
|
{
|
||||||
Uint16 row = (y % 8) + ((x / 8 + y / 8 * p->hor) * 16), col = 7 - (x % 8);
|
if(x >= p->hor * 8 || y >= p->ver * 8)
|
||||||
if(x >= p->hor * 8 || y >= p->ver * 8 || row > (p->hor * p->ver * 16) - 8)
|
|
||||||
return;
|
return;
|
||||||
|
int row = (y % 8) + ((x / 8 + y / 8 * p->hor) * 16);
|
||||||
|
if(row > (p->hor * p->ver * 16) - 8)
|
||||||
|
return;
|
||||||
|
int col = 7 - (x % 8);
|
||||||
if(color == 0 || color == 2)
|
if(color == 0 || color == 2)
|
||||||
layer[row] &= ~(1UL << col);
|
layer[row] &= ~(1UL << col);
|
||||||
else
|
else
|
||||||
|
@ -77,6 +78,8 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
|
||||||
layer[row + 8] &= ~(1UL << col);
|
layer[row + 8] &= ~(1UL << col);
|
||||||
else
|
else
|
||||||
layer[row + 8] |= 1UL << col;
|
layer[row + 8] |= 1UL << col;
|
||||||
|
|
||||||
|
p->up[y / 8] |= 1<<(y % 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -143,18 +146,25 @@ void
|
||||||
drawppu(Ppu *p)
|
drawppu(Ppu *p)
|
||||||
{
|
{
|
||||||
Uint16 x, y;
|
Uint16 x, y;
|
||||||
for(y = 0; y < p->ver; ++y)
|
for(y = 0; y < p->ver; ++y) {
|
||||||
|
if(p->up[y] == 0)
|
||||||
|
continue;
|
||||||
for(x = 0; x < p->hor; ++x) {
|
for(x = 0; x < p->hor; ++x) {
|
||||||
Uint8 v, h;
|
Uint8 v, h;
|
||||||
Uint16 key = (y * p->hor + x) * 16;
|
Uint16 key = (y * p->hor + x) * 16;
|
||||||
for(v = 0; v < 8; v++)
|
for(v = 0; v < 8; v++) {
|
||||||
|
if((p->up[y] & (1<<v)) == 0)
|
||||||
|
continue;
|
||||||
for(h = 0; h < 8; h++) {
|
for(h = 0; h < 8; h++) {
|
||||||
Uint8 color = readpixel(&p->fg[key], h, v);
|
Uint8 color = readpixel(&p->fg[key], h, v);
|
||||||
if(color == 0)
|
if(color == 0)
|
||||||
color = readpixel(&p->bg[key], h, v);
|
color = readpixel(&p->bg[key], h, v);
|
||||||
drawpixel(p, x * 8 + p->pad + 7 - h, y * 8 + p->pad + v, color);
|
drawpixel(p, x * 8 + p->pad + 7 - h, y * 8 + p->pad + v, color);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
p->up[y] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -171,6 +181,8 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad)
|
||||||
return 0;
|
return 0;
|
||||||
if(!(p->fg = malloc(p->width * p->height * sizeof(Uint8) / 4)))
|
if(!(p->fg = malloc(p->width * p->height * sizeof(Uint8) / 4)))
|
||||||
return 0;
|
return 0;
|
||||||
|
if(!(p->up = malloc(p->ver)))
|
||||||
|
return 0;
|
||||||
clear(p);
|
clear(p);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ typedef unsigned short Uint16;
|
||||||
typedef unsigned int Uint32;
|
typedef unsigned int Uint32;
|
||||||
|
|
||||||
typedef struct Ppu {
|
typedef struct Ppu {
|
||||||
Uint8 *bg, *fg;
|
Uint8 *bg, *fg, *up;
|
||||||
Uint16 hor, ver, pad, width, height;
|
Uint16 hor, ver, pad, width, height;
|
||||||
Uint32 *output, colors[4];
|
Uint32 *output, colors[4];
|
||||||
} Ppu;
|
} Ppu;
|
||||||
|
|
|
@ -86,6 +86,7 @@ quit(void)
|
||||||
free(ppu.output);
|
free(ppu.output);
|
||||||
free(ppu.fg);
|
free(ppu.fg);
|
||||||
free(ppu.bg);
|
free(ppu.bg);
|
||||||
|
free(ppu.up);
|
||||||
SDL_UnlockAudioDevice(audio_id);
|
SDL_UnlockAudioDevice(audio_id);
|
||||||
SDL_DestroyTexture(gTexture);
|
SDL_DestroyTexture(gTexture);
|
||||||
gTexture = NULL;
|
gTexture = NULL;
|
||||||
|
|
Loading…
Reference in a new issue