From 44f14e515e111164c552d0f9a9ad8dce38b3d136 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 27 Apr 2022 04:35:46 -0700 Subject: web: move some memory management to c; use ccall wrapper less --- web/static/dartboat.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'web/static/dartboat.js') diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 06d9d10..9921cf3 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -15,15 +15,8 @@ function clearOi() { } 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]; - - let func = UTF8ToString(f); - setTimeout(() => Module.ccall(func, null, types, vals), ms); + const func = UTF8ToString(f); + setTimeout(() => Module[`_${func}`](...args), ms); } function promptGet() { @@ -142,7 +135,7 @@ function drawVisit(visit_no, p1_pts, p1_rem, p2_pts, p2_rem, p2_darts) { function setDelay(val, update_opts = true) { if (update_opts) localStorage.setItem('dartboat_delay', val); - Module.ccall('set_delay', null, ['number'], [val]); + _set_delay(Number(val)); } function updateDelay(val) { @@ -151,7 +144,7 @@ function updateDelay(val) { function setStdev(val, update_opts = true) { if (update_opts) localStorage.setItem('dartboat_stdev', val); - Module.ccall('set_stdev', null, ['number', 'number'], [val, val]); + _set_stdev(Number(val), Number(val)); } function updateStdev(val) { @@ -212,8 +205,7 @@ document.addEventListener('keydown', e => { function boatReady() { if (document.readyState === 'loading') - document.addEventListener('DOMContentLoaded', () => - Module.ccall('init')); + document.addEventListener('DOMContentLoaded', () => _init()); else - Module.ccall('init'); + _init(); } -- cgit v1.2.3-70-g09d2