Author: mesyeti <mesyeti@mesyeti.uk>
add BuffAttr and other stuff
source/app.c | 2 ++ source/backend.c | 4 ++++ source/backend.h | 2 ++ source/backends/glLegacy.c | 5 +++++ source/backends/soft.c | 9 +++++++-- source/backends/stub.c | 8 +++++++- source/buffer.c | 37 ++++++++++++++++++++++++++++++------- source/buffer.h | 8 +++++++- source/video.c | 4 ++++ source/video.h | 1 +
diff --git a/source/app.c b/source/app.c index 10882cadef6bfebe8c77d8f33699e36c5b7d7c6a..70b77c69916aeb86d9e11db60bf5fe882c7011b8 100644 --- a/source/app.c +++ b/source/app.c @@ -30,6 +30,8 @@ default: continue; } } + // render + Backend_Render(); oldFrameTime = newFrameTime; } diff --git a/source/backend.c b/source/backend.c index 8032163580e267eb658649cc6ffff739cd683faf..1de9556c194b15ab4194f8493a671ec3c53cfe7b 100644 --- a/source/backend.c +++ b/source/backend.c @@ -34,6 +34,10 @@ void Backend_OnScreenUpdate(void) { backend.onScreenUpdate(); } +void Backend_OnCellChange(int x, int y) { + backend.onCellChange(x, y); +} + void Backend_Render(void) { backend.render(); } diff --git a/source/backend.h b/source/backend.h index 24f308eb6f688dd333512fcf97389b06491373af..cdb23f1a85e28156272be8bc6a92bb95a6bd419b 100644 --- a/source/backend.h +++ b/source/backend.h @@ -27,6 +27,7 @@ void (*freeTexture)(Texture* texture); Vec2 (*getTextureSize)(Texture* texture); void (*onWindowResize)(void); void (*onScreenUpdate)(void); + void (*onCellChange)(int x, int y); void (*render)(void); } Backend; @@ -38,6 +39,7 @@ void Backend_FreeTexture(Texture* texture); Vec2 Backend_GetTextureSize(Texture* texture); void Backend_OnWindowResize(void); void Backend_OnScreenUpdate(void); +void Backend_OnCellChange(int x, int y); void Backend_Render(void); #endif diff --git a/source/backends/glLegacy.c b/source/backends/glLegacy.c index fbe2fa44f816f7d9bf023818d9bd738ae61bc24b..73e2bde90a7ab3da111d899f10b6a30962ec2530 100644 --- a/source/backends/glLegacy.c +++ b/source/backends/glLegacy.c @@ -227,6 +227,10 @@ static void OnScreenUpdate(void) { } +static void OnCellChange(int x, int y) { + +} + static void Render(void) { } @@ -241,6 +245,7 @@ .freeTexture = &FreeTexture, .getTextureSize = &GetTextureSize, .onWindowResize = &OnWindowResize, .onScreenUpdate = &OnScreenUpdate, + .onCellChange = &OnCellChange, .render = &Render }; } diff --git a/source/backends/soft.c b/source/backends/soft.c index d86549c1fbdd90362ceb6b42cd455f76f6f87f22..470294f21cff22ccb5d5b667ae9b7024085af219 100644 --- a/source/backends/soft.c +++ b/source/backends/soft.c @@ -177,6 +177,10 @@ } } } +static void OnCellChange(int x, int y) { + state.changes[(y * screen.buffer.width) + x] = true; +} + static void Render(void) { if (state.redraw) { for (int i = 0; i < state.bufferW * state.bufferH; ++ i) { @@ -199,8 +203,8 @@ int cy = y * ch; BufCell* cell = Buffer_Get(&screen.buffer, x, y); - ColourRGB fg = Screen_GetColour(true, cell->fgMode, cell->fg); - ColourRGB bg = Screen_GetColour(false, cell->bgMode, cell->bg); + ColourRGB fg = Screen_GetColour(true, cell->attr.fgMode, cell->attr.fg); + ColourRGB bg = Screen_GetColour(false, cell->attr.bgMode, cell->attr.bg); FillRect(cx, cy, cw, ch, (Colour) {bg.r, bg.g, bg.b, 255}); @@ -234,6 +238,7 @@ .freeTexture = &FreeTexture, .getTextureSize = &GetTextureSize, .onWindowResize = &OnWindowResize, .onScreenUpdate = &OnScreenUpdate, + .onCellChange = &OnCellChange, .render = &Render }; } diff --git a/source/backends/stub.c b/source/backends/stub.c index c8d879b1779adaf28cd4bcda1032f4f7c126fd54..edad0a2e87c592fdade2d35c224ce2e789f300ad 100644 --- a/source/backends/stub.c +++ b/source/backends/stub.c @@ -3,7 +3,7 @@ #include "stub.h" static void Init(bool beforeWindow) { - + (void) beforeWindow; } static void Free(void) { @@ -37,6 +37,11 @@ static void OnScreenUpdate(void) { } +static void OnCellChange(int x, int y) { + (void) x; + (void) y; +} + static void Render(void) { } @@ -51,6 +56,7 @@ .freeTexture = &FreeTexture, .getTextureSize = &GetTextureSize, .onWindowResize = &OnWindowResize, .onScreenUpdate = &OnScreenUpdate, + .onCellChange = &OnCellChange, .render = &Render }; } diff --git a/source/buffer.c b/source/buffer.c index c6c1619e38bc0833c636f912368ce6735eec1caf..0fad27ebab72086dd675c34a6312e1480d20b2ef 100644 --- a/source/buffer.c +++ b/source/buffer.c @@ -3,11 +3,9 @@ #include "buffer.h" static BufCell FromChar(char ch) { BufCell ret; - ret.ch = ch; - ret.fgMode = BUF_16COL; - ret.bgMode = BUF_16COL; - ret.fg.idx = 0x7; - ret.bg.idx = 0x4; + ret.ch = ch; + ret.attr.fgMode = BUF_DEFAULT; + ret.attr.bgMode = BUF_DEFAULT; return ret; } @@ -19,8 +17,9 @@ for (int i = 0; i < width * height; ++ i) { ret.buf[i] = FromChar(0); } - ret.width = width; - ret.height = height; + ret.width = width; + ret.height = height; + ret.isScreenBuf = false; return ret; } @@ -32,6 +31,30 @@ void Buffer_WriteChar(Buffer* buf, UChar ch, int x, int y) { if ((x < 0) || (y < 0) || (x >= buf->width) || (y >= buf->height)) return; buf->buf[(y * buf->width) + x] = FromChar(ch); +} + +bool Buffer_CellEq(BufCell a, BufCell b) { + if (a.ch != b.ch) return false; + if (a.attr.fgMode != b.attr.fgMode) return false; + if (a.attr.bgMode != b.attr.bgMode) return false; + + switch (a.attr.fgMode) { + case BUF_DEFAULT: break; + case BUF_16COL: + case BUF_256COL: if (a.attr.fg.idx != b.attr.fg.idx) return false; break; + case BUF_TC: if (Video_RGBEq(a.attr.fg.rgb, b.attr.fg.rgb)) return false; break; + default: assert(0); + } + + switch (a.attr.bgMode) { + case BUF_DEFAULT: break; + case BUF_16COL: + case BUF_256COL: if (a.attr.fg.idx != b.attr.fg.idx) return false; break; + case BUF_TC: if (Video_RGBEq(a.attr.fg.rgb, b.attr.fg.rgb)) return false; break; + default: assert(0); + } + + return true; } BufCell* Buffer_Get(Buffer* buf, int x, int y) { diff --git a/source/buffer.h b/source/buffer.h index 7ae1a1806cc0970c593c5c536a19d8d3b07a29c4..5f0c1adce15c9d2d328d14b431fa89975cc7ae0d 100644 --- a/source/buffer.h +++ b/source/buffer.h @@ -18,22 +18,28 @@ ColourRGB rgb; } BufCol; typedef struct { - UChar ch; uint8_t fgMode; uint8_t bgMode; BufCol fg; BufCol bg; +} BufAttr; + +typedef struct { + UChar ch; + BufAttr attr; } BufCell; typedef struct { BufCell* buf; int width; int height; + bool isScreenBuf; } Buffer; Buffer Buffer_New(int width, int height); void Buffer_Free(Buffer* buf); void Buffer_WriteChar(Buffer* buf, UChar ch, int x, int y); +bool Buffer_CellEq(BufCell a, BufCell b); BufCell* Buffer_Get(Buffer* buf, int x, int y); void Buffer_Blit(Buffer* dest, Buffer* src, int x, int y, Rect clip); diff --git a/source/video.c b/source/video.c index 3cbedc59d5b8d96eebd328df1f4134971909b6a8..00703f0110d0014c6cb5d4b5502af51c809987f8 100644 --- a/source/video.c +++ b/source/video.c @@ -58,3 +58,7 @@ (uint8_t) (b * 255.0), colour.a }; } + +bool Video_RGBEq(ColourRGB a, ColourRGB b) { + return (a.r == b.r) && (a.g == b.g) && (a.b == b.b); +} diff --git a/source/video.h b/source/video.h index fee3c452964828ed8e559c0fe33093fd1b84b478..5138125ad96d0ac2266e18cadd4ca8379bfd2f62 100644 --- a/source/video.h +++ b/source/video.h @@ -25,5 +25,6 @@ void Video_Init(const char* windowName); void Video_Free(void); Colour Video_MultiplyColour(Colour colour, float by); +bool Video_RGBEq(ColourRGB a, ColourRGB b); #endif