diff options
-rw-r--r-- | web/web_control.c | 13 | ||||
-rw-r--r-- | web/web_main.c | 1 | ||||
-rw-r--r-- | web/web_match.c | 7 | ||||
-rw-r--r-- | web/web_match.h | 3 | ||||
-rw-r--r-- | web/web_opts.c | 20 | ||||
-rw-r--r-- | web/web_scoreboard.c | 6 |
6 files changed, 27 insertions, 23 deletions
diff --git a/web/web_control.c b/web/web_control.c index 39b92ba..310bbcf 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -20,7 +20,6 @@ static int curr_match_id = 0; void set_active_player(int pn) { state->active_player = pn; - state->active_leg = state->legs[pn-1]; scoreboard_set_player_active(pn); if (state->mode == M_PVC && pn == 2) @@ -36,7 +35,7 @@ void toggle_active_player() void update_user_rem_from_pts(int pts) { - update_player_rem(state->active_player, state->active_leg->rem - pts); + update_player_rem(state->active_player, state_active_leg()->rem - pts); scoreboard_flush_player_info(state->active_player); } @@ -160,12 +159,12 @@ void handle_next() void user_visit(int points) { - if (!is_points_valid(points, state->active_leg->rem)) { + if (!is_points_valid(points, state_active_leg()->rem)) { oi(); return; } - struct leg *l = state->active_leg; + struct leg *l = state_active_leg(); if (l->n_visits == l->size_visits) leg_grow_visits(l); struct visit *v = l->visits + l->n_visits++; @@ -212,7 +211,7 @@ static bool player_is_comp(int pn) static void undo_active() { - struct leg *l = state->active_leg; + struct leg *l = state_active_leg(); if (player_is_comp(state->active_player)) { l->rem += l->visits[--l->n_visits].points; @@ -227,7 +226,6 @@ static void undo_active() update_player_rem(state->active_player, l->rem); state->active_player = prev_throw_player(); - state->active_leg = state->legs[state->active_player - 1]; } static bool first_user_has_thrown() { @@ -252,7 +250,7 @@ void user_undo() if (state->num_darts) { state->num_darts = 0; - struct leg *l = state->active_leg; + struct leg *l = state_active_leg(); scoreboard_set_player_avg(state->active_player, ((double)(l->start - l->visits[l->n_visits-2].rem) / (l->n_visits - 1))); @@ -262,7 +260,6 @@ void user_undo() } state->active_player = prev_throw_player(); - state->active_leg = state->legs[state->active_player - 1]; while (player_is_comp(state->active_player)) undo_active(); undo_active(); diff --git a/web/web_main.c b/web/web_main.c index d525a94..76ef382 100644 --- a/web/web_main.c +++ b/web/web_main.c @@ -1,6 +1,5 @@ #include "web_control.h" #include "web_opts.h" -#include "web_prompt.h" #include "web_svg.h" #include "comp.h" diff --git a/web/web_match.c b/web/web_match.c index b3e8243..b399b85 100644 --- a/web/web_match.c +++ b/web/web_match.c @@ -1,5 +1,7 @@ #include "web_match.h" +#include "match.h" + #include <stdbool.h> #include <stddef.h> #include <stdlib.h> @@ -26,3 +28,8 @@ bool match_is_over() { return state->legs[0]->rem <= 0 || state->legs[1]->rem <= 0; } + +struct leg *state_active_leg() +{ + return state->legs[state->active_player - 1]; +} diff --git a/web/web_match.h b/web/web_match.h index 56117b5..85fcdbf 100644 --- a/web/web_match.h +++ b/web/web_match.h @@ -14,7 +14,6 @@ enum match_mode { struct match_state { enum match_mode mode; struct leg *legs[2]; - struct leg *active_leg; int active_player; int boat_undone; int num_darts; @@ -35,4 +34,6 @@ void match_opts_free(); bool match_is_over(); +struct leg *state_active_leg(); + #endif diff --git a/web/web_opts.c b/web/web_opts.c index b459305..b593306 100644 --- a/web/web_opts.c +++ b/web/web_opts.c @@ -14,9 +14,9 @@ #define PREFIX "dartboat_" int delay_ms = 1000; -static int difficulty = 32; -struct { int diff; double stdev; } DIFF_PRESETS[] = { +static int difficulty = 32; +static struct { int diff; double stdev; } DIFF_PRESETS[] = { { 0, 66.80}, // 10 { 8, 40.24}, // 20 {16, 28.14}, // 30 @@ -33,12 +33,12 @@ struct { int diff; double stdev; } DIFF_PRESETS[] = { }; #define NUM_DIFF_PRESETS (sizeof(DIFF_PRESETS) / sizeof(*DIFF_PRESETS)) -void set_delay(char *val) +static void set_delay(char *val) { delay_ms = atoi(val); } -void set_stdev(int diff) +static void set_stdev(int diff) { if (diff < DIFF_PRESETS[0].diff) diff = DIFF_PRESETS[0].diff; @@ -55,7 +55,7 @@ void set_stdev(int diff) ((diff - DIFF_PRESETS[ind - 1].diff) * step); } -void set_difficulty(char *val) +static void set_difficulty(char *val) { int diff = atoi(val); difficulty = diff < 0 ? 0 : diff > 99 ? 99 : diff; @@ -63,7 +63,7 @@ void set_difficulty(char *val) set_stdev(difficulty); } -char *prefix_opt(char *opt) +static char *prefix_opt(char *opt) { char len = strlen(opt); char *s = malloc(len + sizeof(PREFIX)); @@ -73,7 +73,7 @@ char *prefix_opt(char *opt) return s; } -char *read_opt(char *opt) +static char *read_opt(char *opt) { char *s = prefix_opt(opt); char *val = (char *)EM_ASM_INT({return readOpt($0)}, s); @@ -81,7 +81,7 @@ char *read_opt(char *opt) return val; } -bool read_delay() +static bool read_delay() { char *val = read_opt("delay"); if (!val) return false; @@ -91,7 +91,7 @@ bool read_delay() return true; } -bool read_difficulty() +static bool read_difficulty() { char *val = read_opt("difficulty"); if (!val) return false; @@ -115,7 +115,7 @@ void opts_init() dom_set_value("#difficulty", buf); } -void store_opt(char *opt, char *val) +static void store_opt(char *opt, char *val) { char *s = prefix_opt(opt); EM_ASM({storeOpt($0, $1)}, s, val); diff --git a/web/web_scoreboard.c b/web/web_scoreboard.c index 4ca823a..3b288c5 100644 --- a/web/web_scoreboard.c +++ b/web/web_scoreboard.c @@ -19,14 +19,14 @@ static struct { void scoreboard_set_player_active(int pn) { - char sel[64], *psel = sel; + char buf[64], *sel = buf; if (pn == -1) - psel = NULL; + sel = NULL; else sprintf(sel, "#p%d-info", pn); - dom_set_uniq_class(psel, "active", "[id$=-info]"); + dom_set_uniq_class(sel, "active", "[id$=-info]"); } void scoreboard_set_player_name(int pn, char *str) |