Skip to content

Commit

Permalink
Debugging code for #3040
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Oct 26, 2016
1 parent b9d9509 commit b5bfb3b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions debug/workers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
var src = [
"self.addEventListener('message', function () {",
" console.log('received message from main');",
" self.postMessage({});",
"});"
].join("\n");
var blob = new Blob([src], { type: 'text/javascript' })
var workerURL = URL.createObjectURL(blob);
var worker = new Worker(workerURL);
worker.addEventListener('message', function () {
console.log('received message from worker');
});
worker.postMessage({});
</script>
9 changes: 9 additions & 0 deletions js/source/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const assert = require('assert');
*/
class Worker {
constructor(self) {
console.log('worker created', self);

this.self = self;
this.actor = new Actor(self, this);

Expand All @@ -34,34 +36,41 @@ class Worker {
}

setLayers(mapId, layerDefinitions) {
console.log('worker setLayers');
this.getLayerIndex(mapId).replace(layerDefinitions);
}

updateLayers(mapId, layerDefinitions) {
console.log('worker updateLayers');
this.getLayerIndex(mapId).update(layerDefinitions);
}

loadTile(mapId, params, callback) {
console.log('worker loadTile');
assert(params.type);
this.getWorkerSource(mapId, params.type).loadTile(params, callback);
}

reloadTile(mapId, params, callback) {
console.log('worker reloadTile');
assert(params.type);
this.getWorkerSource(mapId, params.type).reloadTile(params, callback);
}

abortTile(mapId, params) {
console.log('worker abortTile');
assert(params.type);
this.getWorkerSource(mapId, params.type).abortTile(params);
}

removeTile(mapId, params) {
console.log('worker removeTile');
assert(params.type);
this.getWorkerSource(mapId, params.type).removeTile(params);
}

redoPlacement(mapId, params, callback) {
console.log('worker redoPlacement');
assert(params.type);
this.getWorkerSource(mapId, params.type).redoPlacement(params, callback);
}
Expand Down
4 changes: 4 additions & 0 deletions js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class WorkerTile {
this.status = 'parsing';
this.data = data;

console.log(`parse ${this.coord.z}/${this.coord.x}/${this.coord.y}`);

this.collisionBoxArray = new CollisionBoxArray();
this.symbolInstancesArray = new SymbolInstancesArray();
this.symbolQuadsArray = new SymbolQuadsArray();
Expand Down Expand Up @@ -99,6 +101,8 @@ class WorkerTile {
}

const done = () => {
console.log(`done ${this.coord.z}/${this.coord.x}/${this.coord.y}`);

this.status = 'done';

if (this.redoPlacementAfterDone) {
Expand Down
3 changes: 3 additions & 0 deletions js/util/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Actor {
this.callbacks = {};
this.callbackID = 0;
this.receive = this.receive.bind(this);
console.log('addEventListener', this.target);
this.target.addEventListener('message', this.receive, false);
}

Expand All @@ -36,6 +37,7 @@ class Actor {
send(type, data, callback, buffers, targetMapId) {
const id = callback ? `${this.mapId}:${this.callbackID++}` : null;
if (callback) this.callbacks[id] = callback;
console.log('postMessage', type);
this.target.postMessage({
targetMapId: targetMapId,
sourceMapId: this.mapId,
Expand All @@ -46,6 +48,7 @@ class Actor {
}

receive(message) {
console.log('receive', message.data.type);
const data = message.data,
id = data.id;
let callback;
Expand Down

0 comments on commit b5bfb3b

Please sign in to comment.