-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
44 lines (32 loc) · 1.04 KB
/
Copy pathworker.js
File metadata and controls
44 lines (32 loc) · 1.04 KB
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
40
41
42
43
importScripts("./gomen.js");
function progress(piece_count, stage, board_idx, board_total) {
}
async function main() {
const response = await fetch("./legal-boards.leb128");
if (response.ok) {
legal_boards = new Uint8Array(await response.arrayBuffer());
} else {
console.log("couldn't load legal boards");
}
await wasm_bindgen("./gomen_bg.wasm");
const solver = new wasm_bindgen.Solver(legal_boards);
postMessage({ type: 'ready' });
// Set up message handler for solve requests
onmessage = (message) => {
const data = message.data;
if (data.type === 'solve') {
const queue = new wasm_bindgen.Queue();
for (const piece of data.queue) {
queue.add_shape(piece);
}
const garbage = BigInt(data.garbage);
const solutions = solver.solve(queue, garbage, data.hold, data.physics);
const solutionArray = solutions === "" ? [] : solutions.split(",");
postMessage({
type: 'solutions',
solutions: solutionArray
});
}
};
}
main();