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

draft: cancel ok in synctam

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