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/static/index.html | 2 +- web/static/sw.js | 2 +- web/web_control.c | 26 ++++++++++++++++++++++---- web/web_control.h | 1 + web/web_prompt.c | 7 ++++++- 5 files changed, 31 insertions(+), 7 deletions(-) (limited to 'web') diff --git a/web/static/index.html b/web/static/index.html index 609161a..8da5baa 100644 --- a/web/static/index.html +++ b/web/static/index.html @@ -3,7 +3,7 @@ dartboat™ - + diff --git a/web/static/sw.js b/web/static/sw.js index 5510e3f..253d350 100644 --- a/web/static/sw.js +++ b/web/static/sw.js @@ -1,5 +1,5 @@ const CACHE_PREFIX = 'dartboat-' -const CACHE_VERSION = '8'; +const CACHE_VERSION = '9'; const CACHE_NAME = `${CACHE_PREFIX}${CACHE_VERSION}`; const CACHE_FILES = [ 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() diff --git a/web/web_control.h b/web/web_control.h index 19c8719..738f3eb 100644 --- a/web/web_control.h +++ b/web/web_control.h @@ -1,6 +1,7 @@ #ifndef WEB_CONTROL_H #define WEB_CONTROL_H +void clear_scheduled(); void start_match(); void match_mode_selected(int mode); void end_match(); diff --git a/web/web_prompt.c b/web/web_prompt.c index edb9f99..5bb7758 100644 --- a/web/web_prompt.c +++ b/web/web_prompt.c @@ -4,6 +4,7 @@ #include "web_match.h" #include "web_misc.h" #include "web_scoreboard.h" +#include "web_svg.h" #include #include @@ -479,7 +480,11 @@ void prompt_handle_undo() void prompt_handle_exit() { if (key_is_active("exit")) { - // FIXME clear scheduled c calls (comp throwing) + clear_scheduled(); + // FIXME: we need to clean up since end_boat_visit is never + // called, but it's currently a bit messy + svg_clear_points(); + prompt_set_input(NULL); scoreboard_set_player_active(-1); end_match(); } -- cgit v1.2.3-70-g09d2