summaryrefslogtreecommitdiff
path: root/web/web_control.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/web_control.c')
-rw-r--r--web/web_control.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/web/web_control.c b/web/web_control.c
index cb83b99..b0dfd3b 100644
--- a/web/web_control.c
+++ b/web/web_control.c
@@ -15,11 +15,7 @@
#include <emscripten/emscripten.h>
-static int num_scheduled;
-void clear_scheduled()
-{
- num_scheduled = 0;
-}
+static int curr_match_id = 0;
void set_active_player(int pn)
{
@@ -45,13 +41,10 @@ void update_user_rem_from_pts(int pts)
}
EMSCRIPTEN_KEEPALIVE
-void end_boat_visit(int rem, double avg, bool scheduled)
+void end_boat_visit(int rem, double avg, int match_id)
{
- if (scheduled) {
- if (!num_scheduled)
- return;
- --num_scheduled;
- }
+ if (!state || match_id != curr_match_id)
+ return;
svg_clear_points();
update_player_rem(2, rem);
@@ -64,11 +57,10 @@ void end_boat_visit(int rem, double avg, bool scheduled)
}
EMSCRIPTEN_KEEPALIVE
-void draw_boat_throwing(int pts, char *str, double x, double y)
+void draw_boat_throwing(int pts, char *str, double x, double y, int match_id)
{
- if (!num_scheduled)
+ if (!state || match_id != curr_match_id)
return;
- --num_scheduled;
char pts_str[10];
sprintf(pts_str, "%d", pts);
@@ -103,7 +95,7 @@ void boat_visit()
(double)l->start / (((l->n_visits - 1) * 3) + v->n_darts) * 3;
if (!delay_ms) {
- end_boat_visit(l->rem, avg, false);
+ end_boat_visit(l->rem, avg, curr_match_id);
return;
}
@@ -121,15 +113,13 @@ void boat_visit()
char *tmp = malloc(len_str + 1); // free in draw_boat_throwing
memcpy(tmp, str, len_str + 1);
- EM_ASM({scheduleCCall($0, $1, $2, $3, $4, $5)},
+ EM_ASM({scheduleCCall($0, $1, $2, $3, $4, $5, $6)},
"draw_boat_throwing", delay_ms * (i+1),
- pts, tmp, c.x, c.y);
- ++num_scheduled;
+ pts, tmp, c.x, c.y, curr_match_id);
}
EM_ASM({scheduleCCall($0, $1, $2, $3, $4)}, "end_boat_visit",
- delay_ms * (v->n_darts + 1), l->rem, avg, true);
- ++num_scheduled;
+ delay_ms * (v->n_darts + 1), l->rem, avg, curr_match_id);
}
void handle_next()
@@ -288,6 +278,8 @@ void match_mode_selected(int mode)
void start_match()
{
if (state) free_state(); // rematch gets us here
+ ++curr_match_id;
+
state = calloc(1, sizeof(*state));
state->mode = match_opts->mode;
state->legs[0] = leg_init(match_opts->start_pts, match_opts->p1_name);
@@ -314,6 +306,11 @@ void start_match()
void end_match()
{
+ // clean up in case match was ended early
+ svg_clear_points();
+ prompt_set_input(NULL);
+ scoreboard_set_player_active(-1);
+
dom_remove_class("#key-exit", "visible");
dom_enable_exit_dialogue(false);
if (state) free_state();