diff --git a/assets/js/acas-backend-instance.js b/assets/js/acas-backend-instance.js index 6ab6e27..5193337 100644 --- a/assets/js/acas-backend-instance.js +++ b/assets/js/acas-backend-instance.js @@ -466,8 +466,7 @@ class BackendInstance { this.pV[profile].lc0WeightName = weightName; - if(this.getEngine(profile)?.setZeroWeights) - this.getEngine(profile).setZeroWeights(await loadFileAsUint8Array(`/A.C.A.S/assets/lc0-weights/${weightName}`)); + this.contactEngine('setZeroWeights', [await loadFileAsUint8Array(`/A.C.A.S/assets/lc0-weights/${weightName}`)], profile); } disableEngineElo(profile) { @@ -900,8 +899,8 @@ class BackendInstance { return this.engines[i ? i : this.engines.length - 1]; } - getEngine(i) { - return this.getEngineAcasObj(i)['engine']; + contactEngine(method, args, i) { + return this.getEngineAcasObj(i)['engine'](method, args); } sendMsgToEngine(msg, i) { @@ -942,7 +941,7 @@ class BackendInstance { const oldestUnfinishedCalcRequestObj = this.pV[profile].pendingCalculations.find(x => !x.finished); const isMessageForCurrentFen = oldestUnfinishedCalcRequestObj?.fen === this.currentFen; - if(!data?.currmovenumber) console.warn(msg, `(FOR FEN: ${oldestUnfinishedCalcRequestObj?.fen})`); + if(!data?.currmovenumber) console.warn(`${profile} ->`, msg, `\n(Message is for FEN -> ${oldestUnfinishedCalcRequestObj?.fen})`); if(msg.includes('option name UCI_Variant type combo')) { const chessVariants = extractVariantNames(msg); @@ -1065,8 +1064,6 @@ class BackendInstance { { toast.error(`FATAL ERROR: COI failed to enable SharedArrayBuffer, report issue to GitHub!`, 1e9); } else { - this.killExtraEngines(); - const msgHandler = msg => { try { this.engineMessageHandler(msg, profile); @@ -1079,41 +1076,69 @@ class BackendInstance { switch(profileChessEngine) { case 'lc0': - const waitForZeroFish = setInterval(async () => { - if(typeof zerofish !== 'undefined') { - clearInterval(waitForZeroFish); + const lc0 = new Worker('assets/libraries/zerofish/zerofishWorker.js', { type: 'module' }); + let lc0_loaded = false; + + lc0.onmessage = async e => { + if(e.data === true) { + lc0_loaded = true; this.engines.push({ 'type': profileChessEngine, - 'engine': await zerofish(), - 'sendMsg': msg => this.getEngine(profile).zero(msg), + 'engine': (method, a) => lc0.postMessage({ method: method, args: [...a] }), + 'sendMsg': msg => lc0.postMessage({ method: 'zero', args: [msg] }), + 'worker': lc0, profile }); - const ZeroFish = this.getEngine(profile); - - ZeroFish.listenZero = msgHandler; - await this.setEngineWeight(this.pV[profile].lc0WeightName, profile); - + this.engineStartNewGame('chess', profile); + } else if (e.data) { + msgHandler(e.data); + } + }; + + const waitLc0 = setInterval(() => { + if(lc0_loaded) { + clearInterval(waitLc0); + return; } + + lc0.postMessage({ method: 'acas_check_loaded' }); }, 100); break; default: // Fairy Stockfish NNUE WASM - this.engines.push({ - 'type': profileChessEngine, - 'engine': await Stockfish(), - 'sendMsg': msg => this.getEngine(profile).postMessage(msg), - profile - }); + const stockfish = new Worker('assets/libraries/fairy-stockfish-nnue.wasm/stockfishWorker.js'); + let stockfish_loaded = false; + + stockfish.onmessage = async e => { + if(e.data === true) { + stockfish_loaded = true; - const FairyStockfish = this.getEngine(profile); + this.engines.push({ + 'type': profileChessEngine, + 'engine': (method, a) => stockfish.postMessage({ method: method, args: [...a] }), + 'sendMsg': msg => stockfish.postMessage({ method: 'postMessage', args: [msg] }), + 'worker': stockfish, + profile + }); + + this.engineStartNewGame(formatVariant(this.pV[profile].chessVariant), profile); + } else if (e.data) { + msgHandler(e.data); + } + }; - FairyStockfish.addMessageListener(msgHandler); + const waitStockfish = setInterval(() => { + if(stockfish_loaded) { + clearInterval(waitStockfish); + return; + } - this.engineStartNewGame(formatVariant(this.pV[profile].chessVariant), profile); + stockfish.postMessage({ method: 'acas_check_loaded' }); + }, 100); break; } } @@ -1391,13 +1416,14 @@ class BackendInstance { killEngine(i) { console.warn('Killing engine', i); - let engine = null; + let worker = null; if(typeof i === 'string') { const engineIndex = this.engines.findIndex(obj => obj.profile === i); if(engineIndex !== -1) { - engine = this.engines[engineIndex].engine; + worker = this.engines[engineIndex].worker; + this.engines.splice(engineIndex, 1); if(this.pV[i]) { @@ -1410,10 +1436,9 @@ class BackendInstance { if(i >= 0 && i < this.engines.length) { const profileName = this.engines[i].profile; - engine = this.engines[i].engine; + worker = this.engines[i].worker; + this.engines.splice(i, 1); - - console.warn(profileName, engine); if(this.pV[profileName]) { this.Interface.boardUtils.removeMarkings(profileName); @@ -1425,19 +1450,9 @@ class BackendInstance { this.sendMsgToEngine('quit', i); - const freeFunction = engine?.['_free']; - - if(freeFunction) - engine?._free(); - } - - killExtraEngines() { - /* No implementation needed yet - for(let i = 0; i < this.engines.length; i++) { - if(this.engines.length - 1 !== i) { - this.killEngine(i); - } - }*/ + setTimeout(() => { + worker.terminate(); + }, 1000); } killEngines() { diff --git a/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.js b/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.js index 89afb9d..ba8e781 100644 --- a/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.js +++ b/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.js @@ -1,6 +1,6 @@ var Stockfish = (function() { - var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + var _scriptDir = '/A.C.A.S/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.js'; if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename; return ( function(Stockfish) { diff --git a/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.worker.js b/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.worker.js index 10f9b5e..06c145d 100644 --- a/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.worker.js +++ b/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.worker.js @@ -1,15 +1 @@ -"use strict";var Module={};if(typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string"){var nodeWorkerThreads=require("worker_threads");var parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",function(data){onmessage({data:data})});var nodeFS=require("fs");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(nodeFS.readFileSync(f,"utf8"))},postMessage:function(msg){parentPort.postMessage(msg)},performance:global.performance||{now:function(){return Date.now()}}})}function threadPrintErr(){var text=Array.prototype.slice.call(arguments).join(" ");console.error(text)}function threadAlert(){var text=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:text,threadId:Module["_pthread_self"]()})}var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=function(info,receiveInstance){var instance=new WebAssembly.Instance(Module["wasmModule"],info);receiveInstance(instance);Module["wasmModule"]=null;return instance.exports};function moduleLoaded(){}self.onmessage=function(e){try{if(e.data.cmd==="load"){Module["wasmModule"]=e.data.wasmModule;Module["wasmMemory"]=e.data.wasmMemory;Module["buffer"]=Module["wasmMemory"].buffer;Module["ENVIRONMENT_IS_PTHREAD"]=true;if(typeof e.data.urlOrBlob==="string"){importScripts(e.data.urlOrBlob)}else{var objectUrl=URL.createObjectURL(e.data.urlOrBlob);importScripts(objectUrl);URL.revokeObjectURL(objectUrl)}Stockfish(Module).then(function(instance){Module=instance;moduleLoaded()})}else if(e.data.cmd==="objectTransfer"){Module["PThread"].receiveObjectTransfer(e.data)}else if(e.data.cmd==="run"){Module["__performance_now_clock_drift"]=performance.now()-e.data.time;Module["__emscripten_thread_init"](e.data.threadInfoStruct,/*isMainBrowserThread=*/0,/*isMainRuntimeThread=*/0);var max=e.data.stackBase;var top=e.data.stackBase+e.data.stackSize;Module["establishStackSpace"](top,max);Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInit();try{var result=Module["invokeEntryPoint"](e.data.start_routine,e.data.arg);if(Module["keepRuntimeAlive"]()){Module["PThread"].setExitStatus(result)}else{Module["PThread"].threadExit(result)}}catch(ex){if(ex==="Canceled!"){Module["PThread"].threadCancel()}else if(ex!="unwind"){if(ex instanceof Module["ExitStatus"]){if(Module["keepRuntimeAlive"]()){}else{Module["PThread"].threadExit(ex.status)}}else{Module["PThread"].threadExit(-2);throw ex}}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["PThread"].threadCancel()}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processThreadQueue"){if(Module["_pthread_self"]()){Module["_emscripten_current_thread_process_queued_calls"]()}}else{err("worker.js received unknown command "+e.data.cmd);err(e.data)}}catch(ex){err("worker.js onmessage() captured an uncaught exception: "+ex);if(ex&&ex.stack)err(ex.stack);throw ex}}; -// -// Patch `onmessage` to support custom message -// -const oldOnmessage = self.onmessage; - -self.onmessage = (e) => { - if (e.data.cmd === "custom") { - if (typeof Module["onCustomMessage"] === "function") { - Module["onCustomMessage"](e.data.userData); - } - } else { - oldOnmessage(e); - } -}; +"use strict";var Module={};if("object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node){var nodeWorkerThreads=require("worker_threads"),parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",function(e){onmessage({data:e})});var nodeFS=require("fs");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(nodeFS.readFileSync(f,"utf8"))},postMessage:function(e){parentPort.postMessage(e)},performance:global.performance||{now:function(){return Date.now()}}})}function threadPrintErr(){var e=Array.prototype.slice.call(arguments).join(" ");console.error(e)}function threadAlert(){var e=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:e,threadId:Module._pthread_self()})}var err=threadPrintErr;function moduleLoaded(){}self.alert=threadAlert,Module.instantiateWasm=function(e,a){var t=new WebAssembly.Instance(Module.wasmModule,e);return a(t),Module.wasmModule=null,t.exports},self.onmessage=function(e){try{if("load"===e.data.cmd){if(Module.wasmModule=e.data.wasmModule,Module.wasmMemory=e.data.wasmMemory,Module.buffer=Module.wasmMemory.buffer,Module.ENVIRONMENT_IS_PTHREAD=!0,"string"==typeof e.data.urlOrBlob)importScripts(e.data.urlOrBlob);else{console.log(e.data.urlOrBlob);var a=URL.createObjectURL(e.data.urlOrBlob);importScripts(a),URL.revokeObjectURL(a)}Stockfish(Module).then(function(e){Module=e,moduleLoaded()})}else if("objectTransfer"===e.data.cmd)Module.PThread.receiveObjectTransfer(e.data);else if("run"===e.data.cmd){Module.__performance_now_clock_drift=performance.now()-e.data.time,Module.__emscripten_thread_init(e.data.threadInfoStruct,0,0);var t=e.data.stackBase,r=e.data.stackBase+e.data.stackSize;Module.establishStackSpace(r,t),Module.PThread.receiveObjectTransfer(e.data),Module.PThread.threadInit();try{var o=Module.invokeEntryPoint(e.data.start_routine,e.data.arg);Module.keepRuntimeAlive()?Module.PThread.setExitStatus(o):Module.PThread.threadExit(o)}catch(d){if("Canceled!"===d)Module.PThread.threadCancel();else if("unwind"!=d){if(d instanceof Module.ExitStatus)Module.keepRuntimeAlive()||Module.PThread.threadExit(d.status);else throw Module.PThread.threadExit(-2),d}}}else"cancel"===e.data.cmd?Module._pthread_self()&&Module.PThread.threadCancel():"setimmediate"===e.data.target||("processThreadQueue"===e.data.cmd?Module._pthread_self()&&Module._emscripten_current_thread_process_queued_calls():(err("worker.js received unknown command "+e.data.cmd),err(e.data)))}catch(s){throw err("worker.js onmessage() captured an uncaught exception: "+s),s&&s.stack&&err(s.stack),s}};const oldOnmessage=self.onmessage;self.onmessage=e=>{"custom"===e.data.cmd?"function"==typeof Module.onCustomMessage&&Module.onCustomMessage(e.data.userData):oldOnmessage(e)}; \ No newline at end of file diff --git a/assets/libraries/fairy-stockfish-nnue.wasm/stockfishWorker.js b/assets/libraries/fairy-stockfish-nnue.wasm/stockfishWorker.js new file mode 100644 index 0000000..3f851b7 --- /dev/null +++ b/assets/libraries/fairy-stockfish-nnue.wasm/stockfishWorker.js @@ -0,0 +1,28 @@ +importScripts('/A.C.A.S/assets/libraries/fairy-stockfish-nnue.wasm/stockfish.js'); + +let engine = null; + +(async () => { + engine = await Stockfish(); +})(); + +onmessage = e => { + const { method, args } = e.data; + + if (!engine) { + postMessage(false); + return; + } + + if(engine && method === 'acas_check_loaded') { + postMessage(true); + + engine.addMessageListener(postMessage); + + return; + } + + if (engine[method] && typeof engine[method] === 'function') { + engine[method](...args); + } +}; \ No newline at end of file diff --git a/assets/libraries/zerofish/zerofishEngine.js b/assets/libraries/zerofish/zerofishEngine.js index eadd7b5..075d0d7 100644 --- a/assets/libraries/zerofish/zerofishEngine.js +++ b/assets/libraries/zerofish/zerofishEngine.js @@ -1,1075 +1,3 @@ -var zerofish = (()=>{ - var _scriptDir = import.meta.url; - - return (function(moduleArg={}) { - - function aa() { - f.buffer != l.buffer && p(); - return l - } - function q() { - f.buffer != l.buffer && p(); - return ba - } - function r() { - f.buffer != l.buffer && p(); - return ca - } - function w() { - f.buffer != l.buffer && p(); - return da - } - function ea() { - f.buffer != l.buffer && p(); - return fa - } - var y = moduleArg, ha, z, readyPromise = new Promise((a,b)=>{ - ha = a; - z = b - } - ); - y.listenFish = a=>console.log("fish:", a); - y.listenZero = a=>console.log("zero:", a); - y.zero = a=>y.uci(a, !1); - y.fish = a=>y.uci(a, !0); - y.uci = (a,b)=>{ - const c = A(a) + 1 - , e = ia(c); - if (!e) - throw Error(`Could not allocate ${c} bytes`); - B(a, e, c); - ja(e, b); - ka(e) - } - ; - y.setZeroWeights = a=>{ - const b = ia(a.byteLength); - if (!b) - throw Error(`Could not allocate ${a.byteLength} bytes`); - y.HEAPU8.set(a, b); - la(b, a.byteLength) - } - ; - y.print = a=>{ - a.startsWith("zero:") ? y.listenZero(a.slice(5)) : a.startsWith("fish:") ? y.listenFish(a.slice(5)) : console.info(a) - } - ; - y.printErr = a=>console.error(a); - var ma = Object.assign({}, y), na = "object" == typeof window, C = "function" == typeof importScripts, oa = "object" == typeof process && "object" == typeof process.Ga && "string" == typeof process.Ga.node, D = y.ENVIRONMENT_IS_PTHREAD || !1, E = "", pa; - if (na || C) - C ? E = self.location.href : "undefined" != typeof document && document.currentScript && (E = document.currentScript.src), - _scriptDir && (E = _scriptDir), - E.startsWith("blob:") ? E = "" : E = E.substr(0, E.replace(/[?#].*/, "").lastIndexOf("/") + 1), - C && (pa = a=>{ - var b = new XMLHttpRequest; - b.open("GET", a, !1); - b.responseType = "arraybuffer"; - b.send(null); - return new Uint8Array(b.response) - } - ); - var qa = y.print || console.log.bind(console) - , F = y.printErr || console.error.bind(console); - Object.assign(y, ma); - ma = null; - var f, ra, H = !1, I, l, ba, ca, da, fa; - function p() { - var a = f.buffer; - y.HEAP8 = l = new Int8Array(a); - y.HEAPU8 = ba = new Uint8Array(a); - y.HEAP16 = new Int16Array(a); - y.HEAPU16 = new Uint16Array(a); - y.HEAP32 = ca = new Int32Array(a); - y.HEAPU32 = da = new Uint32Array(a); - y.HEAPF32 = new Float32Array(a); - y.HEAPF64 = fa = new Float64Array(a); - } - var sa = 268435456; - if (D) - f = y.wasmMemory; - else if (y.wasmMemory) - f = y.wasmMemory; - else if (f = new WebAssembly.Memory({ - initial: sa / 65536, - maximum: 32768, - shared: !0 - }), - !(f.buffer instanceof SharedArrayBuffer)) - throw F("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"), - oa && F("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and/or recent version)"), - Error("bad memory"); - p(); - sa = f.buffer.byteLength; - var ta = [] - , ua = [] - , va = [] - , wa = [] - , xa = [] - , ya = !1 - , J = 0 - , za = null - , K = null; - function Aa() { - J--; - if (0 == J && (null !== za && (clearInterval(za), - za = null), - K)) { - var a = K; - K = null; - a() - } - } - function L(a) { - a = "Aborted(" + a + ")"; - F(a); - H = !0; - I = 1; - a = new WebAssembly.RuntimeError(a + ". Build with -sASSERTIONS for more info."); - z(a); - throw a; - } - var Ba = a=>a.startsWith("data:application/octet-stream;base64,"), M; - y.locateFile ? (M = "zerofishEngine.wasm", - Ba(M) || (M = E + M)) : M = (new URL("zerofishEngine.wasm",import.meta.url)).href; - function Ca(a) { - if (pa) - return pa(a); - throw "both async and sync fetching of the wasm failed"; - } - function Da(a) { - return (na || C) && "function" == typeof fetch ? fetch(a, { - credentials: "same-origin" - }).then(b=>{ - if (!b.ok) - throw `failed to load wasm binary file at '${a}'`; - return b.arrayBuffer() - } - ).catch(()=>Ca(a)) : Promise.resolve().then(()=>Ca(a)) - } - function Ea(a, b, c) { - return Da(a).then(e=>WebAssembly.instantiate(e, b)).then(c, e=>{ - F(`failed to asynchronously prepare wasm: ${e}`); - L(e) - } - ) - } - function Fa(a, b) { - var c = M; - return "function" != typeof WebAssembly.instantiateStreaming || Ba(c) || "function" != typeof fetch ? Ea(c, a, b) : fetch(c, { - credentials: "same-origin" - }).then(e=>WebAssembly.instantiateStreaming(e, a).then(b, function(h) { - F(`wasm streaming compile failed: ${h}`); - F("falling back to ArrayBuffer instantiation"); - return Ea(c, a, b) - })) - } - function Ga(a) { - this.name = "ExitStatus"; - this.message = `Program terminated with exit(${a})`; - this.status = a - } - var Ha = a=>{ - a.terminate(); - a.onmessage = ()=>{} - } - , Ja = a=>{ - 0 == P.fa.length && (Ia(), - P.qa(P.fa[0])); - var b = P.fa.pop(); - if (!b) - return 6; - P.ha.push(b); - P.ca[a.ga] = b; - b.ga = a.ga; - b.postMessage({ - cmd: "run", - start_routine: a.Aa, - arg: a.wa, - pthread_ptr: a.ga - }, a.Fa); - return 0 - } - , Q = 0 - , Ka = ()=>0 < Q - , Na = a=>{ - var b = La(); - a = a(); - Ma(b); - return a - } - , R = (a,b,...c)=>Na(()=>{ - for (var e = c.length, h = Oa(8 * e), g = h >> 3, k = 0; k < c.length; k++) { - var u = c[k]; - ea()[g + k] = u - } - return Pa(a, 0, e, h, b) - } - ); - function Qa(a) { - if (D) - return R(0, 1, a); - I = a; - 0 < Q || (P.ta(), - H = !0); - throw new Ga(a); - } - var T = a=>{ - I = a; - if (D) - throw Ra(a), - "unwind"; - 0 < Q || D || (Sa(), - S(wa), - Ta(0), - Ua[1].length && Va(1, 10), - Ua[2].length && Va(2, 10), - P.ta(), - ya = !0); - Qa(a) - } - , Wa = a=>{ - if (!(a instanceof Ga || "unwind" == a)) - throw a; - } - ; - function Xa() { - for (var a = 8; a--; ) - Ia(); - ta.unshift(()=>{ - J++; - Ya(()=>Aa()) - } - ) - } - function Ia() { - var a = y.locateFile ? new Worker(E + "zerofishEngine.worker.js",{ - type: "module" - }) : new Worker(new URL("zerofishEngine.worker.js",import.meta.url),{ - type: "module" - }); - P.fa.push(a) - } - function Ya(a) { - D ? a() : Promise.all(P.fa.map(P.qa)).then(a) - } - var P = { - fa: [], - ha: [], - va: [], - ca: {}, - na() { - D ? (P.receiveObjectTransfer = P.za, - P.threadInitTLS = P.ua, - P.setExitStatus = P.sa) : Xa() - }, - sa: a=>I = a, - La: ["$terminateWorker"], - ta: ()=>{ - for (var a of P.ha) - Ha(a); - for (a of P.fa) - Ha(a); - P.fa = []; - P.ha = []; - P.ca = [] - } - , - ra: a=>{ - var b = a.ga; - delete P.ca[b]; - P.fa.push(a); - P.ha.splice(P.ha.indexOf(a), 1); - a.ga = 0; - Za(b) - } - , - za() {}, - ua() { - P.va.forEach(a=>a()) - }, - qa: a=>new Promise(b=>{ - a.onmessage = g=>{ - g = g.data; - var k = g.cmd; - if (g.targetThread && g.targetThread != U()) { - var u = P.ca[g.targetThread]; - u ? u.postMessage(g, g.transferList) : F(`Internal error! Worker sent a message "${k}" to target pthread ${g.targetThread}, but that thread no longer exists!`) - } else if ("checkMailbox" === k) - V(); - else if ("spawnThread" === k) - Ja(g); - else if ("cleanupThread" === k) - P.ra(P.ca[g.thread]); - else if ("killThread" === k) - g = g.thread, - k = P.ca[g], - delete P.ca[g], - Ha(k), - Za(g), - P.ha.splice(P.ha.indexOf(k), 1), - k.ga = 0; - else if ("cancelThread" === k) - P.ca[g.thread].postMessage({ - cmd: "cancel" - }); - else if ("loaded" === k) - a.loaded = !0, - b(a); - else if ("alert" === k) - alert(`Thread ${g.threadId}: ${g.text}`); - else if ("setimmediate" === g.target) - a.postMessage(g); - else if ("callHandler" === k) - y[g.handler](...g.args); - else - k && F(`worker sent an unknown command ${k}`) - } - ; - a.onerror = g=>{ - F(`${"worker sent an error!"} ${g.filename}:${g.lineno}: ${g.message}`); - throw g; - } - ; - var c = [], e = ["print", "printErr"], h; - for (h of e) - y.hasOwnProperty(h) && c.push(h); - a.postMessage({ - cmd: "load", - handlers: c, - urlOrBlob: y.mainScriptUrlOrBlob, - wasmMemory: f, - wasmModule: ra - }) - } - ) - }; - y.PThread = P; - var S = a=>{ - for (; 0 < a.length; ) - a.shift()(y) - } - ; - y.establishStackSpace = ()=>{ - var a = U() - , b = w()[a + 52 >> 2]; - a = w()[a + 56 >> 2]; - $a(b, b - a); - Ma(b) - } - ; - function Ra(a) { - if (D) - return R(1, 0, a); - --Q; - T(a) - } - var W = [], ab; - y.invokeEntryPoint = (a,b)=>{ - Q = 0; - var c = W[a]; - c || (a >= W.length && (W.length = a + 1), - W[a] = c = ab.get(a)); - a = c(b); - 0 < Q ? P.sa(a) : bb(a) - } - ; - class cb { - constructor(a) { - this.ma = a - 24 - } - na(a, b) { - w()[this.ma + 16 >> 2] = 0; - w()[this.ma + 4 >> 2] = a; - w()[this.ma + 8 >> 2] = b - } - } - var db = 0 - , eb = 0; - function fb(a, b, c, e) { - return D ? R(2, 1, a, b, c, e) : gb(a, b, c, e) - } - var gb = (a,b,c,e)=>{ - if ("undefined" == typeof SharedArrayBuffer) - return F("Current environment does not support SharedArrayBuffer, pthreads are not available!"), - 6; - var h = []; - if (D && 0 === h.length) - return fb(a, b, c, e); - a = { - Aa: c, - ga: a, - wa: e, - Fa: h - }; - return D ? (a.Ja = "spawnThread", - postMessage(a, h), - 0) : Ja(a) - } - , hb = "undefined" != typeof TextDecoder ? new TextDecoder("utf8") : void 0 - , ib = (a,b)=>{ - for (var c = b + NaN, e = b; a[e] && !(e >= c); ) - ++e; - if (16 < e - b && a.buffer && hb) - return hb.decode(a.buffer instanceof SharedArrayBuffer ? a.slice(b, e) : a.subarray(b, e)); - for (c = ""; b < e; ) { - var h = a[b++]; - if (h & 128) { - var g = a[b++] & 63; - if (192 == (h & 224)) - c += String.fromCharCode((h & 31) << 6 | g); - else { - var k = a[b++] & 63; - h = 224 == (h & 240) ? (h & 15) << 12 | g << 6 | k : (h & 7) << 18 | g << 12 | k << 6 | a[b++] & 63; - 65536 > h ? c += String.fromCharCode(h) : (h -= 65536, - c += String.fromCharCode(55296 | h >> 10, 56320 | h & 1023)) - } - } else - c += String.fromCharCode(h) - } - return c - } - , jb = a=>a ? ib(q(), a) : ""; - function kb(a, b, c) { - return D ? R(3, 1, a, b, c) : 0 - } - function lb(a, b, c) { - return D ? R(4, 1, a, b, c) : 0 - } - function mb(a, b, c, e) { - if (D) - return R(5, 1, a, b, c, e) - } - var nb = a=>{ - "function" === typeof Atomics.Ha && (Atomics.Ha(r(), a >> 2, a).value.then(V), - a += 128, - Atomics.store(r(), a >> 2, 1)) - } - ; - y.__emscripten_thread_mailbox_await = nb; - var V = ()=>{ - var a = U(); - if (a && (nb(a), - a = ob, - !ya && !H)) - try { - if (a(), - !(ya || 0 < Q)) - try { - D ? bb(I) : T(I) - } catch (b) { - Wa(b) - } - } catch (b) { - Wa(b) - } - } - ; - y.checkMailbox = V; - var pb = [], X = a=>0 === a % 4 && (0 !== a % 100 || 0 === a % 400), qb = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335], rb = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], tb = (a,b,c,e)=>{ - if (!(0 < e)) - return 0; - var h = c; - e = c + e - 1; - for (var g = 0; g < a.length; ++g) { - var k = a.charCodeAt(g); - if (55296 <= k && 57343 >= k) { - var u = a.charCodeAt(++g); - k = 65536 + ((k & 1023) << 10) | u & 1023 - } - if (127 >= k) { - if (c >= e) - break; - b[c++] = k - } else { - if (2047 >= k) { - if (c + 1 >= e) - break; - b[c++] = 192 | k >> 6 - } else { - if (65535 >= k) { - if (c + 2 >= e) - break; - b[c++] = 224 | k >> 12 - } else { - if (c + 3 >= e) - break; - b[c++] = 240 | k >> 18; - b[c++] = 128 | k >> 12 & 63 - } - b[c++] = 128 | k >> 6 & 63 - } - b[c++] = 128 | k & 63 - } - } - b[c] = 0; - return c - h - } - , B = (a,b,c)=>tb(a, q(), b, c), Y = a=>{ - Y.oa || (Y.oa = {}); - Y.oa[a] || (Y.oa[a] = 1, - F(a)) - } - , A = a=>{ - for (var b = 0, c = 0; c < a.length; ++c) { - var e = a.charCodeAt(c); - 127 >= e ? b++ : 2047 >= e ? b += 2 : 55296 <= e && 57343 >= e ? (b += 4, - ++c) : b += 3 - } - return b - } - , ub = {}, wb = ()=>{ - if (!vb) { - var a = { - USER: "web_user", - LOGNAME: "web_user", - PATH: "/", - PWD: "/", - HOME: "/home/web_user", - LANG: ("object" == typeof navigator && navigator.languages && navigator.languages[0] || "C").replace("-", "_") + ".UTF-8", - _: "./this.program" - }, b; - for (b in ub) - void 0 === ub[b] ? delete a[b] : a[b] = ub[b]; - var c = []; - for (b in a) - c.push(`${b}=${a[b]}`); - vb = c - } - return vb - } - , vb; - function xb(a, b) { - if (D) - return R(6, 1, a, b); - var c = 0; - wb().forEach((e,h)=>{ - var g = b + c; - h = w()[a + 4 * h >> 2] = g; - for (g = 0; g < e.length; ++g) - aa()[h++] = e.charCodeAt(g); - aa()[h] = 0; - c += e.length + 1 - } - ); - return 0 - } - function yb(a, b) { - if (D) - return R(7, 1, a, b); - var c = wb(); - w()[a >> 2] = c.length; - var e = 0; - c.forEach(h=>e += h.length + 1); - w()[b >> 2] = e; - return 0 - } - function zb(a) { - return D ? R(8, 1, a) : 52 - } - function Ab(a, b, c, e) { - return D ? R(9, 1, a, b, c, e) : 52 - } - function Bb(a, b, c, e, h) { - return D ? R(10, 1, a, b, c, e, h) : 70 - } - var Ua = [null, [], []] - , Va = (a,b)=>{ - var c = Ua[a]; - 0 === b || 10 === b ? ((1 === a ? qa : F)(ib(c, 0)), - c.length = 0) : c.push(b) - } - ; - function Cb(a, b, c, e) { - if (D) - return R(11, 1, a, b, c, e); - for (var h = 0, g = 0; g < c; g++) { - var k = w()[b >> 2] - , u = w()[b + 4 >> 2]; - b += 8; - for (var v = 0; v < u; v++) - Va(a, q()[k + v]); - h += u - } - w()[e >> 2] = h; - return 0 - } - var Db = ()=>{ - if ("object" == typeof crypto && "function" == typeof crypto.getRandomValues) - return a=>(a.set(crypto.getRandomValues(new Uint8Array(a.byteLength))), - a); - L("initRandomDevice") - } - , Eb = a=>(Eb = Db())(a) - , Fb = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] - , Gb = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; - function Hb(a) { - var b = Array(A(a) + 1); - tb(a, b, 0, b.length); - return b - } - var Ib = (a,b)=>{ - aa().set(a, b) - } - , Jb = (a,b,c,e)=>{ - function h(d, m, t) { - for (d = "number" == typeof d ? d.toString() : d || ""; d.length < m; ) - d = t[0] + d; - return d - } - function g(d, m) { - return h(d, m, "0") - } - function k(d, m) { - function t(sb) { - return 0 > sb ? -1 : 0 < sb ? 1 : 0 - } - var G; - 0 === (G = t(d.getFullYear() - m.getFullYear())) && 0 === (G = t(d.getMonth() - m.getMonth())) && (G = t(d.getDate() - m.getDate())); - return G - } - function u(d) { - switch (d.getDay()) { - case 0: - return new Date(d.getFullYear() - 1,11,29); - case 1: - return d; - case 2: - return new Date(d.getFullYear(),0,3); - case 3: - return new Date(d.getFullYear(),0,2); - case 4: - return new Date(d.getFullYear(),0,1); - case 5: - return new Date(d.getFullYear() - 1,11,31); - case 6: - return new Date(d.getFullYear() - 1,11,30) - } - } - function v(d) { - var m = d.ia; - for (d = new Date((new Date(d.ja + 1900,0,1)).getTime()); 0 < m; ) { - var t = d.getMonth() - , G = (X(d.getFullYear()) ? Fb : Gb)[t]; - if (m > G - d.getDate()) - m -= G - d.getDate() + 1, - d.setDate(1), - 11 > t ? d.setMonth(t + 1) : (d.setMonth(0), - d.setFullYear(d.getFullYear() + 1)); - else { - d.setDate(d.getDate() + m); - break - } - } - t = new Date(d.getFullYear() + 1,0,4); - m = u(new Date(d.getFullYear(),0,4)); - t = u(t); - return 0 >= k(m, d) ? 0 >= k(t, d) ? d.getFullYear() + 1 : d.getFullYear() : d.getFullYear() - 1 - } - var n = w()[e + 40 >> 2]; - e = { - Da: r()[e >> 2], - Ca: r()[e + 4 >> 2], - ka: r()[e + 8 >> 2], - pa: r()[e + 12 >> 2], - la: r()[e + 16 >> 2], - ja: r()[e + 20 >> 2], - ea: r()[e + 24 >> 2], - ia: r()[e + 28 >> 2], - Ma: r()[e + 32 >> 2], - Ba: r()[e + 36 >> 2], - Ea: n ? jb(n) : "" - }; - c = jb(c); - n = { - "%c": "%a %b %d %H:%M:%S %Y", - "%D": "%m/%d/%y", - "%F": "%Y-%m-%d", - "%h": "%b", - "%r": "%I:%M:%S %p", - "%R": "%H:%M", - "%T": "%H:%M:%S", - "%x": "%m/%d/%y", - "%X": "%H:%M:%S", - "%Ec": "%c", - "%EC": "%C", - "%Ex": "%m/%d/%y", - "%EX": "%H:%M:%S", - "%Ey": "%y", - "%EY": "%Y", - "%Od": "%d", - "%Oe": "%e", - "%OH": "%H", - "%OI": "%I", - "%Om": "%m", - "%OM": "%M", - "%OS": "%S", - "%Ou": "%u", - "%OU": "%U", - "%OV": "%V", - "%Ow": "%w", - "%OW": "%W", - "%Oy": "%y" - }; - for (var x in n) - c = c.replace(new RegExp(x,"g"), n[x]); - var N = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ") - , O = "January February March April May June July August September October November December".split(" "); - n = { - "%a": d=>N[d.ea].substring(0, 3), - "%A": d=>N[d.ea], - "%b": d=>O[d.la].substring(0, 3), - "%B": d=>O[d.la], - "%C": d=>g((d.ja + 1900) / 100 | 0, 2), - "%d": d=>g(d.pa, 2), - "%e": d=>h(d.pa, 2, " "), - "%g": d=>v(d).toString().substring(2), - "%G": v, - "%H": d=>g(d.ka, 2), - "%I": d=>{ - d = d.ka; - 0 == d ? d = 12 : 12 < d && (d -= 12); - return g(d, 2) - } - , - "%j": d=>{ - for (var m = 0, t = 0; t <= d.la - 1; m += (X(d.ja + 1900) ? Fb : Gb)[t++]) - ; - return g(d.pa + m, 3) - } - , - "%m": d=>g(d.la + 1, 2), - "%M": d=>g(d.Ca, 2), - "%n": ()=>"\n", - "%p": d=>0 <= d.ka && 12 > d.ka ? "AM" : "PM", - "%S": d=>g(d.Da, 2), - "%t": ()=>"\t", - "%u": d=>d.ea || 7, - "%U": d=>g(Math.floor((d.ia + 7 - d.ea) / 7), 2), - "%V": d=>{ - var m = Math.floor((d.ia + 7 - (d.ea + 6) % 7) / 7); - 2 >= (d.ea + 371 - d.ia - 2) % 7 && m++; - if (m) - 53 == m && (t = (d.ea + 371 - d.ia) % 7, - 4 == t || 3 == t && X(d.ja) || (m = 1)); - else { - m = 52; - var t = (d.ea + 7 - d.ia - 1) % 7; - (4 == t || 5 == t && X(d.ja % 400 - 1)) && m++ - } - return g(m, 2) - } - , - "%w": d=>d.ea, - "%W": d=>g(Math.floor((d.ia + 7 - (d.ea + 6) % 7) / 7), 2), - "%y": d=>(d.ja + 1900).toString().substring(2), - "%Y": d=>d.ja + 1900, - "%z": d=>{ - d = d.Ba; - var m = 0 <= d; - d = Math.abs(d) / 60; - return (m ? "+" : "-") + String("0000" + (d / 60 * 100 + d % 60)).slice(-4) - } - , - "%Z": d=>d.Ea, - "%%": ()=>"%" - }; - c = c.replace(/%%/g, "\x00\x00"); - for (x in n) - c.includes(x) && (c = c.replace(new RegExp(x,"g"), n[x](e))); - c = c.replace(/\0\0/g, "%"); - x = Hb(c); - if (x.length > b) - return 0; - Ib(x, a); - return x.length - 1 - } - ; - P.na(); - var Kb = [Qa, Ra, fb, kb, lb, mb, xb, yb, zb, Ab, Bb, Cb] - , Mb = { - b: (a,b,c)=>{ - (new cb(a)).na(b, c); - db = a; - eb++; - throw db; - } - , - k: a=>{ - Lb(a, !C, 1, !na, 1048576, !1); - P.ua() - } - , - h: a=>{ - D ? postMessage({ - cmd: "cleanupThread", - thread: a - }) : P.ra(P.ca[a]) - } - , - D: gb, - g: kb, - v: lb, - w: mb, - F: ()=>1, - C: (a,b)=>{ - a == b ? setTimeout(V) : D ? postMessage({ - targetThread: a, - cmd: "checkMailbox" - }) : (a = P.ca[a]) && a.postMessage({ - cmd: "checkMailbox" - }) - } - , - E: (a,b,c,e,h)=>{ - pb.length = e; - b = h >> 3; - for (h = 0; h < e; h++) - pb[h] = ea()[b + h]; - a = Kb[a]; - P.ya = c; - c = a(...pb); - P.ya = 0; - return c - } - , - j: nb, - e: ()=>{} - , - o: function(a, b, c) { - a = new Date(1E3 * (b + 2097152 >>> 0 < 4194305 - !!a ? (a >>> 0) + 4294967296 * b : NaN)); - r()[c >> 2] = a.getSeconds(); - r()[c + 4 >> 2] = a.getMinutes(); - r()[c + 8 >> 2] = a.getHours(); - r()[c + 12 >> 2] = a.getDate(); - r()[c + 16 >> 2] = a.getMonth(); - r()[c + 20 >> 2] = a.getFullYear() - 1900; - r()[c + 24 >> 2] = a.getDay(); - b = (X(a.getFullYear()) ? qb : rb)[a.getMonth()] + a.getDate() - 1 | 0; - r()[c + 28 >> 2] = b; - r()[c + 36 >> 2] = -(60 * a.getTimezoneOffset()); - b = (new Date(a.getFullYear(),6,1)).getTimezoneOffset(); - var e = (new Date(a.getFullYear(),0,1)).getTimezoneOffset(); - a = (b != e && a.getTimezoneOffset() == Math.min(e, b)) | 0; - r()[c + 32 >> 2] = a - }, - B: (a,b,c,e)=>{ - var h = (new Date).getFullYear() - , g = new Date(h,0,1) - , k = new Date(h,6,1); - h = g.getTimezoneOffset(); - var u = k.getTimezoneOffset() - , v = Math.max(h, u); - w()[a >> 2] = 60 * v; - r()[b >> 2] = Number(h != u); - a = n=>n.toLocaleTimeString(void 0, { - hour12: !1, - timeZoneName: "short" - }).split(" ")[1]; - g = a(g); - k = a(k); - u < h ? (B(g, c, 17), - B(k, e, 17)) : (B(g, e, 17), - B(k, c, 17)) - } - , - x: ()=>{ - L("") - } - , - i: ()=>{ - C || (Y("Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread"), - L("Blocking on the main thread is not allowed by default. See https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread")) - } - , - G: ()=>Date.now(), - l: ()=>{ - Q += 1; - throw "unwind"; - } - , - p: function(a, b, c) { - var e = Error().stack.toString(); - e = e.slice(e.indexOf("\n", Math.max(e.lastIndexOf("_emscripten_log"), e.lastIndexOf("_emscripten_get_callstack"))) + 1); - a & 8 && "undefined" == typeof emscripten_source_map && (Y('Source map information is not available, emscripten_log with EM_LOG_C_STACK will be ignored. Build with "--pre-js $EMSCRIPTEN/src/emscripten-source-map.min.js" linker flag to add source map loading to code.'), - a = a ^ 8 | 16); - var h = e.split("\n"); - e = ""; - var g = RegExp("\\s*(.*?)@(.*?):([0-9]+):([0-9]+)") - , k = RegExp("\\s*(.*?)@(.*):(.*)(:(.*))?") - , u = RegExp("\\s*at (.*?) \\((.*):(.*):(.*)\\)"); - for (m in h) { - var v = h[m], n; - if ((n = u.exec(v)) && 5 == n.length) { - v = n[1]; - var x = n[2]; - var N = n[3]; - n = n[4] - } else if ((n = g.exec(v)) || (n = k.exec(v)), - n && 4 <= n.length) - v = n[1], - x = n[2], - N = n[3], - n = n[4] | 0; - else { - e += v + "\n"; - continue - } - var O = !1; - if (a & 8) { - var d = emscripten_source_map.Ka({ - line: N, - xa: n - }); - if (O = d?.source) - a & 64 && (d.source = d.source.substring(d.source.replace(/\\/g, "/").lastIndexOf("/") + 1)), - e += ` at ${v} (${d.source}:${d.line}:${d.xa})\n` - } - if (a & 16 || !O) - a & 64 && (x = x.substring(x.replace(/\\/g, "/").lastIndexOf("/") + 1)), - e += (O ? ` = ${v}` : ` at ${v}`) + ` (${x}:${N}:${n})\n` - } - var m = e = e.replace(/\s+$/, ""); - return !b || 0 >= c ? A(m) + 1 : B(m, b, c) + 1 - }, - c: ()=>performance.timeOrigin + performance.now(), - A: a=>{ - var b = q().length; - a >>>= 0; - if (a <= b || 2147483648 < a) - return !1; - for (var c = 1; 4 >= c; c *= 2) { - var e = b * (1 + .2 / c); - e = Math.min(e, a + 100663296); - var h = Math; - e = Math.max(a, e); - a: { - h = (h.min.call(h, 2147483648, e + (65536 - e % 65536) % 65536) - f.buffer.byteLength + 65535) / 65536; - try { - f.grow(h); - p(); - var g = 1; - break a - } catch (k) {} - g = void 0 - } - if (g) - return !0 - } - return !1 - } - , - m: Ka, - s: xb, - t: yb, - d: T, - f: zb, - u: Ab, - n: Bb, - z: Cb, - q: (a,b)=>{ - Eb(q().subarray(a, a + b)); - return 0 - } - , - y: function(a) { - y.Ia(jb(a)) - }, - a: f || y.wasmMemory, - r: (a,b,c,e)=>Jb(a, b, c, e) - } - , Z = function() { - function a(c, e) { - Z = c.exports; - P.va.push(Z.P); - ab = Z.R; - ua.unshift(Z.H); - ra = e; - Aa(); - return Z - } - var b = { - a: Mb - }; - J++; - if (y.instantiateWasm) - try { - return y.instantiateWasm(b, a) - } catch (c) { - F(`Module.instantiateWasm callback failed with error: ${c}`), - z(c) - } - Fa(b, function(c) { - a(c.instance, c.module) - }).catch(z); - return {} - }() - , ka = y._free = a=>(ka = y._free = Z.I)(a) - , ia = y._malloc = a=>(ia = y._malloc = Z.J)(a) - , U = y._pthread_self = ()=>(U = y._pthread_self = Z.K)(); - y._main = (a,b)=>(y._main = Z.L)(a, b); - var ja = y._uci = (a,b)=>(ja = y._uci = Z.M)(a, b) - , la = y._set_weights = (a,b)=>(la = y._set_weights = Z.N)(a, b); - y._quit = ()=>(y._quit = Z.O)(); - y.__emscripten_tls_init = ()=>(y.__emscripten_tls_init = Z.P)(); - var Nb = y.__emscripten_proxy_main = (a,b)=>(Nb = y.__emscripten_proxy_main = Z.Q)(a, b) - , Sa = ()=>(Sa = Z.S)() - , Lb = y.__emscripten_thread_init = (a,b,c,e,h,g)=>(Lb = y.__emscripten_thread_init = Z.T)(a, b, c, e, h, g); - y.__emscripten_thread_crashed = ()=>(y.__emscripten_thread_crashed = Z.U)(); - var Ta = a=>(Ta = Z.V)(a) - , Pa = (a,b,c,e,h)=>(Pa = Z.W)(a, b, c, e, h) - , Za = a=>(Za = Z.X)(a) - , bb = y.__emscripten_thread_exit = a=>(bb = y.__emscripten_thread_exit = Z.Y)(a) - , ob = ()=>(ob = Z.Z)() - , $a = (a,b)=>($a = Z._)(a, b) - , Ma = a=>(Ma = Z.$)(a) - , Oa = a=>(Oa = Z.aa)(a) - , La = ()=>(La = Z.ba)(); - y.___original_main = ()=>(y.___original_main = Z.da)(); - y.___start_em_js = 84932; - y.___stop_em_js = 84995; - y.wasmMemory = f; - y.keepRuntimeAlive = Ka; - y.stringToUTF8 = B; - y.lengthBytesUTF8 = A; - y.ExitStatus = Ga; - var Ob; - K = function Pb() { - Ob || Qb(); - Ob || (K = Pb) - } - ; - function Qb() { - if (!(0 < J)) - if (D) - ha(y), - D || S(ua), - startWorker(y); - else if (S(ta), - !(0 < J || Ob || (Ob = !0, - y.calledRun = !0, - H))) { - D || S(ua); - D || S(va); - ha(y); - if (Rb) { - var a = Nb; - Q += 1; - try { - var b = a(0, 0); - T(b, !0) - } catch (c) { - Wa(c) - } - } - D || S(xa) - } - } - var Rb = !0; - Qb(); - - return readyPromise - } - ); -} -)(); -export default zerofish; \ No newline at end of file +var zerofish=(()=>{var e=import.meta.url;return function(r={}){function t(){return b.buffer!=E.buffer&&F(),E}function a(){return b.buffer!=E.buffer&&F(),x}function n(){return b.buffer!=E.buffer&&F(),S}function i(){return b.buffer!=E.buffer&&F(),O}function o(){return b.buffer!=E.buffer&&F(),T}var s,u,l,f=r,c=new Promise((e,r)=>{u=e,l=r});f.listenFish=e=>console.log("fish:",e),f.listenZero=e=>console.log("zero:",e),f.zero=e=>f.uci(e,!1),f.fish=e=>f.uci(e,!0),f.uci=(e,r)=>{let t=eM(e)+1,a=eW(t);if(!a)throw Error(`Could not allocate ${t} bytes`);e2(e,a,t),eL(a,r),eI(a)},f.setZeroWeights=e=>{let r=eW(e.byteLength);if(!r)throw Error(`Could not allocate ${e.byteLength} bytes`);f.HEAPU8.set(e,r),eR(r,e.byteLength)},f.print=e=>{e.startsWith("zero:")?f.listenZero(e.slice(5)):e.startsWith("fish:")?f.listenFish(e.slice(5)):console.info(e)},f.printErr=e=>console.error(e);var h,$=Object.assign({},f),_="object"==typeof window,g="function"==typeof importScripts,d="object"==typeof process&&"object"==typeof process.Ga&&"string"==typeof process.Ga.node,m=f.ENVIRONMENT_IS_PTHREAD||!1,p="";(_||g)&&(g?p=self.location.href:"undefined"!=typeof document&&document.currentScript&&(p=document.currentScript.src),e&&(p=e),p=p.startsWith("blob:")?"":p.substr(0,p.replace(/[?#].*/,"").lastIndexOf("/")+1),g&&(h=e=>{var r=new XMLHttpRequest;return r.open("GET",e,!1),r.responseType="arraybuffer",r.send(null),new Uint8Array(r.response)}));var v=f.print||console.log.bind(console),w=f.printErr||console.error.bind(console);Object.assign(f,$),$=null;var b,y,M,E,x,S,O,T,k=!1;function F(){var e=b.buffer;f.HEAP8=E=new Int8Array(e),f.HEAPU8=x=new Uint8Array(e),f.HEAP16=new Int16Array(e),f.HEAPU16=new Uint16Array(e),f.HEAP32=S=new Int32Array(e),f.HEAPU32=O=new Uint32Array(e),f.HEAPF32=new Float32Array(e),f.HEAPF64=T=new Float64Array(e)}var A=268435456;if(m)b=f.wasmMemory;else if(f.wasmMemory)b=f.wasmMemory;else if(!((b=new WebAssembly.Memory({initial:A/65536,maximum:32768,shared:!0})).buffer instanceof SharedArrayBuffer))throw w("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),d&&w("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and/or recent version)"),Error("bad memory");F(),A=b.buffer.byteLength;var Y=[],C=[],H=[],j=[],P=[],z=!1,D=0,I=null,W=null;function B(){if(0==--D&&(null!==I&&(clearInterval(I),I=null),W)){var e=W;W=null,e()}}function L(e){throw w(e="Aborted("+e+")"),k=!0,M=1,l(e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info.")),e}var R,U=e=>e.startsWith("data:application/octet-stream;base64,");function N(e){if(h)return h(e);throw"both async and sync fetching of the wasm failed"}function G(e,r,t){var a;return(a=e,(_||g)&&"function"==typeof fetch?fetch(a,{credentials:"same-origin"}).then(e=>{if(!e.ok)throw`failed to load wasm binary file at '${a}'`;return e.arrayBuffer()}).catch(()=>N(a)):Promise.resolve().then(()=>N(a))).then(e=>WebAssembly.instantiate(e,r)).then(t,e=>{w(`failed to asynchronously prepare wasm: ${e}`),L(e)})}function q(e){this.name="ExitStatus",this.message=`Program terminated with exit(${e})`,this.status=e}f.locateFile?U(R="zerofishEngine.wasm")||(R=p+R):R=new URL("zerofishEngine.wasm",import.meta.url).href;var V=e=>{e.terminate(),e.onmessage=()=>{}},Z=e=>{0==ea.fa.length&&(et(),ea.qa(ea.fa[0]));var r=ea.fa.pop();return r?(ea.ha.push(r),ea.ca[e.ga]=r,r.ga=e.ga,r.postMessage({cmd:"run",start_routine:e.Aa,arg:e.wa,pthread_ptr:e.ga},e.Fa),0):6},J=0,K=e=>{var r=rr();return e=e(),eQ(r),e},X=(e,r,...t)=>K(()=>{for(var a=t.length,n=re(8*a),i=n>>3,s=0;s{if(M=e,m)throw ei(e),"unwind";0{if(!(e instanceof q||"unwind"==e))throw e};function et(){var e=f.locateFile?new Worker(p+"zerofishEngine.worker.js",{type:"module"}):new Worker(new URL("zerofishEngine.worker.js",import.meta.url),{type:"module"});ea.fa.push(e)}var ea={fa:[],ha:[],va:[],ca:{},na(){m?(ea.receiveObjectTransfer=ea.za,ea.threadInitTLS=ea.ua,ea.setExitStatus=ea.sa):function e(){for(var r=8;r--;)et();Y.unshift(()=>{var e;D++,e=()=>B(),m?e():Promise.all(ea.fa.map(ea.qa)).then(e)})}()},sa:e=>M=e,La:["$terminateWorker"],ta(){for(var e of ea.ha)V(e);for(e of ea.fa)V(e);ea.fa=[],ea.ha=[],ea.ca=[]},ra(e){var r=e.ga;delete ea.ca[r],ea.fa.push(e),ea.ha.splice(ea.ha.indexOf(e),1),e.ga=0,eZ(r)},za(){},ua(){ea.va.forEach(e=>e())},qa:e=>new Promise(r=>{e.onmessage=t=>{var a=(t=t.data).cmd;if(t.targetThread&&t.targetThread!=eB()){var n=ea.ca[t.targetThread];n?n.postMessage(t,t.transferList):w(`Internal error! Worker sent a message "${a}" to target pthread ${t.targetThread}, but that thread no longer exists!`)}else"checkMailbox"===a?ev():"spawnThread"===a?Z(t):"cleanupThread"===a?ea.ra(ea.ca[t.thread]):"killThread"===a?(t=t.thread,a=ea.ca[t],delete ea.ca[t],V(a),eZ(t),ea.ha.splice(ea.ha.indexOf(a),1),a.ga=0):"cancelThread"===a?ea.ca[t.thread].postMessage({cmd:"cancel"}):"loaded"===a?(e.loaded=!0,r(e)):"alert"===a?alert(`Thread ${t.threadId}: ${t.text}`):"setimmediate"===t.target?e.postMessage(t):"callHandler"===a?f[t.handler](...t.args):a&&w(`worker sent an unknown command ${a}`)},e.onerror=e=>{throw w(`worker sent an error! ${e.filename}:${e.lineno}: ${e.message}`),e};var t,a=[];for(t of["print","printErr"])f.hasOwnProperty(t)&&a.push(t);e.postMessage({cmd:"load",handlers:a,urlOrBlob:f.mainScriptUrlOrBlob,wasmMemory:b,wasmModule:y})})};f.PThread=ea;var en=e=>{for(;0{var e=eB(),r=i()[e+52>>2];e=i()[e+56>>2],eX(r,r-e),eQ(r)};var eo,es=[];f.invokeEntryPoint=(e,r)=>{J=0;var t=es[e];t||(e>=es.length&&(es.length=e+1),es[e]=t=eo.get(e)),e=t(r),0>2]=0,i()[this.ma+4>>2]=e,i()[this.ma+8>>2]=r}}var el=0,ef=0;function ec(e,r,t,a){return m?X(2,1,e,r,t,a):eh(e,r,t,a)}var eh=(e,r,t,a)=>{if("undefined"==typeof SharedArrayBuffer)return w("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var n=[];return m&&0===n.length?ec(e,r,t,a):(e={Aa:t,ga:e,wa:a,Fa:n},m?(e.Ja="spawnThread",postMessage(e,n),0):Z(e))},e$="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0,e_=(e,r)=>{for(var t=r+NaN,a=r;e[a]&&!(a>=t);)++a;if(16(n=224==(240&n)?(15&n)<<12|i<<6|o:(7&n)<<18|i<<12|o<<6|63&e[r++])?t+=String.fromCharCode(n):(n-=65536,t+=String.fromCharCode(55296|n>>10,56320|1023&n))}}else t+=String.fromCharCode(n)}return t},eg=e=>e?e_(a(),e):"";function ed(e,r,t){return m?X(3,1,e,r,t):0}function em(e,r,t){return m?X(4,1,e,r,t):0}function e0(e,r,t,a){if(m)return X(5,1,e,r,t,a)}var ep=e=>{"function"==typeof Atomics.Ha&&(Atomics.Ha(n(),e>>2,e).value.then(ev),e+=128,Atomics.store(n(),e>>2,1))};f.__emscripten_thread_mailbox_await=ep;var ev=()=>{var e=eB();if(e&&(ep(e),e=eK,!z&&!k))try{if(e(),!(z||00==e%4&&(0!=e%100||0==e%400),ey=[0,31,60,91,121,152,182,213,244,274,305,335],e1=[0,31,59,90,120,151,181,212,243,273,304,334],e4=(e,r,t,a)=>{if(!(0=o&&(o=65536+((1023&o)<<10)|1023&e.charCodeAt(++i)),127>=o){if(t>=a)break;r[t++]=o}else{if(2047>=o){if(t+1>=a)break;r[t++]=192|o>>6}else{if(65535>=o){if(t+2>=a)break;r[t++]=224|o>>12}else{if(t+3>=a)break;r[t++]=240|o>>18,r[t++]=128|o>>12&63}r[t++]=128|o>>6&63}r[t++]=128|63&o}}return r[t]=0,t-n},e2=(e,r,t)=>e4(e,a(),r,t),e3=e=>{e3.oa||(e3.oa={}),e3.oa[e]||(e3.oa[e]=1,w(e))},eM=e=>{for(var r=0,t=0;t=a?r++:2047>=a?r+=2:55296<=a&&57343>=a?(r+=4,++t):r+=3}return r},eE={},ex=()=>{if(!ew){var e,r={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:"./this.program"};for(e in eE)void 0===eE[e]?delete r[e]:r[e]=eE[e];var t=[];for(e in r)t.push(`${e}=${r[e]}`);ew=t}return ew};function eS(e,r){if(m)return X(6,1,e,r);var a=0;return ex().forEach((n,o)=>{var s=r+a;for(o=i()[e+4*o>>2]=s,s=0;s>2]=t.length;var a=0;return t.forEach(e=>a+=e.length+1),i()[r>>2]=a,0}function eT(e){return m?X(8,1,e):52}function ek(e,r,t,a){return m?X(9,1,e,r,t,a):52}function e6(e,r,t,a,n){return m?X(10,1,e,r,t,a,n):70}var eF=[null,[],[]],e5=(e,r)=>{var t=eF[e];0===r||10===r?((1===e?v:w)(e_(t,0)),t.length=0):t.push(r)};function eA(e,r,t,n){if(m)return X(11,1,e,r,t,n);for(var o=0,s=0;s>2],l=i()[r+4>>2];r+=8;for(var f=0;f>2]=o,0}var e9=()=>{if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues)return e=>(e.set(crypto.getRandomValues(new Uint8Array(e.byteLength))),e);L("initRandomDevice")},e7=e=>(e7=e9())(e),eY=[31,29,31,30,31,30,31,31,30,31,30,31],eC=[31,28,31,30,31,30,31,31,30,31,30,31],eH=(e,r)=>{t().set(e,r)},ej=(e,r,t,a)=>{function o(e,r,t){for(e="number"==typeof e?e.toString():e||"";e.lengthe?-1:0a-e.getDate())r-=a-e.getDate()+1,e.setDate(1),11>t?e.setMonth(t+1):(e.setMonth(0),e.setFullYear(e.getFullYear()+1));else{e.setDate(e.getDate()+r);break}}return t=new Date(e.getFullYear()+1,0,4),r=l(new Date(e.getFullYear(),0,4)),t=l(t),0>=u(r,e)?0>=u(t,e)?e.getFullYear()+1:e.getFullYear():e.getFullYear()-1}var c,h,$=i()[a+40>>2];for(var _ in a={Da:n()[a>>2],Ca:n()[a+4>>2],ka:n()[a+8>>2],pa:n()[a+12>>2],la:n()[a+16>>2],ja:n()[a+20>>2],ea:n()[a+24>>2],ia:n()[a+28>>2],Ma:n()[a+32>>2],Ba:n()[a+36>>2],Ea:$?eg($):""},t=eg(t),$={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})t=t.replace(RegExp(_,"g"),$[_]);var g="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),d="January February March April May June July August September October November December".split(" ");for(_ in $={"%a":e=>g[e.ea].substring(0,3),"%A":e=>g[e.ea],"%b":e=>d[e.la].substring(0,3),"%B":e=>d[e.la],"%C":e=>s((e.ja+1900)/100|0,2),"%d":e=>s(e.pa,2),"%e":e=>o(e.pa,2," "),"%g":e=>f(e).toString().substring(2),"%G":f,"%H":e=>s(e.ka,2),"%I":e=>(0==(e=e.ka)?e=12:12s(e.la+1,2),"%M":e=>s(e.Ca,2),"%n":()=>"\n","%p":e=>0<=e.ka&&12>e.ka?"AM":"PM","%S":e=>s(e.Da,2),"%t":()=>" ","%u":e=>e.ea||7,"%U":e=>s(Math.floor((e.ia+7-e.ea)/7),2),"%V"(e){var r=Math.floor((e.ia+7-(e.ea+6)%7)/7);if(2>=(e.ea+371-e.ia-2)%7&&r++,r)53==r&&(4==(t=(e.ea+371-e.ia)%7)||3==t&&eb(e.ja)||(r=1));else{r=52;var t=(e.ea+7-e.ia-1)%7;(4==t||5==t&&eb(e.ja%400-1))&&r++}return s(r,2)},"%w":e=>e.ea,"%W":e=>s(Math.floor((e.ia+7-(e.ea+6)%7)/7),2),"%y":e=>(e.ja+1900).toString().substring(2),"%Y":e=>e.ja+1900,"%z"(e){var r=0<=(e=e.Ba);return(r?"+":"-")+String("0000"+((e=Math.abs(e)/60)/60*100+e%60)).slice(-4)},"%Z":e=>e.Ea,"%%":()=>"%"},t=t.replace(/%%/g,"\0\0"),$)t.includes(_)&&(t=t.replace(RegExp(_,"g"),$[_](a)));return(_=(h=Array(eM(c=t=t.replace(/\0\0/g,"%"))+1),e4(c,h,0,h.length),h)).length>r?0:(eH(_,e),_.length-1)};ea.na();var eP=[Q,ei,ec,ed,em,e0,eS,eO,eT,ek,e6,eA],ez={b(e,r,t){throw new eu(e).na(r,t),el=e,ef++,el},k(e){eG(e,!g,1,!_,1048576,!1),ea.ua()},h(e){m?postMessage({cmd:"cleanupThread",thread:e}):ea.ra(ea.ca[e])},D:eh,g:ed,v:em,w:e0,F:()=>1,C(e,r){e==r?setTimeout(ev):m?postMessage({targetThread:e,cmd:"checkMailbox"}):(e=ea.ca[e])&&e.postMessage({cmd:"checkMailbox"})},E(e,r,t,a,n){for(e8.length=a,r=n>>3,n=0;n>>0<4194305-!!e?(e>>>0)+4294967296*r:NaN)),n()[t>>2]=e.getSeconds(),n()[t+4>>2]=e.getMinutes(),n()[t+8>>2]=e.getHours(),n()[t+12>>2]=e.getDate(),n()[t+16>>2]=e.getMonth(),n()[t+20>>2]=e.getFullYear()-1900,n()[t+24>>2]=e.getDay(),r=(eb(e.getFullYear())?ey:e1)[e.getMonth()]+e.getDate()-1|0,n()[t+28>>2]=r,n()[t+36>>2]=-(60*e.getTimezoneOffset()),r=new Date(e.getFullYear(),6,1).getTimezoneOffset();var a=new Date(e.getFullYear(),0,1).getTimezoneOffset();e=0|(r!=a&&e.getTimezoneOffset()==Math.min(a,r)),n()[t+32>>2]=e},B(e,r,t,a){var o=(new Date).getFullYear(),s=new Date(o,0,1),u=new Date(o,6,1);o=s.getTimezoneOffset();var l=u.getTimezoneOffset(),f=Math.max(o,l);i()[e>>2]=60*f,n()[r>>2]=Number(o!=l),s=(e=e=>e.toLocaleTimeString(void 0,{hour12:!1,timeZoneName:"short"}).split(" ")[1])(s),u=e(u),lDate.now(),l(){throw J+=1,"unwind"},p:function(e,r,t){var a=Error().stack.toString();a=a.slice(a.indexOf("\n",Math.max(a.lastIndexOf("_emscripten_log"),a.lastIndexOf("_emscripten_get_callstack")))+1),8&e&&"undefined"==typeof emscripten_source_map&&(e3('Source map information is not available, emscripten_log with EM_LOG_C_STACK will be ignored. Build with "--pre-js $EMSCRIPTEN/src/emscripten-source-map.min.js" linker flag to add source map loading to code.'),e=8^e|16);var n=a.split("\n");a="";var i=RegExp("\\s*(.*?)@(.*?):([0-9]+):([0-9]+)"),o=RegExp("\\s*(.*?)@(.*):(.*)(:(.*))?"),s=RegExp("\\s*at (.*?) \\((.*):(.*):(.*)\\)");for(_ in n){var u,l=n[_];if((u=s.exec(l))&&5==u.length){l=u[1];var f=u[2],c=u[3];u=u[4]}else if((u=i.exec(l))||(u=o.exec(l)),u&&4<=u.length)l=u[1],f=u[2],c=u[3],u=0|u[4];else{a+=l+"\n";continue}var h=!1;if(8&e){var $=emscripten_source_map.Ka({line:c,xa:u});(h=$?.source)&&(64&e&&($.source=$.source.substring($.source.replace(/\\/g,"/").lastIndexOf("/")+1)),a+=` at ${l} (${$.source}:${$.line}:${$.xa}) +`)}(16&e||!h)&&(64&e&&(f=f.substring(f.replace(/\\/g,"/").lastIndexOf("/")+1)),a+=(h?` = ${l}`:` at ${l}`)+` (${f}:${c}:${u}) +`)}var _=a=a.replace(/\s+$/,"");return!r||0>=t?eM(_)+1:e2(_,r,t)+1},c:()=>performance.timeOrigin+performance.now(),A(e){var r=a().length;if((e>>>=0)<=r||2147483648=t;t*=2){var n=r*(1+.2/t);n=Math.min(n,e+100663296);var i=Math;n=Math.max(e,n);a:{i=(i.min.call(i,2147483648,n+(65536-n%65536)%65536)-b.buffer.byteLength+65535)/65536;try{b.grow(i),F();var o=1;break a}catch(s){}o=void 0}if(o)return!0}return!1},m:()=>0(e7(a().subarray(e,e+r)),0),y:function(e){f.Ia(eg(e))},a:b||f.wasmMemory,r:(e,r,t,a)=>ej(e,r,t,a)},eD=function(){function e(e,r){return eD=e.exports,ea.va.push(eD.P),eo=eD.R,C.unshift(eD.H),y=r,B(),eD}var r,t,a,n={a:ez};if(D++,f.instantiateWasm)try{return f.instantiateWasm(n,e)}catch(i){w(`Module.instantiateWasm callback failed with error: ${i}`),l(i)}return(r=n,t=function(r){e(r.instance,r.module)},a=R,"function"!=typeof WebAssembly.instantiateStreaming||U(a)||"function"!=typeof fetch?G(a,r,t):fetch(a,{credentials:"same-origin"}).then(e=>WebAssembly.instantiateStreaming(e,r).then(t,function(e){return w(`wasm streaming compile failed: ${e}`),w("falling back to ArrayBuffer instantiation"),G(a,r,t)}))).catch(l),{}}(),eI=f._free=e=>(eI=f._free=eD.I)(e),eW=f._malloc=e=>(eW=f._malloc=eD.J)(e),eB=f._pthread_self=()=>(eB=f._pthread_self=eD.K)();f._main=(e,r)=>(f._main=eD.L)(e,r);var eL=f._uci=(e,r)=>(eL=f._uci=eD.M)(e,r),eR=f._set_weights=(e,r)=>(eR=f._set_weights=eD.N)(e,r);f._quit=()=>(f._quit=eD.O)(),f.__emscripten_tls_init=()=>(f.__emscripten_tls_init=eD.P)();var eU=f.__emscripten_proxy_main=(e,r)=>(eU=f.__emscripten_proxy_main=eD.Q)(e,r),eN=()=>(eN=eD.S)(),eG=f.__emscripten_thread_init=(e,r,t,a,n,i)=>(eG=f.__emscripten_thread_init=eD.T)(e,r,t,a,n,i);f.__emscripten_thread_crashed=()=>(f.__emscripten_thread_crashed=eD.U)();var eq=e=>(eq=eD.V)(e),eV=(e,r,t,a,n)=>(eV=eD.W)(e,r,t,a,n),eZ=e=>(eZ=eD.X)(e),eJ=f.__emscripten_thread_exit=e=>(eJ=f.__emscripten_thread_exit=eD.Y)(e),eK=()=>(eK=eD.Z)(),eX=(e,r)=>(eX=eD._)(e,r),eQ=e=>(eQ=eD.$)(e),re=e=>(re=eD.aa)(e),rr=()=>(rr=eD.ba)();function rt(){if(!(0(f.___original_main=eD.da)(),f.___start_em_js=84932,f.___stop_em_js=84995,f.wasmMemory=b,f.keepRuntimeAlive=()=>0{var module=Module["wasmModule"];Module["wasmModule"]=null;var instance=new WebAssembly.Instance(module,info);return receiveInstance(instance)};self.onunhandledrejection=e=>{throw e.reason||e};function handleMessage(e){try{if(e.data.cmd==="load"){let messageQueue=[];self.onmessage=e=>messageQueue.push(e);self.startWorker=instance=>{Module=instance;postMessage({"cmd":"loaded"});for(let msg of messageQueue){handleMessage(msg)}self.onmessage=handleMessage};Module["wasmModule"]=e.data.wasmModule;for(const handler of e.data.handlers){Module[handler]=(...args)=>{postMessage({cmd:"callHandler",handler:handler,args:args})}}Module["wasmMemory"]=e.data.wasmMemory;Module["buffer"]=Module["wasmMemory"].buffer;Module["ENVIRONMENT_IS_PTHREAD"]=true;(e.data.urlOrBlob?import(e.data.urlOrBlob):import("./zerofishEngine.js")).then(exports=>exports.default(Module))}else if(e.data.cmd==="run"){Module["__emscripten_thread_init"](e.data.pthread_ptr,/*is_main=*/0,/*is_runtime=*/0,/*can_block=*/1);Module["__emscripten_thread_mailbox_await"](e.data.pthread_ptr);Module["establishStackSpace"]();Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInitTLS();if(!initializedJS){initializedJS=true}try{Module["invokeEntryPoint"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!="unwind"){throw ex}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["__emscripten_thread_exit"](-1)}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="checkMailbox"){if(initializedJS){Module["checkMailbox"]()}}else if(e.data.cmd){err(`worker.js received unknown command ${e.data.cmd}`);err(e.data)}}catch(ex){Module["__emscripten_thread_crashed"]?.();throw ex}}self.onmessage=handleMessage; +"use strict";var Module={};var initializedJS=false;function threadPrintErr(...args){var text=args.join(" ");console.error(text)}function threadAlert(...args){var text=args.join(" ");postMessage({cmd:"alert",text:text,threadId:Module["_pthread_self"]()})}var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=(info,receiveInstance)=>{var module=Module["wasmModule"];Module["wasmModule"]=null;var instance=new WebAssembly.Instance(module,info);return receiveInstance(instance)};self.onunhandledrejection=e=>{throw e.reason||e};function handleMessage(e){try{if(e.data.cmd==="load"){let messageQueue=[];self.onmessage=e=>messageQueue.push(e);self.startWorker=instance=>{Module=instance;postMessage({"cmd":"loaded"});for(let msg of messageQueue){handleMessage(msg)}self.onmessage=handleMessage};Module["wasmModule"]=e.data.wasmModule;for(const handler of e.data.handlers){Module[handler]=(...args)=>{postMessage({cmd:"callHandler",handler:handler,args:args})}}Module["wasmMemory"]=e.data.wasmMemory;Module["buffer"]=Module["wasmMemory"].buffer;Module["ENVIRONMENT_IS_PTHREAD"]=true;(e.data.urlOrBlob?import(e.data.urlOrBlob):import("./zerofishEngine.js")).then(exports=>exports.default(Module))}else if(e.data.cmd==="run"){Module["__emscripten_thread_init"](e.data.pthread_ptr,/*is_main=*/0,/*is_runtime=*/0,/*can_block=*/1);Module["__emscripten_thread_mailbox_await"](e.data.pthread_ptr);Module["establishStackSpace"]();Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInitTLS();if(!initializedJS){initializedJS=true}try{Module["invokeEntryPoint"](e.data.start_routine,e.data.arg)}catch(ex){if(ex!="unwind"){throw ex}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["__emscripten_thread_exit"](-1)}}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="checkMailbox"){if(initializedJS){Module["checkMailbox"]()}}else if(e.data.cmd){err(`worker.js received unknown command ${e.data.cmd}`);err(e.data)}}catch(ex){Module["__emscripten_thread_crashed"]?.();throw ex}}self.onmessage=handleMessage; \ No newline at end of file diff --git a/assets/libraries/zerofish/zerofishWorker.js b/assets/libraries/zerofish/zerofishWorker.js new file mode 100644 index 0000000..5480560 --- /dev/null +++ b/assets/libraries/zerofish/zerofishWorker.js @@ -0,0 +1,28 @@ +import zerofish from '/A.C.A.S/assets/libraries/zerofish/zerofishEngine.js'; + +let engine = null; + +(async () => { + engine = await zerofish(); +})(); + +onmessage = e => { + const { method, args } = e.data; + + if (!engine) { + postMessage(false); + return; + } + + if(engine && method === 'acas_check_loaded') { + postMessage(true); + + engine.listenZero = msg => postMessage(msg); + + return; + } + + if (engine[method] && typeof engine[method] === 'function') { + engine[method](...args); + } +}; \ No newline at end of file diff --git a/index.html b/index.html index b14e19a..7ad13ee 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,6 @@ -