diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-20 03:02:17 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-20 03:02:17 -0700 |
commit | 48814611e9b638c4b2475fec129d83dcf92a889b (patch) | |
tree | 9be976dd1e1b6fb4b43a7764aeb7797a1b13faf0 /web/web_scoreboard.c | |
parent | ea0bafa754757ddb9ca06ae1cd3c40bc4649b83a (diff) | |
download | dartboat-48814611e9b638c4b2475fec129d83dcf92a889b.tar.gz dartboat-48814611e9b638c4b2475fec129d83dcf92a889b.tar.xz |
web: dynamically allocate player bufs
Diffstat (limited to 'web/web_scoreboard.c')
-rw-r--r-- | web/web_scoreboard.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 57090fb..7dc4b8e 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -15,16 +15,16 @@ static struct { bufstr name, rem, sugg, avg; -} bufs[4]; +} *bufs; #define NUM_SLOTS 2 static int slots[NUM_SLOTS]; -static int active_pn = -1; +static int active_pn; static void flush_slot(int slot) { int pn = slots[slot - 1]; - if (pn == -1) return; + if (!pn) return; // FIXME: should be combined with flushing player info char sel[32]; @@ -46,7 +46,7 @@ static int player_slot(int pn) return i + 1; } - return -1; + return 0; } static void set_slot_player(int slot, int pn) @@ -61,10 +61,10 @@ static void set_slot_active(int slot) { char buf[64], *sel = buf; - if (slot == -1) - sel = NULL; - else + if (slot) sprintf(sel, "#info-slot-%d", slot); + else + sel = NULL; dom_set_uniq_class(sel, "active", ".info-slot"); } @@ -89,8 +89,8 @@ void scoreboard_set_player_active(int pn) { active_pn = pn; - if (pn == -1) { - set_slot_active(-1); + if (!pn) { + set_slot_active(0); return; } @@ -98,7 +98,7 @@ void scoreboard_set_player_active(int pn) int slot1, slot2, pslot; if (np == 1) { slot1 = 1; - slot2 = -1; + slot2 = 0; pslot = 1; } else if (np == 2) { slot1 = 1; @@ -140,7 +140,7 @@ void scoreboard_set_player_avg(int pn, double avg) void scoreboard_flush_player_info(int pn) { int slot = player_slot(pn); - if (slot == -1) return; + if (!slot) return; char sel[32]; int len = sprintf(sel, "#info-slot-%d .", slot); @@ -224,6 +224,9 @@ void update_player_rem(int pn, int rem) void scoreboard_show_info(int num_players) { + if (bufs) free(bufs); + bufs = calloc(num_players, sizeof(*bufs)); + set_slot_player(1, 1); dom_add_class("#info-slot-1 .inner", "visible"); @@ -238,20 +241,13 @@ void scoreboard_show_info(int num_players) } } -static void clear_player_info(int pn) -{ - scoreboard_set_player_name(pn, NULL); - scoreboard_set_player_rem(pn, NULL); - scoreboard_set_player_sugg(pn, NULL); - scoreboard_set_player_avg(pn, 0); -} - void scoreboard_hide_info() { - dom_set_uniq_class(NULL, "visible", ".info-slot .inner"); - for (int pn = 1; pn < 4; ++pn) // FIXME - clear_player_info(pn); + free(bufs); + bufs = NULL; + memset(slots, 0, sizeof(slots)); + dom_set_uniq_class(NULL, "visible", ".info-slot .inner"); dom_remove_class("#info-slot-prev", "visible"); dom_remove_class("#info-slot-next", "visible"); } |