summaryrefslogtreecommitdiff
path: root/web/web_control.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-16 02:19:46 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-16 02:19:46 -0700
commit03bbcf1bf6be002dde3463c2370c11b2c7e38732 (patch)
treee75d4d85b0203927df73fb354227c53f95e5d5b0 /web/web_control.c
parent6a5cc149d373354941d046d3b3d851901fb4caf3 (diff)
downloaddartboat-03bbcf1bf6be002dde3463c2370c11b2c7e38732.tar.gz
dartboat-03bbcf1bf6be002dde3463c2370c11b2c7e38732.tar.xz
web: clean up properly when match is ended while comp is throwing
Diffstat (limited to 'web/web_control.c')
-rw-r--r--web/web_control.c26
1 files changed, 22 insertions, 4 deletions
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()