fix fdm threading
This commit is contained in:
parent
8f8b631d63
commit
27da69c1db
3 changed files with 31 additions and 35 deletions
|
|
@ -131,7 +131,7 @@ const funcs = self.minion = {
|
||||||
},
|
},
|
||||||
|
|
||||||
sliceZ(data, seq) {
|
sliceZ(data, seq) {
|
||||||
log('minion.sliceZ', { data, seq });
|
debug('minion.sliceZ', { data, seq });
|
||||||
let { z, points, options } = data;
|
let { z, points, options } = data;
|
||||||
let i = 0, p = 0, realp = new Array(points.length / 3);
|
let i = 0, p = 0, realp = new Array(points.length / 3);
|
||||||
while (i < points.length) {
|
while (i < points.length) {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ let drivers = {
|
||||||
WJET
|
WJET
|
||||||
},
|
},
|
||||||
ccvalue = self.navigator ? self.navigator.hardwareConcurrency || 0 : 0,
|
ccvalue = self.navigator ? self.navigator.hardwareConcurrency || 0 : 0,
|
||||||
concurrent = 1,//Math.min(4, self.Worker && ccvalue > 3 ? ccvalue - 1 : 0),
|
concurrent = Math.min(4, self.Worker && ccvalue > 3 ? ccvalue - 1 : 0),
|
||||||
current = {
|
current = {
|
||||||
print: null,
|
print: null,
|
||||||
snap: null,
|
snap: null,
|
||||||
|
|
@ -192,11 +192,10 @@ const minwork = {
|
||||||
},
|
},
|
||||||
|
|
||||||
sliceZ(z, points, options) {
|
sliceZ(z, points, options) {
|
||||||
debug('minwork.sliceZ', { z, points, options });
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// if (concurrent < 2) {
|
if (concurrent < 2) {
|
||||||
// reject("concurrent slice unavaiable");
|
reject("concurrent slice unavaiable");
|
||||||
// }
|
}
|
||||||
let { each } = options;
|
let { each } = options;
|
||||||
// todo use shared array buffer?
|
// todo use shared array buffer?
|
||||||
let i = 0, floatP = new Float32Array(points.length * 3);
|
let i = 0, floatP = new Float32Array(points.length * 3);
|
||||||
|
|
@ -205,57 +204,54 @@ const minwork = {
|
||||||
floatP[i++] = p.y;
|
floatP[i++] = p.y;
|
||||||
floatP[i++] = p.z;
|
floatP[i++] = p.z;
|
||||||
}
|
}
|
||||||
const state = { zeros: [ floatP.buffer ] };
|
|
||||||
minwork.queue({
|
minwork.queue({
|
||||||
cmd: "sliceZ",
|
cmd: "sliceZ",
|
||||||
z,
|
z,
|
||||||
points: floatP,
|
points: floatP,
|
||||||
options
|
options: codec.toCodable(options)
|
||||||
}, data => {
|
}, data => {
|
||||||
console.log({ data });
|
let recs = codec.decode(data.output);
|
||||||
for (let rec of data.output) {
|
if (each) {
|
||||||
|
for (let rec of recs) {
|
||||||
each(rec);
|
each(rec);
|
||||||
}
|
}
|
||||||
resolve();
|
}
|
||||||
}, state.zeros);
|
resolve(recs);
|
||||||
|
}, [ floatP.buffer ]);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
queue(work, ondone, direct) {
|
queue(work, ondone, direct) {
|
||||||
debug('WORKER.queue', { work, direct });
|
minionq.push({work, ondone, direct});
|
||||||
// if (direct) {
|
|
||||||
// return ondone(work);
|
|
||||||
// }
|
|
||||||
let seq = ++miniseq;
|
|
||||||
minifns[seq] = ondone;
|
|
||||||
minionq.push({ seq, work, direct });
|
|
||||||
minwork.kick();
|
minwork.kick();
|
||||||
},
|
},
|
||||||
|
|
||||||
queueAsync(work, direct) {
|
queueAsync(work, direct) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(resolve => {
|
||||||
minwork.queue(work, resolve, direct);
|
minwork.queue(work, resolve, direct);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
kick() {
|
kick() {
|
||||||
if (minionq.length === 0 || minions.length === 0) {
|
if (minions.length && minionq.length) {
|
||||||
return;
|
let qrec = minionq.shift();
|
||||||
}
|
|
||||||
let minion = minions.shift();
|
let minion = minions.shift();
|
||||||
let { seq, work, direct } = minionq.shift();
|
let seq = miniseq++;
|
||||||
work.seq = seq;
|
qrec.work.seq = seq;
|
||||||
debug('WORKER.send', { work, direct });
|
minifns[seq] = (data) => {
|
||||||
minion.postMessage(work, direct);
|
qrec.ondone(data);
|
||||||
minions.push(minion);
|
minions.push(minion);
|
||||||
|
minwork.kick();
|
||||||
|
};
|
||||||
|
minion.postMessage(qrec.work, qrec.direct);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
broadcast(cmd, data, direct) {
|
broadcast(cmd, data, direct) {
|
||||||
if (direct) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (let minion of minions) {
|
for (let minion of minions) {
|
||||||
minion.postMessage({ cmd, data });
|
minion.postMessage({
|
||||||
|
cmd, ...data
|
||||||
|
}, direct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
|
|
||||||
import { base } from '../geo/base.js';
|
|
||||||
import { Layers } from './layers.js';
|
import { Layers } from './layers.js';
|
||||||
|
import { newPoint } from '../geo/point.js';
|
||||||
import { polygons as POLY } from '../geo/polygons.js';
|
import { polygons as POLY } from '../geo/polygons.js';
|
||||||
|
|
||||||
let tracker;
|
let tracker;
|
||||||
|
|
@ -144,7 +144,7 @@ class Slice {
|
||||||
} else {
|
} else {
|
||||||
// create top object from object bundle passed back by slicePost()
|
// create top object from object bundle passed back by slicePost()
|
||||||
let top = new Top(data.poly);
|
let top = new Top(data.poly);
|
||||||
top.thin_fill = data.thin_fill ? data.thin_fill.map(p => base.newPoint(p.x,p.y,p.z)) : undefined;
|
top.thin_fill = data.thin_fill ? data.thin_fill.map(p => newPoint(p.x,p.y,p.z)) : undefined;
|
||||||
top.fill_lines = data.fill_lines;
|
top.fill_lines = data.fill_lines;
|
||||||
top.fill_sparse = data.fill_sparse;
|
top.fill_sparse = data.fill_sparse;
|
||||||
top.fill_off = data.fill_off;
|
top.fill_off = data.fill_off;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue