grid-apps-cmms/src/kiri/mode/sla/driver.js

49 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-06-03 22:39:30 -04:00
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
2020-04-13 17:42:40 -04:00
import { newPrint } from '../../core/print.js';
import { sla_slice } from './slice.js';
import { sla_export } from './export.js';
2020-04-13 17:42:40 -04:00
export const SLA = {
init,
legacy: false,
slice: sla_slice,
prepare: sla_prepare,
export: sla_export,
2022-02-21 11:58:02 -05:00
};
2020-06-03 22:39:30 -04:00
2022-02-21 11:58:02 -05:00
if (SLA.legacy) {
console.log("SLA Driver in Legacy Mode");
}
2020-04-17 14:20:49 -04:00
function init(worker) {
// console.log({ INIT_SLA: worker });
}
2022-02-21 11:58:02 -05:00
// runs in worker. would usually be in src/mode/sla/prepare.js
// but the SLA driver skips the prepare step because there is no path routing
async function sla_prepare(widgets, settings, update) {
self.kiri_worker.current.print = newPrint(settings, widgets);
2022-02-21 11:58:02 -05:00
if (!SLA.wasm) {
fetch('/wasm/kiri-sla.wasm')
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, {
env: {
reportf: (a,b) => { console.log('[f]',a,b) },
reporti: (a,b) => { console.log('[i]',a,b) }
}
}))
.then(results => {
let {module, instance} = results;
let {exports} = instance;
let heap = new Uint8Array(exports.memory.buffer);
SLA.wasm = {
heap,
memory: exports.memory,
render: exports.render,
rle_encode: exports.rle_encode
};
});
2020-11-08 19:38:02 -05:00
}
2022-02-21 11:58:02 -05:00
update(1);
}