blob: 90b39561e0bd9e0f995ebbda056fcb2198cf7dff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
workers = [];
function exit() {
for (var worker of workers) {
worker.terminate();
}
console.clear();
}
async function main() {
let fetchingSource = fetch('bin/webhogg-wasm.wasm');
let canvasElement = document.getElementById('c');
let offCanvas = canvasElement.transferControlToOffscreen();
let fetchedSource = await fetchingSource;
source = await fetchedSource.arrayBuffer();
const modules = [
{ type: 'graphics',
source: source,
canvas: offCanvas,
dt: 16 },
{ type: 'logic',
source: source,
canvas: [],
dt: 10000 },
];
for (var module of modules) {
let worker = new Worker('pkg/worker.js');
if (module.type === 'graphics') {
worker.postMessage(module, [module.canvas]);
} else {
worker.postMessage(module);
}
workers.push(worker);
}
}
main();
|