diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-16 02:19:46 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-16 02:19:46 -0700 |
commit | 03bbcf1bf6be002dde3463c2370c11b2c7e38732 (patch) | |
tree | e75d4d85b0203927df73fb354227c53f95e5d5b0 | |
parent | 6a5cc149d373354941d046d3b3d851901fb4caf3 (diff) | |
download | dartboat-03bbcf1bf6be002dde3463c2370c11b2c7e38732.tar.gz dartboat-03bbcf1bf6be002dde3463c2370c11b2c7e38732.tar.xz |
web: clean up properly when match is ended while comp is throwing
-rw-r--r-- | web/static/index.html | 2 | ||||
-rw-r--r-- | web/static/sw.js | 2 | ||||
-rw-r--r-- | web/web_control.c | 26 | ||||
-rw-r--r-- | web/web_control.h | 1 | ||||
-rw-r--r-- | web/web_prompt.c | 7 |
5 files changed, 31 insertions, 7 deletions
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 @@ <head> <title>dartboat™</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> - <meta name="viewport" content="width=device-width, initial-scale=1"> + <meta name="viewport" content="width=device-width, user-scalable=no"> <meta name="description" content="Darts opponent for when you've got no friends."> <meta name="theme-color" content="#583a90"> <link rel="stylesheet" type="text/css" href="style.css"> 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 <emscripten/emscripten.h> +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 <stdio.h> #include <stdlib.h> @@ -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(); } |