diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-06-24 17:23:29 +0200 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-06-24 17:23:29 +0200 |
commit | f7b1199a46f4034a49b624afa0d0b74535fa9623 (patch) | |
tree | 17838bc3965fe48e8e6481cae2ce194cf3f37fc7 /src/client.c | |
parent | 4579a7f94e3ac323a0b69d05fdb3eea9b7e6b999 (diff) |
clean up color dirty-tracking
Signed-off-by: Lizzy Fleckenstein <lizzy@vlhl.dev>
Diffstat (limited to 'src/client.c')
-rw-r--r-- | src/client.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/client.c b/src/client.c index 593e9ac..78511c6 100644 --- a/src/client.c +++ b/src/client.c @@ -49,13 +49,19 @@ void gfx_clear_effects(client *c) fprintf(c->termbuf, "\e[0m"); } -void gfx_set_color(client *c, color col, bool bg, bool *has_old, color *old) +typedef struct { + bool bg; + bool has_old; + color old; +} color_layer; + +void gfx_set_color(client *c, color_layer *l, color col) { - if (*has_old && old->r == col.r && old->g == col.g && old->b == col.b) + if (l->has_old && l->old.r == col.r && l->old.g == col.g && l->old.b == col.b) return; - fprintf(c->termbuf, "\e[%u;2;%u;%u;%um", bg ? 48 : 38, col.r, col.g, col.b); - *has_old = true; - *old = col; + fprintf(c->termbuf, "\e[%u;2;%u;%u;%um", l->bg ? 48 : 38, col.r, col.g, col.b); + l->has_old = true; + l->old = col; } void gfx_clear(client *c) @@ -148,10 +154,9 @@ void gfx_render(client *c, uint64_t dtime) for (size_t i = 0; i < c->players.len; i++) fprintf(c->termbuf, "%.*s\n", PSTR(c->players.data[i].name)); - bool has_bg = false; - bool has_fg = false; - color bg; - color fg; + color_layer fg = {0}; + color_layer bg = {0}; + bg.bg = true; for (size_t y = 0; y < c->map.bounds.size.y; y++) { for (size_t x = 0; x < c->map.bounds.size.y; x++) { @@ -159,19 +164,19 @@ void gfx_render(client *c, uint64_t dtime) vec2 pos = vec2_add(c->map.bounds.pos, CVEC2(off)); node_display dis = gfx_render_node(c, pos, chunk_index(c->map, off)); - gfx_set_color(c, dis.bg, true, &has_bg, &bg); + gfx_set_color(c, &bg, dis.bg); if (vec2_eq(pos, c->player_pos)) { fprintf(c->termbuf, "🙂"); } else if (dis.texture) { - gfx_set_color(c, dis.fg, false, &has_fg, &fg); + gfx_set_color(c, &fg, dis.fg); fprintf(c->termbuf, "%s", dis.texture); } else { fprintf(c->termbuf, " "); } } gfx_clear_effects(c); - has_bg = false; - has_fg = false; + bg.has_old = false; + fg.has_old = false; fprintf(c->termbuf, "\n"); } fflush(c->termbuf); |