summaryrefslogtreecommitdiff
path: root/web/dartboat_wasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/dartboat_wasm.c')
-rw-r--r--web/dartboat_wasm.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c
index e624c67..9c838bd 100644
--- a/web/dartboat_wasm.c
+++ b/web/dartboat_wasm.c
@@ -17,11 +17,10 @@ int delay_ms = 1000;
struct match_state {
struct leg *l1, *l2;
+ int undone_count;
int complete;
};
-int undone_count = 0;
-
struct match_state *state;
void set_user_active() {
@@ -166,8 +165,8 @@ EMSCRIPTEN_KEEPALIVE void boat_visit() {
EM_ASM({promptMsgL($0)}, "Bot is throwing…");
struct leg *l = state->l2;
- if (undone_count) {
- --undone_count;
+ if (state->undone_count) {
+ --state->undone_count;
l->rem = l->visits[l->n_visits++].rem;
} else {
comp_visit(l);
@@ -253,7 +252,7 @@ EMSCRIPTEN_KEEPALIVE bool user_undo() {
struct visit *v = l->visits + --l->n_visits;
l->rem += v->points;
state->l2->rem += state->l2->visits[--state->l2->n_visits].points;
- ++undone_count;
+ ++state->undone_count;
EM_ASM({updatePlayerAvg($0, $1)}, P_USER,
l->n_visits ? (double)(l->start-l->rem)/l->n_visits : 0);
@@ -325,7 +324,7 @@ void init_boat() {
EMSCRIPTEN_KEEPALIVE void free_match() {
leg_free(state->l1);
- state->l2->n_visits += undone_count; // FIXME messy way to avoid memory leak
+ state->l2->n_visits += state->undone_count; // FIXME messy way to avoid memory leak
leg_free(state->l2);
free(state);
state = NULL;