From d31b800c35595428790905b21b771bbc187488ab Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 23 Apr 2022 17:53:11 -0700 Subject: web: fix undo state carrying over into next match --- web/dartboat_wasm.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'web/dartboat_wasm.c') 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; -- cgit v1.2.3-70-g09d2