brute force kill/recreate worker for cancellation
This commit is contained in:
parent
26bf2baf5e
commit
c85bad54ca
4 changed files with 36 additions and 82 deletions
|
|
@ -257,15 +257,11 @@ var gs_kiri_slicer = exports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- synchronous slice -- can't be cancelled --
|
|
||||||
// create a Slice for each z offset in the zIndexes array
|
// create a Slice for each z offset in the zIndexes array
|
||||||
for (var i = 0; i < zIndexes.length; i++) {
|
for (var i = 0; i < zIndexes.length; i++) {
|
||||||
// slice next layer and add to slices[] array
|
// slice next layer and add to slices[] array
|
||||||
sliceZ(zIndexes[i], zHeights[i]);
|
sliceZ(zIndexes[i], zHeights[i]);
|
||||||
// kill slicing if onupdate() returns 42
|
onupdate(i / zIndexes.length);
|
||||||
if (onupdate(i / zIndexes.length) === 42) {
|
|
||||||
return ondone(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for cam, mark top and bottom as mandatory (hasFlats)
|
// for cam, mark top and bottom as mandatory (hasFlats)
|
||||||
|
|
@ -284,39 +280,6 @@ var gs_kiri_slicer = exports;
|
||||||
|
|
||||||
// pass Slices array back to ondone function
|
// pass Slices array back to ondone function
|
||||||
ondone(slices);
|
ondone(slices);
|
||||||
*/
|
|
||||||
|
|
||||||
var sliceIndex = 0;
|
|
||||||
|
|
||||||
function kickSlice() {
|
|
||||||
sliceZ(zIndexes[sliceIndex], zHeights[sliceIndex]);
|
|
||||||
// kill slicing if onupdate() returns 42
|
|
||||||
if (onupdate(sliceIndex / zIndexes.length) === 42) {
|
|
||||||
return ondone(null);
|
|
||||||
}
|
|
||||||
if (++sliceIndex < zIndexes.length) {
|
|
||||||
setTimeout(kickSlice, 0);
|
|
||||||
} else {
|
|
||||||
// for cam, mark top and bottom as mandatory (hasFlats)
|
|
||||||
if (options.cam && slices.length > 0) {
|
|
||||||
slices[0].hasFlats = true;
|
|
||||||
slices[slices.length-1].hasFlats = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// connect slices into linked list for island/bridge projections
|
|
||||||
for (i=1; i<slices.length; i++) {
|
|
||||||
slices[i-1].up = slices[i];
|
|
||||||
slices[i].down = slices[i-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
slices.slice_time = time() - timeStart;
|
|
||||||
|
|
||||||
// pass Slices array back to ondone function
|
|
||||||
ondone(slices);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
kickSlice();
|
|
||||||
|
|
||||||
/** ***** SLICING FUNCTIONS ***** */
|
/** ***** SLICING FUNCTIONS ***** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,6 @@ var gs_kiri_widget = exports;
|
||||||
progress: 0
|
progress: 0
|
||||||
};
|
};
|
||||||
this.saved = false;
|
this.saved = false;
|
||||||
// cancel slice/print ops
|
|
||||||
this.cancel = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ******************************************************************
|
/** ******************************************************************
|
||||||
|
|
@ -530,7 +528,6 @@ var gs_kiri_widget = exports;
|
||||||
startTime = UTIL.time();
|
startTime = UTIL.time();
|
||||||
|
|
||||||
widget.settings = settings;
|
widget.settings = settings;
|
||||||
widget.cancel = false;
|
|
||||||
|
|
||||||
onupdate(0.0001, "slicing");
|
onupdate(0.0001, "slicing");
|
||||||
|
|
||||||
|
|
@ -548,10 +545,9 @@ var gs_kiri_widget = exports;
|
||||||
if (reply.slices) { widget.clearSlices(); widget.slices = [] };
|
if (reply.slices) { widget.clearSlices(); widget.slices = [] };
|
||||||
if (reply.slice) widget.slices.push(KIRI.codec.decode(reply.slice, {mesh:widget.mesh}));
|
if (reply.slice) widget.slices.push(KIRI.codec.decode(reply.slice, {mesh:widget.mesh}));
|
||||||
if (reply.error) {
|
if (reply.error) {
|
||||||
widget.cancel = true;
|
|
||||||
ondone(false, reply.error);
|
ondone(false, reply.error);
|
||||||
}
|
}
|
||||||
if (reply.done && !widget.cancel) {
|
if (reply.done) {
|
||||||
widget.modified = false;
|
widget.modified = false;
|
||||||
ondone(true);
|
ondone(true);
|
||||||
}
|
}
|
||||||
|
|
@ -577,12 +573,6 @@ var gs_kiri_widget = exports;
|
||||||
|
|
||||||
var catchupdate = function(progress, message) {
|
var catchupdate = function(progress, message) {
|
||||||
onupdate(progress, message);
|
onupdate(progress, message);
|
||||||
if (widget.cancel) {
|
|
||||||
ondone("canceled");
|
|
||||||
return 42;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var driver = null;
|
var driver = null;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ if (self.window) {
|
||||||
BASE = self.base,
|
BASE = self.base,
|
||||||
seqid = 1,
|
seqid = 1,
|
||||||
running = {},
|
running = {},
|
||||||
worker = new Worker(pre + "/code/worker.js/" + exports.VERSION);
|
slicing = {},
|
||||||
|
worker = null;
|
||||||
|
|
||||||
// new moto.Ajax(function(body) {
|
// new moto.Ajax(function(body) {
|
||||||
// console.log({body:body});
|
// console.log({body:body});
|
||||||
|
|
@ -24,20 +25,6 @@ if (self.window) {
|
||||||
// worker = new Worker(URL.createObjectURL(blob));
|
// worker = new Worker(URL.createObjectURL(blob));
|
||||||
// }).request(pre + "/code/worker.js/");
|
// }).request(pre + "/code/worker.js/");
|
||||||
|
|
||||||
worker.onmessage = function(e) {
|
|
||||||
var now = time(),
|
|
||||||
reply = e.data,
|
|
||||||
record = running[reply.seq],
|
|
||||||
onreply = record.fn;
|
|
||||||
|
|
||||||
if (reply.done) delete running[reply.seq];
|
|
||||||
|
|
||||||
// calculate and replace recv time
|
|
||||||
reply.time_recv = now - reply.time_recv;
|
|
||||||
|
|
||||||
onreply(reply.data, reply);
|
|
||||||
};
|
|
||||||
|
|
||||||
function send(fn, data, onreply, async, zerocopy) {
|
function send(fn, data, onreply, async, zerocopy) {
|
||||||
var seq = seqid++;
|
var seq = seqid++;
|
||||||
|
|
||||||
|
|
@ -52,6 +39,32 @@ if (self.window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
KIRI.work = {
|
KIRI.work = {
|
||||||
|
restart : function() {
|
||||||
|
if (worker) worker.terminate();
|
||||||
|
|
||||||
|
for (var key in slicing) {
|
||||||
|
slicing[key]({error: "cancelled"});
|
||||||
|
}
|
||||||
|
slicing = {};
|
||||||
|
running = {};
|
||||||
|
|
||||||
|
worker = new Worker(pre + "/code/worker.js/" + exports.VERSION);
|
||||||
|
|
||||||
|
worker.onmessage = function(e) {
|
||||||
|
var now = time(),
|
||||||
|
reply = e.data,
|
||||||
|
record = running[reply.seq],
|
||||||
|
onreply = record.fn;
|
||||||
|
|
||||||
|
if (reply.done) delete running[reply.seq];
|
||||||
|
|
||||||
|
// calculate and replace recv time
|
||||||
|
reply.time_recv = now - reply.time_recv;
|
||||||
|
|
||||||
|
onreply(reply.data, reply);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
decimate : function(vertices, callback) {
|
decimate : function(vertices, callback) {
|
||||||
var vertices = vertices.buffer.slice(0);
|
var vertices = vertices.buffer.slice(0);
|
||||||
send("decimate", vertices, function(output) {
|
send("decimate", vertices, function(output) {
|
||||||
|
|
@ -65,18 +78,16 @@ if (self.window) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
cancel : function(widget) {
|
|
||||||
send("cancel", widget ? {id:widget.id} : {});
|
|
||||||
},
|
|
||||||
|
|
||||||
slice : function(settings, widget, callback) {
|
slice : function(settings, widget, callback) {
|
||||||
var vertices = widget.getGeoVertices().buffer.slice(0);
|
var vertices = widget.getGeoVertices().buffer.slice(0);
|
||||||
|
slicing[widget.id] = callback;
|
||||||
send("slice", {
|
send("slice", {
|
||||||
id: widget.id,
|
id: widget.id,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
vertices: vertices,
|
vertices: vertices,
|
||||||
position: widget.mesh.position
|
position: widget.mesh.position
|
||||||
}, function(reply) {
|
}, function(reply) {
|
||||||
|
if (reply.done || reply.error) delete slicing[widget.id];
|
||||||
callback(reply);
|
callback(reply);
|
||||||
}, null, [vertices]);
|
}, null, [vertices]);
|
||||||
},
|
},
|
||||||
|
|
@ -115,6 +126,9 @@ if (self.window) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// start first worker
|
||||||
|
KIRI.work.restart();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
module = { exports: {} };
|
module = { exports: {} };
|
||||||
|
|
@ -164,19 +178,6 @@ if (self.window) {
|
||||||
send.done(vertices);
|
send.done(vertices);
|
||||||
},
|
},
|
||||||
|
|
||||||
cancel: function(data) {
|
|
||||||
if (data.id) {
|
|
||||||
var widget = cache[data.id];
|
|
||||||
if (widget) widget.cancel = true;
|
|
||||||
} else {
|
|
||||||
for (var id in cache) {
|
|
||||||
if (cache.hasOwnProperty(id)) {
|
|
||||||
cache[id].cancel = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
slice: function(data, send) {
|
slice: function(data, send) {
|
||||||
var settings = data.settings,
|
var settings = data.settings,
|
||||||
vertices = new Float32Array(data.vertices),
|
vertices = new Float32Array(data.vertices),
|
||||||
|
|
|
||||||
|
|
@ -2551,7 +2551,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
// hide all dialogs
|
// hide all dialogs
|
||||||
hideDialog();
|
hideDialog();
|
||||||
// cancel slicing
|
// cancel slicing
|
||||||
KIRI.work.cancel();
|
KIRI.work.restart();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue