diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-22 22:22:57 -0700 | 
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-22 22:22:57 -0700 | 
| commit | 07f0616f88553e0a4b3a5c23b0024e78d94d9d7e (patch) | |
| tree | 9883976c9a2f370c53b98a6dcd456b98df05dc1e /web/static/dartboat.js | |
| parent | e8592a80976919681d92a0d6ff89bae6d5fb992f (diff) | |
| download | dartboat-07f0616f88553e0a4b3a5c23b0024e78d94d9d7e.tar.gz dartboat-07f0616f88553e0a4b3a5c23b0024e78d94d9d7e.tar.xz | |
implement generic ccall scheduler in web js
Diffstat (limited to 'web/static/dartboat.js')
| -rw-r--r-- | web/static/dartboat.js | 29 | 
1 files changed, 12 insertions, 17 deletions
| diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 2a26a0c..0014d3a 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -190,20 +190,16 @@ function setNoneActive() {  	document.getElementById('p2-state').classList.remove('active');  } -function scheduleBoatThrowing(pts, ptr, delay_ms) { -	// ptr to c string must be copied before returning -	let str = UTF8ToString(ptr); -	setTimeout( -		function() { Module.ccall('draw_boat_throwing', null, -			['number', 'string'], [pts, str]) }, -		delay_ms); -} +function scheduleCCall(f, ms, ...args) { +	let types = []; +	let vals = []; + +	for (let i = 0; i < args.length/2; i++) +		vals[i] = (types[i] = UTF8ToString(args[i*2])) == 'string' ? +			UTF8ToString(args[i*2+1]) : args[i*2+1]; -function scheduleEndBoatThrowing(rem, avg, delay_ms) { -	setTimeout( -		function() { Module.ccall('end_boat_throwing', null, -			['number', 'number'], [rem, avg]) }, -		delay_ms); +	let func = UTF8ToString(f); +	setTimeout(function() { Module.ccall(func, null, types, vals) }, ms);  }  const POINT_CLASSES = [180, 140, 100, 60, 40, 20, 1, 0]; @@ -213,11 +209,10 @@ function drawVisit(visit_no, u_pts, u_rem, b_pts, b_rem, b_darts) {  	for (let [i, ptr] of [u_pts, u_rem, visit_no, b_rem, b_pts, b_darts].entries()) {  		let div = document.createElement('div');  		let v = div.textContent = UTF8ToString(ptr); -		if (i == 0 || i == 4) { +		if (i == 0 || i == 4)  			div.className = `p${POINT_CLASSES.find(x => x <= v)}`; -		} else if (i == 5) { -			if (v) div.textContent = `… ${v}`; -		} +		else if (i == 5 && v) +			div.textContent = `… ${v}`;  		div.className += ` visit-col${i+1}`;  		elem.append(div);  	} | 
