diff options
author | kdx <kikoodx@paranoici.org> | 2023-05-05 19:50:40 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-05-05 19:50:40 +0200 |
commit | e4f1c916a1389485b6f94013fea83f001bdcca71 (patch) | |
tree | 4360b5640a82981b1a407b014121d019a78d22d8 | |
parent | 49039e7cfe9ee1db083ce802460eaa3d791f2cec (diff) | |
download | study-sttky-e4f1c916a1389485b6f94013fea83f001bdcca71.tar.gz |
update px
-rw-r--r-- | src/px.c | 34 | ||||
-rw-r--r-- | src/px.h | 5 |
2 files changed, 28 insertions, 11 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) @@ -57,7 +59,6 @@ pxDeinit(void) int pxFlip(void) { - extern int flip_offset_x; extern int flip_offset_y; uint8_t *pixels = NULL; @@ -68,11 +69,11 @@ pxFlip(void) } for (int y = 0; y < PX_HEIGHT; y++) { - const int iy = (y + flip_offset_y) % PX_HEIGHT; + const int iy = (y + flip_offset_y % PX_HEIGHT + PX_HEIGHT) + % PX_HEIGHT; for (int x = 0; x < PX_WIDTH; x++) { - const int ax = (x + flip_offset_x) % PX_WIDTH; const int ix = x << 2; - PxCol col = pxbuf[ax + iy * PX_WIDTH]; + PxCol col = pxbuf[x + iy * PX_WIDTH]; if (pxpal[col].spal) col = pxpal[col].spal - 1; pixels[ix + y * pitch + 0] = pxpal[col].b; @@ -84,15 +85,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 @@ -111,14 +115,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 @@ -64,7 +64,7 @@ void pxDeinit(void); int pxFlip(void); /*** DRAW ***/ -/* Fill the clipping region with color 'c'. */ +/* Fill and reset Z on the clipping region with color 'c'. */ void pxCls(PxCol c); /* Set the clipping region. */ @@ -73,6 +73,9 @@ void pxClip(int x, int y, int w, int h); /* Reset the clipping region. */ void pxClipReset(void); +/* Set Z layer. */ +void pxZ(unsigned int z); + /* Put a pixel. */ void pxPset(int x, int y, PxCol c); |