diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-02-17 09:26:13 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-02-17 09:26:13 +0100 |
commit | 9ccdf5bc8973e1936ff6255f8f02af304aff9084 (patch) | |
tree | bbff5158e9bdc92ee8382a8bd6502cc7e5c346d8 | |
parent | daf44bcdc706dd84bf291b207a8f720bc2b26159 (diff) |
Make drawing more efficient
-rw-r--r-- | src/ahoy/gui.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ahoy/gui.c b/src/ahoy/gui.c index 918ddbc..1201700 100644 --- a/src/ahoy/gui.c +++ b/src/ahoy/gui.c @@ -1,4 +1,5 @@ #include <err.h> +#include <stdbit.h> #include <stddef.h> #include <stdint.h> #include <stdlib.h> @@ -87,15 +88,14 @@ windrw(void) SDL_SetRenderDrawColor(rndr, 0, 0, 0, UINT8_MAX); SDL_RenderClear(rndr); + SDL_SetRenderDrawColor(rndr, 0, UINT8_MAX, 0, UINT8_MAX); for (size_t i = 0; i < lengthof(c8.screen); i++) { - for (size_t j = 64; j-- > 0;) { - bool set = (UINT64_C(1) << j) & c8.screen[i]; + uint64_t row = c8.screen[i]; + while (row) { + int j = stdc_first_trailing_one(row) - 1; r.x = cols[j] * qw.quot + qw.rem / 2; r.y = i * qh.quot + qh.rem / 2; - if (set) - SDL_SetRenderDrawColor(rndr, 0, UINT8_MAX, 0, UINT8_MAX); - else - SDL_SetRenderDrawColor(rndr, 0, 0, 0, UINT8_MAX); + row ^= 1ULL << j; SDL_RenderFillRect(rndr, &r); } } |