t
This commit is contained in:
parent
0990b98436
commit
1a3ba56d9a
123 changed files with 16018 additions and 9153 deletions
24
src/mapPatchWorker.js
Normal file
24
src/mapPatchWorker.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { generatePatch } from "./mapPatch.js";
|
||||
import { collectTransferableBuffers } from "./transferUtils.js";
|
||||
|
||||
self.onmessage = (event) => {
|
||||
const { id, world, rect, options } = event.data || {};
|
||||
try {
|
||||
const result = generatePatch(world, rect, {
|
||||
...(options || {}),
|
||||
// The worker owns this preview clone. If a multi-tile attempt fails the
|
||||
// main thread discards the entire worker world, so a second full-size field
|
||||
// snapshot is unnecessary and would recreate the large-patch memory spike.
|
||||
_workerOwnedPreview: true,
|
||||
onProgress: (progress) => self.postMessage({ id, type: "progress", progress }),
|
||||
});
|
||||
// The main thread owns the pre-patch world while preview generation runs.
|
||||
// Return the worker-owned preview by transferring its buffers instead of
|
||||
// cloning the complete padded world a second time.
|
||||
const payload = { id, ok: true, world, result };
|
||||
const transfer = Array.from(collectTransferableBuffers(payload));
|
||||
self.postMessage(payload, transfer);
|
||||
} catch (error) {
|
||||
self.postMessage({ id, ok: false, error: error?.message || String(error), stack: error?.stack || "" });
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue