diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-02 15:20:34 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-02 15:20:34 -0700 |
commit | 237359d107c5f8fb3e1f7a3532696eb19a6c56fc (patch) | |
tree | 192f6007e9a59c334477dd6ab6ce209b067614ba /web/web_control.c | |
parent | 09c23f60189223db58d98e49ee94df947667662d (diff) | |
download | dartboat-237359d107c5f8fb3e1f7a3532696eb19a6c56fc.tar.gz dartboat-237359d107c5f8fb3e1f7a3532696eb19a6c56fc.tar.xz |
web: buffer player info and flush on state change
Constant calls from Wasm to JS to replace unchanged elements in the DOM
is not very efficient.
Diffstat (limited to 'web/web_control.c')
-rw-r--r-- | web/web_control.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/web/web_control.c b/web/web_control.c index 13e37ec..4f78d67 100644 --- a/web/web_control.c +++ b/web/web_control.c @@ -33,6 +33,7 @@ EMSCRIPTEN_KEEPALIVE void update_user_rem_from_pts(int pts) { update_player_rem(state->active_player, state->active_leg->rem - pts); + ui_flush_player_info(state->active_player); } EMSCRIPTEN_KEEPALIVE @@ -40,7 +41,7 @@ void end_boat_visit(int rem, double avg) { EM_ASM(svgClearPoints()); update_player_rem(2, rem); - EM_ASM({updatePlayerAvg($0, $1)}, 2, avg); + ui_set_player_avg(2, avg); EM_ASM({setPromptInput($0)}, ""); EM_ASM({promptMsgR($0)}, ""); @@ -114,6 +115,8 @@ void handle_next() boat_visit(); } } + + ui_flush(); } EMSCRIPTEN_KEEPALIVE @@ -156,7 +159,7 @@ void user_undo() if (state->num_darts) { state->num_darts = 0; - EM_ASM({updatePlayerAvg($0, $1)}, state->active_player, + ui_set_player_avg(state->active_player, ((double)(state->active_leg->start - state->active_leg->visits[ state->active_leg->n_visits-2].rem) / @@ -186,10 +189,10 @@ void user_undo() ++state->boat_undone; } - update_player_avg(state->active_player, 0); + ui_set_player_avg(state->active_player, 0); update_player_rem(state->active_player, l->rem); if (state->mode == M_PVC) { - update_player_avg(2, 0); + ui_set_player_avg(2, 0); update_player_rem(2, state->legs[1]->rem); } @@ -229,15 +232,15 @@ void start_match(int mode) state->legs[1] = leg_init(501, mode == M_PVC ? "Bot" : "Player 2"); EM_ASM({showPlayerInfo($0)}, 1); - EM_ASM({updatePlayerName($0, $1)}, 1, state->legs[0]->name); + update_player_name(1, state->legs[0]->name); update_player_rem(1, state->legs[0]->rem); - EM_ASM({updatePlayerAvg($0, $1)}, 1, 0); + update_player_avg(1, 0); if (mode != M_P) { EM_ASM({showPlayerInfo($0)}, 2); - EM_ASM({updatePlayerName($0, $1)}, 2, state->legs[1]->name); + update_player_name(2, state->legs[1]->name); update_player_rem(2, state->legs[1]->rem); - EM_ASM({updatePlayerAvg($0, $1)}, 2, 0); + update_player_avg(2, 0); } draw_visits(); |