Skip to content

Commit 234969d

Browse files
committed
🐛 allow cell fill for different initialization types
This forces a render of all cells on the very first frame, which is perfectly acceptable.
1 parent 37594f1 commit 234969d

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/cell.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
#include "cell.h"
44

5-
void cells_clear(Cell *buf, int w, int h) {
5+
void cells_fill(Cell *buf, int w, int h, uint32_t ch, uint32_t fg,
6+
uint32_t bg) {
67
for (int i = 0; i < w * h; i++) {
7-
buf[i].ch = ' ';
8-
buf[i].fg = ATTR_DEFAULT;
9-
buf[i].bg = ATTR_DEFAULT;
8+
buf[i].ch = ch;
9+
buf[i].fg = fg;
10+
buf[i].bg = bg;
1011
}
1112
}
1213

src/cell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef struct {
2424
#define ATTR_MASK 0xFF000000
2525
#define COLOR_MASK 0x00FFFFFF
2626

27-
void cells_clear(Cell *buf, int w, int h);
27+
void cells_fill(Cell *buf, int w, int h, uint32_t ch, uint32_t fg, uint32_t bg);
2828
int cell_cmp(Cell *a, Cell *b);
2929

3030
#endif

src/clayterm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,11 @@ struct Clayterm *init(void *mem, int w, int h, int row) {
416416
.lasty = -1,
417417
};
418418

419-
cells_clear(ct->front, w, h);
420-
cells_clear(ct->back, w, h);
419+
// initialize back buffer with spaces and default fg/bg
420+
cells_fill(ct->back, w, h, ' ', ATTR_DEFAULT, ATTR_DEFAULT);
421+
422+
// initialize front buffer with zeros. Every cell will be
423+
cells_fill(ct->front, w, h, 0, 0, 0);
421424
return ct;
422425
}
423426

@@ -551,7 +554,7 @@ void reduce(struct Clayterm *ct, uint32_t *buf, int len, int mode) {
551554
ct->lastfg = ct->lastbg = 0xffffffff;
552555
ct->lastx = ct->lasty = -1;
553556

554-
cells_clear(ct->back, ct->w, ct->h);
557+
cells_fill(ct->back, ct->w, ct->h, ' ', ATTR_DEFAULT, ATTR_DEFAULT);
555558

556559
/* walk Clay render commands into back buffer */
557560
for (int32_t j = 0; j < cmds.length; j++) {

0 commit comments

Comments
 (0)