From 237359d107c5f8fb3e1f7a3532696eb19a6c56fc Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 2 May 2022 15:20:34 -0700 Subject: 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. --- web/web_control.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'web/web_control.c') 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(); -- cgit v1.2.3-70-g09d2