From 07f0616f88553e0a4b3a5c23b0024e78d94d9d7e Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 22 Apr 2022 22:22:57 -0700 Subject: implement generic ccall scheduler in web js --- web/dartboat_wasm.c | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) (limited to 'web/dartboat_wasm.c') diff --git a/web/dartboat_wasm.c b/web/dartboat_wasm.c index e8cde21..19d37db 100644 --- a/web/dartboat_wasm.c +++ b/web/dartboat_wasm.c @@ -156,6 +156,7 @@ EMSCRIPTEN_KEEPALIVE void update_boat_rem(int rem) { get_suggested(rem, 2); } +void end_boat_throwing(int, int); // FIXME EMSCRIPTEN_KEEPALIVE void boat_visit() { if (state->l1->rem <= 0 || state->l2->rem <= 0) @@ -175,41 +176,27 @@ EMSCRIPTEN_KEEPALIVE void boat_visit() { avg = ((double)l->start / (((l->n_visits - 1) * 3) + v->n_darts)) * 3; if (!delay_ms) { - update_boat_rem(l->rem); - EM_ASM({updateBoatAvg($0)}, avg); - EM_ASM({clearMatchLog()}); - draw_match(); - if (!is_match_over()) - set_user_active(); + end_boat_throwing(l->rem, avg); return; } - int pts = segment_points(v->darts[0]); - char str[20]; - char *seg_name = segment_name(v->darts[0]); - strcpy(str, seg_name); - free(seg_name); + int pts = 0; + char str[20] = {0}; - EM_ASM({scheduleBoatThrowing($0, $1, $2)}, pts, str, delay_ms); - - if (v->n_darts > 1) { - pts += segment_points(v->darts[1]); - seg_name = segment_name(v->darts[1]); - strcat(strcat(str, "-"), seg_name); - free(seg_name); - EM_ASM({scheduleBoatThrowing($0, $1, $2)}, pts, str, delay_ms * 2); - } - - if (v->n_darts > 2) { - pts += segment_points(v->darts[2]); - seg_name = segment_name(v->darts[2]); - strcat(strcat(str, "-"), seg_name); + for (int i = 0; i < v->n_darts; ++i) { + pts += segment_points(v->darts[i]); + char *seg_name = segment_name(v->darts[i]); + if (i) strcat(str, "-"); + strcat(str, seg_name); free(seg_name); - EM_ASM({scheduleBoatThrowing($0, $1, $2)}, pts, str, delay_ms * 3); + EM_ASM({scheduleCCall($0, $1, $2, $3, $4, $5)}, + "draw_boat_throwing", delay_ms * (i+1), + "number", pts, "string", str); } - EM_ASM({scheduleEndBoatThrowing($0, $1, $2)}, - l->rem, avg, delay_ms * (v->n_darts + 1)); + EM_ASM({scheduleCCall($0, $1, $2, $3, $4, $5)}, + "end_boat_throwing", delay_ms * (v->n_darts + 1), + "number", l->rem, "number", avg); } EMSCRIPTEN_KEEPALIVE bool user_visit(int points) { @@ -245,7 +232,7 @@ EMSCRIPTEN_KEEPALIVE bool user_visit(int points) { } // FIXME neg -EMSCRIPTEN_KEEPALIVE bool user_visit_to_rem(int rem) { +EMSCRIPTEN_KEEPALIVE void user_visit_to_rem(int rem) { user_visit(state->l1->rem - rem); } -- cgit v1.2.3-70-g09d2