checkpoint prototype
This commit is contained in:
parent
2f755459ff
commit
849a55439b
12 changed files with 169 additions and 50 deletions
|
|
@ -3,6 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
// dep: moto.license
|
||||
// dep: moto.broker
|
||||
// dep: geo.base
|
||||
// dep: geo.polygons
|
||||
// dep: geo.slicer
|
||||
|
|
@ -10,6 +11,7 @@
|
|||
// dep: kiri.codec
|
||||
// dep: kiri-mode.fdm.post
|
||||
// use: kiri-mode.cam.slicer
|
||||
// dep: kiri-mode.cam.slicer2
|
||||
// dep: ext.clip2
|
||||
gapp.register("kiri-run.minion", [], (root, exports) => {
|
||||
|
||||
|
|
@ -22,8 +24,8 @@ const clib = self.ClipperLib;
|
|||
const ctyp = clib.ClipType;
|
||||
const ptyp = clib.PolyType;
|
||||
const cfil = clib.PolyFillType;
|
||||
const cache = self.cache = {};
|
||||
|
||||
let cache = self.cache = {};
|
||||
let name = "unknown";
|
||||
|
||||
// catch clipper alerts and convert to console messages
|
||||
|
|
@ -45,7 +47,7 @@ function log() {
|
|||
console.log(`[${name}]`, ...arguments);
|
||||
}
|
||||
|
||||
const funcs = {
|
||||
const funcs = self.minion = {
|
||||
label(data, seq) {
|
||||
name = data.name;
|
||||
},
|
||||
|
|
@ -138,19 +140,20 @@ const funcs = {
|
|||
});
|
||||
},
|
||||
|
||||
camSetPoints: data => {
|
||||
const points = new Float32Array(data.data);
|
||||
let i = 0, p = 0, realp = new Array(points.length / 3);
|
||||
while (i < points.length) {
|
||||
realp[p++] = base.newPoint(points[i++], points[i++], points[i++]).round(3);
|
||||
putCache: msg => {
|
||||
const { key, data } = msg;
|
||||
log({ minion_putCache: key, data });
|
||||
if (data) {
|
||||
console.log({ minion_put_cache: key, data });
|
||||
cache[key] = data;
|
||||
} else {
|
||||
console.log({ minion_del_cache: key });
|
||||
delete cache[key];
|
||||
}
|
||||
// log({ camSetPoints: points, realp });
|
||||
cache.camPoints = realp;
|
||||
},
|
||||
|
||||
camClearPoints: data => {
|
||||
// log({ camClearPoints: data });
|
||||
delete cache.camPoints;
|
||||
clearCache: msg => {
|
||||
cache = self.cache = [];
|
||||
},
|
||||
|
||||
wasm: data => {
|
||||
|
|
@ -166,4 +169,6 @@ const funcs = {
|
|||
}
|
||||
};
|
||||
|
||||
moto.broker.publish("minion.started", funcs);
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
// dep: kiri.codec
|
||||
// dep: kiri.slice
|
||||
// dep: moto.license
|
||||
// dep: moto.broker
|
||||
// use: load.png
|
||||
// use: ext.jszip
|
||||
// use: kiri.render
|
||||
|
|
@ -230,19 +231,10 @@ kiri.minions = {
|
|||
}
|
||||
},
|
||||
|
||||
wasm(enable) {
|
||||
for (let minion of minions) {
|
||||
minion.postMessage({
|
||||
cmd: "wasm",
|
||||
enable
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
broadcast(cmd, data, direct) {
|
||||
for (let minion of minions) {
|
||||
minion.postMessage({
|
||||
cmd, data
|
||||
cmd, ...data
|
||||
}, direct);
|
||||
}
|
||||
}
|
||||
|
|
@ -252,6 +244,7 @@ console.log(`kiri | init work | ${gapp.version || "rogue"}`);
|
|||
|
||||
// code is running in the worker / server context
|
||||
const dispatch =
|
||||
self.worker =
|
||||
kiri.server =
|
||||
kiri.worker = {
|
||||
pool_start(data, send) {
|
||||
|
|
@ -326,8 +319,11 @@ kiri.worker = {
|
|||
group.id = data.group;
|
||||
wgroup[data.group] = group;
|
||||
}
|
||||
let vertices = new Float32Array(data.vertices),
|
||||
widget = kiri.newWidget(data.id, group).loadVertices(vertices).setInWorker();
|
||||
|
||||
let vertices = data.vertices,
|
||||
widget = kiri.newWidget(data.id, group)
|
||||
.setInWorker()
|
||||
.loadVertices(vertices);
|
||||
|
||||
// do it here so cancel can work
|
||||
wcache[data.id] = widget;
|
||||
|
|
@ -623,8 +619,26 @@ kiri.worker = {
|
|||
} else {
|
||||
wasm_ctrl.disable();
|
||||
}
|
||||
minwork.wasm(data.enable);
|
||||
minwork.broadcast("wasm", { enable: data.enable ? true : false });
|
||||
send.done({ wasm: data });
|
||||
},
|
||||
|
||||
putCache(msg, send) {
|
||||
const { key, data } = msg;
|
||||
console.log({ worker_putCache: key, data });
|
||||
if (data) {
|
||||
pcache[key] = data;
|
||||
} else {
|
||||
delete pcache[key];
|
||||
}
|
||||
minwork.broadcast("putCache", msg);
|
||||
send.done({ ok: true });
|
||||
},
|
||||
|
||||
clearCache(msg, send) {
|
||||
pcache = {};
|
||||
minwork.broadcast("clearCache", msg);
|
||||
send.done({ ok: true });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -686,6 +700,8 @@ dispatch.onmessage = self.onmessage = function(e) {
|
|||
}
|
||||
};
|
||||
|
||||
moto.broker.publish("worker.started", { dispatch, minions: minwork });
|
||||
|
||||
});
|
||||
|
||||
// load kiri modules
|
||||
|
|
|
|||
Loading…
Reference in a new issue