From 03bbcf1bf6be002dde3463c2370c11b2c7e38732 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 16 May 2022 02:19:46 -0700 Subject: web: clean up properly when match is ended while comp is throwing --- web/web_control.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'web/web_control.c') diff --git a/web/web_control.c b/web/web_control.c index 8148e89..cb83b99 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -15,6 +15,12 @@ #include +static int num_scheduled; +void clear_scheduled() +{ + num_scheduled = 0; +} + void set_active_player(int pn) { state->active_player = pn; @@ -39,8 +45,14 @@ void update_user_rem_from_pts(int pts) } EMSCRIPTEN_KEEPALIVE -void end_boat_visit(int rem, double avg) +void end_boat_visit(int rem, double avg, bool scheduled) { + if (scheduled) { + if (!num_scheduled) + return; + --num_scheduled; + } + svg_clear_points(); update_player_rem(2, rem); scoreboard_set_player_avg(2, avg); @@ -54,6 +66,10 @@ void end_boat_visit(int rem, double avg) EMSCRIPTEN_KEEPALIVE void draw_boat_throwing(int pts, char *str, double x, double y) { + if (!num_scheduled) + return; + --num_scheduled; + char pts_str[10]; sprintf(pts_str, "%d", pts); @@ -87,7 +103,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); + end_boat_visit(l->rem, avg, false); return; } @@ -108,10 +124,12 @@ void boat_visit() EM_ASM({scheduleCCall($0, $1, $2, $3, $4, $5)}, "draw_boat_throwing", delay_ms * (i+1), pts, tmp, c.x, c.y); + ++num_scheduled; } - EM_ASM({scheduleCCall($0, $1, $2, $3)}, "end_boat_visit", - delay_ms * (v->n_darts + 1), l->rem, avg); + EM_ASM({scheduleCCall($0, $1, $2, $3, $4)}, "end_boat_visit", + delay_ms * (v->n_darts + 1), l->rem, avg, true); + ++num_scheduled; } void handle_next() -- cgit v1.2.3-70-g09d2