Commit 14a76a22 authored by Florent Becker's avatar Florent Becker

draft: cancel ok in synctam

parent b1b0721b
...@@ -222,10 +222,15 @@ export class Simulator { ...@@ -222,10 +222,15 @@ export class Simulator {
} }
handleWorkerMessage(e) { handleWorkerMessage(e) {
if (e.data.msg === "tile-added") { Logger.log(Logger.INFO, "got message" + e.data.msg);
const type = this.tileset.getTileTypeById(e.data.tid); if (e.data.msg === "tile-group-added") {
const coords = new Vector2D(e.data.x, e.data.y); let attachments = [];
this.tileBlockAtlas.add_one(type, coords); for (let attachment of e.data.tiles) {
const type = this.tileset.getTileTypeById(attachment.tid);
const coords = new Vector2D(attachment.x, attachment.y);
attachments.push({type: type, coords: coords});
}
this.tileBlockAtlas.add_many(attachments);
this.renderUpdate = true; this.renderUpdate = true;
} else if (e.data.msg === "tiles-added") { } else if (e.data.msg === "tiles-added") {
const fastForwardBuffer = e.data.buffer; const fastForwardBuffer = e.data.buffer;
...@@ -295,12 +300,13 @@ export class Simulator { ...@@ -295,12 +300,13 @@ export class Simulator {
} else { } else {
Logger.log(Logger.INFO, `no glues currently have blockers`); Logger.log(Logger.INFO, `no glues currently have blockers`);
} }
} else {
Logger.log(Logger.WARNING, `unknown message from worker: ${e.data.msg}`);
} }
} }
stepForward() { stepForward() {
let speed = this.ffSpeedInput.value; let speed = this.ffSpeedInput.value;
console.log(speed);
this.tileWorker.postMessage({ msg: "step-forward", repeat: speed }); this.tileWorker.postMessage({ msg: "step-forward", repeat: speed });
} }
...@@ -508,17 +514,13 @@ export class Simulator { ...@@ -508,17 +514,13 @@ export class Simulator {
temp = parseInt(line.split("=")[1].trim()); temp = parseInt(line.split("=")[1].trim());
} else if (line.length > 0) { } else if (line.length > 0) {
const data = line.split(" "); const data = line.split(" ");
if (data.length >= 3) { if (data.length >= 3 && data[0] != "#" ) {
const name = data[0].trim(); const name = data[0].trim();
const x = parseInt(data[1].trim()); const x = parseInt(data[1].trim());
const y = parseInt(data[2].trim()); const y = parseInt(data[2].trim());
const type = this.tileset.getTileTypeByName(name); const type = this.tileset.getTileTypeByName(name);
const coords = new Vector2D(x, y); const coords = new Vector2D(x, y);
// this.addTile(type, coords);
// this.tileWorker.postMessage({ msg: 'add-tile', tid: type.id, x: coords.x, y: coords.y});
this.tileBlockAtlas.add(type, coords);
this.seedTiles.push({type: type, coords: coords}); this.seedTiles.push({type: type, coords: coords});
} }
} }
...@@ -530,7 +532,9 @@ export class Simulator { ...@@ -530,7 +532,9 @@ export class Simulator {
this.tileWorker.postMessage({ msg: 'mode-SyncTAM' }); this.tileWorker.postMessage({ msg: 'mode-SyncTAM' });
} }
this.tileBlockAtlas.add_many(this.seedTiles);
console.log(this.seedTiles.length); console.log(this.seedTiles.length);
if (this.seedTiles.length == 0) { if (this.seedTiles.length == 0) {
let ttypes = this.tileset.tileTypes; let ttypes = this.tileset.tileTypes;
let tile = ttypes[Math.floor(Math.random()*ttypes.length)]; let tile = ttypes[Math.floor(Math.random()*ttypes.length)];
......
...@@ -59,22 +59,18 @@ onmessage = function(e) { ...@@ -59,22 +59,18 @@ onmessage = function(e) {
precomputeSignatures(); precomputeSignatures();
} }
} else if (e.data.msg === "step-forward") { } else if (e.data.msg === "step-forward") {
let n_tiles = e.data.repeat || 1; let n_steps = e.data.repeat || 1;
for (i = 0; i < n_tiles; i++) { for (i = 0; i < n_steps; i++) {
const added_list = stepForward(); const added_list = stepForward();
if (added_list === null) { if (added_list === []) {
postMessage({ msg: "frontier-empty" }); postMessage({ msg: "frontier-empty" });
} else { } else {
for (let i=0; i<added_list.length; i++) {
postMessage({ postMessage({
msg: "tile-added", msg: "tile-group-added",
tid: added_list[i][0], tiles: added_list
x: added_list[i][1],
y: added_list[i][2]
}); });
} }
} }
}
} else if (e.data.msg === "step-backward") { } else if (e.data.msg === "step-backward") {
const removed = stepBackward(); const removed = stepBackward();
if (removed !== null) { if (removed !== null) {
...@@ -587,11 +583,8 @@ function removeTile(x, y) { ...@@ -587,11 +583,8 @@ function removeTile(x, y) {
} }
} }
function stepForward(recursion_level = 0) { function blockTam_stepForward(recursion_level) {
const ret_list = Array(); const ret_list = Array();
if ((simulation_mode === 'aTAM') || (simulation_mode === 'BlockTAM')) {
let tid; let tid;
let loc; let loc;
...@@ -602,7 +595,7 @@ function stepForward(recursion_level = 0) { ...@@ -602,7 +595,7 @@ function stepForward(recursion_level = 0) {
if (setBlockTAMtemperature() === true) { if (setBlockTAMtemperature() === true) {
if (recursion_level < temperatureList.length) { if (recursion_level < temperatureList.length) {
recursion_level += 1; recursion_level += 1;
return stepForward(recursion_level); return blockTame_stepForward(recursion_level);
} }
} }
} }
...@@ -624,24 +617,14 @@ function stepForward(recursion_level = 0) { ...@@ -624,24 +617,14 @@ function stepForward(recursion_level = 0) {
} }
addTile(tid, loc[0], loc[1]); addTile(tid, loc[0], loc[1]);
history.push([{tid: tid, x: loc[0], y: loc[1]}]); let attachment = {tid: tid, x: loc[0], y: loc[1]};
ret_list.push([tid, loc[0], loc[1]]); history.push([attachment]);
ret_list.push([attachment]);
} else {
const frontierList = Array.from(frontierMap.keys());
var history_step = [];
for (let i=0; i<frontierList.length; i++) {
let tid;
let loc;
while (tid === undefined) { return ret_list;
if (i === frontierList.length) { }
break; // no more tiles can be added
}
const key = frontierList[i];
loc = frontierMap.get(key);
function attachmentAt(key, b_add_to_frontier) {
const sig = signatureMap.get(key); const sig = signatureMap.get(key);
const fitting = getFittingTileTypes(sig); const fitting = getFittingTileTypes(sig);
if ((fitting.length > 1) && (b_report_nondeterminism === true)) { if ((fitting.length > 1) && (b_report_nondeterminism === true)) {
...@@ -652,27 +635,60 @@ function stepForward(recursion_level = 0) { ...@@ -652,27 +635,60 @@ function stepForward(recursion_level = 0) {
postMessage({ msg: 'nondeterminism', loc: loc, types: type_list}); postMessage({ msg: 'nondeterminism', loc: loc, types: type_list});
} }
tid = fitting[Math.floor(Math.random() * fitting.length)];
const tid = fitting[Math.floor(Math.random() * fitting.length)];
const loc = frontierMap.get(key);
if (tid === undefined) { if (tid === undefined) {
postMessage({ msg: 'tid-undefined'}); postMessage({msg: 'tid-undefined'});
i++; frontierMap.delete(key);
} return null;
} }
if (tid !== undefined) {
addTile(tid, loc[0], loc[1], false); addTile(tid, loc[0], loc[1], b_add_to_frontier=b_add_to_frontier);
history_step.push({tid: tid, x: loc[0], y: loc[1]}); return {tid: tid, x: loc[0], y: loc[1]};
ret_list.push([tid, loc[0], loc[1]]); }
function stepForward() {
if (simulation_mode === 'blockTAM') {
return blockTAM_stepForward(0);
} }
if (simulation_mode === 'aTAM') {
let attachment = null;
while (attachment === null) {
if (frontierMap.size === 0) {
return [];
} }
history.push(history_step); const frontierList = Array.from(frontierMap.keys());
for (let r = 0; r < ret_list.length; r++) {
addNbrsToFrontier(ret_list[r][0], ret_list[r][1], ret_list[r][2]); const key = frontierList[Math.floor(Math.random() * frontierList.length)];
attachment = attachmentAt(key, true);
} }
history.push([attachment]);
return [attachment];
} }
// console.log('tile added', history, seedSize); if (simulation_mode === 'SyncTAM') {
const frontierList = Array.from(frontierMap.keys());
let attachments = [];
return ret_list; for (let key of frontierList) {
let attachment = attachmentAt(key, false);
if (attachment !== null) {
attachments.push(attachment);
}
}
if (attachments.length > 0)
history.push(attachments);
for (let a of attachments) {
addNbrsToFrontier(a.tid, a.x, a.y)
}
return attachments;
}
} }
function stepBackward() { function stepBackward() {
......
...@@ -52,11 +52,13 @@ onmessage = function(e) { ...@@ -52,11 +52,13 @@ onmessage = function(e) {
} else { } else {
for (let i=0; i<added_list.length; i++) { for (let i=0; i<added_list.length; i++) {
postMessage({ postMessage({
msg: "tile-added", msg: "tile-group-added",
tiles: [{
tid: added_list[i][0], tid: added_list[i][0],
x: added_list[i][1], x: added_list[i][1],
y: added_list[i][2], y: added_list[i][2],
z: added_list[i][3] z: added_list[i][3]
}]
}); });
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment