diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 17:53:11 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-23 17:53:11 -0700 |
commit | d31b800c35595428790905b21b771bbc187488ab (patch) | |
tree | a79f14318c2472fca4c545374664b3c6e79101a8 /web/dartboat_wasm.c | |
parent | 9b7110d2652a18377bdd09094704188399bef0f8 (diff) | |
download | dartboat-d31b800c35595428790905b21b771bbc187488ab.tar.gz dartboat-d31b800c35595428790905b21b771bbc187488ab.tar.xz |
web: fix undo state carrying over into next match
Diffstat (limited to 'web/dartboat_wasm.c')
-rw-r--r-- | web/dartboat_wasm.c | 11 |
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; |