namespace cleanup for workers
This commit is contained in:
parent
d148fe6ae7
commit
4cae0b945a
4 changed files with 35 additions and 23 deletions
|
|
@ -8,12 +8,17 @@
|
|||
|
||||
const BASE = self.base, KIRI = self.kiri, handlers = {};
|
||||
|
||||
KIRI.codec = {
|
||||
const codec = KIRI.codec = {
|
||||
encode: encode,
|
||||
decode: decode,
|
||||
registerDecoder: registerDecoder
|
||||
registerDecoder: registerDecoder,
|
||||
allocFloat32Array: allocFloat32Array
|
||||
};
|
||||
|
||||
function allocFloat32Array(len) {
|
||||
return new Float32Array(len);
|
||||
}
|
||||
|
||||
function encode(o, state) {
|
||||
state = state || {};
|
||||
if (o === null) return null;
|
||||
|
|
@ -140,7 +145,7 @@
|
|||
function encodePointArray(points, state) {
|
||||
if (!points) return null;
|
||||
|
||||
let array = new Float32Array(points.length * 3),
|
||||
let array = codec.allocFloat32Array(points.length * 3),
|
||||
pos = 0;
|
||||
|
||||
points.forEach(function(point) {
|
||||
|
|
|
|||
|
|
@ -858,7 +858,7 @@
|
|||
// find new endpoints that are not shared point
|
||||
let p1 = l1.p1 != point ? l1.p1 : l1.p2,
|
||||
p2 = l2.p1 != point ? l2.p1 : l2.p2,
|
||||
newline = base.newOrderedLine(p1,p2);
|
||||
newline = BASE.newOrderedLine(p1,p2);
|
||||
// remove deleted lines from associated points
|
||||
p1.group.remove(l1);
|
||||
p1.group.remove(l2);
|
||||
|
|
|
|||
|
|
@ -2,16 +2,20 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
// (function() {
|
||||
|
||||
const base = self.base,
|
||||
util = base.util,
|
||||
time = util.time,
|
||||
kiri = self.kiri,
|
||||
ver = kiri.version,
|
||||
Widget = kiri.Widget;
|
||||
Widget = kiri.Widget,
|
||||
current = self.worker = {
|
||||
print: null,
|
||||
snap: null
|
||||
};
|
||||
|
||||
let currentPrint,
|
||||
currentSnap,
|
||||
cache = {};
|
||||
let cache = {};
|
||||
|
||||
console.log(`kiri | init work | ${ver}`);
|
||||
base.debug.disable();
|
||||
|
|
@ -29,7 +33,7 @@ let dispatch = {
|
|||
},
|
||||
|
||||
snap: function(data, send) {
|
||||
currentSnap = data;
|
||||
current.snap = data;
|
||||
send.done();
|
||||
},
|
||||
|
||||
|
|
@ -109,8 +113,8 @@ let dispatch = {
|
|||
|
||||
send.data({update:0.05, updateStatus:"preview"});
|
||||
|
||||
currentPrint = kiri.newPrint(data.settings, widgets, data.id);
|
||||
currentPrint.setup(false, function(update, msg) {
|
||||
current.print = kiri.newPrint(data.settings, widgets, data.id);
|
||||
current.print.setup(false, function(update, msg) {
|
||||
send.data({
|
||||
update: update,
|
||||
updateStatus: msg
|
||||
|
|
@ -118,13 +122,13 @@ let dispatch = {
|
|||
}, function() {
|
||||
send.done({
|
||||
done: true,
|
||||
output: currentPrint.encodeOutput()
|
||||
output: current.print.encodeOutput()
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
printExport: function(data, send) {
|
||||
currentPrint.export(false, function(line, direct) {
|
||||
current.print.export(false, function(line, direct) {
|
||||
send.data({line}, direct);
|
||||
}, function(done, direct) {
|
||||
send.done({done}, direct);
|
||||
|
|
@ -132,14 +136,14 @@ let dispatch = {
|
|||
},
|
||||
|
||||
printGCode: function(data, send) {
|
||||
currentPrint.exportGCode(false, function(gcode) {
|
||||
current.print.exportGCode(false, function(gcode) {
|
||||
send.done({
|
||||
gcode: gcode,
|
||||
lines: currentPrint.lines,
|
||||
bytes: currentPrint.bytes,
|
||||
bounds: currentPrint.bounds,
|
||||
distance: currentPrint.distance,
|
||||
time: currentPrint.time
|
||||
lines: current.print.lines,
|
||||
bytes: current.print.bytes,
|
||||
bounds: current.print.bounds,
|
||||
distance: current.print.distance,
|
||||
time: current.print.time
|
||||
});
|
||||
}, function(line) {
|
||||
send.data({line:line});
|
||||
|
|
@ -147,8 +151,8 @@ let dispatch = {
|
|||
},
|
||||
|
||||
clear: function(data, send) {
|
||||
currentSnap = null;
|
||||
currentPrint = null;
|
||||
current.snap = null;
|
||||
current.print = null;
|
||||
if (!data.id) {
|
||||
cache = {};
|
||||
send.done({ clear: true });
|
||||
|
|
@ -206,3 +210,5 @@ self.onmessage = function(e) {
|
|||
console.log({kiri_msg:e});
|
||||
}
|
||||
};
|
||||
|
||||
// })();
|
||||
|
|
|
|||
|
|
@ -78,9 +78,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
let b64 = atob(currentSnap);
|
||||
let b64 = atob(self.worker.snap);
|
||||
let bin = Uint8Array.from(b64, c => c.charCodeAt(0));
|
||||
let img = new png.PNG().parse(bin, (err, data) => {
|
||||
let img = new png.PNG();
|
||||
img.parse(bin, (err, data) => {
|
||||
preview = img;
|
||||
previewSmall = samplePNG(img, 200, 125);
|
||||
previewLarge = samplePNG(img, 400, 300);
|
||||
|
|
|
|||
Loading…
Reference in a new issue