diff options
Diffstat (limited to 'src/px.c')
-rw-r--r-- | src/px.c | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -4,6 +4,7 @@ #include <assert.h> PxCol pxbuf[PX_WIDTH * PX_HEIGHT] = {0}; +unsigned int pxzbuf[PX_WIDTH * PX_HEIGHT] = {0}; PxPal pxpal[256] = { /* PICO-8 palette */ {0x00, 0x00, 0x00, false, 0, 0}, @@ -30,6 +31,7 @@ static struct { int h; } pxclip = {0, 0, PX_WIDTH, PX_HEIGHT}; static SDL_Texture *pxtexture = NULL; +static unsigned int pxz = 0; int pxInit(void) @@ -79,14 +81,18 @@ pxFlip(void) SDL_UnlockTexture(pxtexture); SDL_RenderCopy(___tzr_renderer, pxtexture, NULL, NULL); + + return 0; } void pxCls(PxCol c) { - for (int y = 0; y < PX_HEIGHT; y++) - for (int x = 0; x < PX_WIDTH; x++) - pxPset(x, y, c); + for (int y = pxclip.y; y < pxclip.y + pxclip.h; y++) + for (int x = pxclip.x; x < pxclip.x + pxclip.w; x++) { + pxbuf[x + y * PX_WIDTH] = c; + pxzbuf[x + y * PX_WIDTH] = 0; + } } void @@ -105,14 +111,24 @@ pxClipReset(void) } void +pxZ(unsigned int z) +{ + pxz = z; +} + +void pxPset(int x, int y, PxCol c) { if (x < pxclip.x || x >= pxclip.x + pxclip.w || y < pxclip.y || y >= pxclip.y + pxclip.h) return; - if (pxpal[c].pal) - c = pxpal[c].pal - 1; - pxbuf[x + y * PX_WIDTH] = c; + + /* z sorting */ + if (pxz < pxzbuf[x + y * PX_WIDTH]) + return; + pxzbuf[x + y * PX_WIDTH] = pxz; + + pxbuf[x + y * PX_WIDTH] = pxpal[c].pal ? pxpal[c].pal : c; } uint8_t |