Commit b1b0721b authored by Florent Becker's avatar Florent Becker

draft: improved tracking of simulation time

parent a33cf7d9
...@@ -312,12 +312,13 @@ ...@@ -312,12 +312,13 @@
<div class="w3-bar-item bar-divider"></div> <div class="w3-bar-item bar-divider"></div>
<button id="select-mode-button" class="w3-bar-item w3-button"><span class="material-icons">highlight_alt</span></button> <button id="select-mode-button" class="w3-bar-item w3-button"><span class="material-icons">highlight_alt</span></button>
<button id="place-mode-button" class="w3-bar-item w3-button"><span class="material-icons">edit</span></button> <button id="place-mode-button" class="w3-bar-item w3-button"><span class="material-icons">edit</span></button>
<button id="zoom-out-button" class="w3-bar-item w3-button w3-right"><span class="material-icons">zoom_out</span></button> <button id="zoom-out-button" class="w3-bar-item w3-button w3-right"><span class="material-icons">zoom_out</span></button>
<button id="zoom-in-button" class="w3-bar-item w3-button w3-right"><span class="material-icons">zoom_in</span></button> <button id="zoom-in-button" class="w3-bar-item w3-button w3-right"><span class="material-icons">zoom_in</span></button>
</div> </div>
<div id="simulator"> <div id="simulator">
<canvas id="sim-canvas"></canvas> <canvas id="sim-canvas"></canvas>
<svg id="sim-canvas" width="100%" height="100%"></svg> <svg id="sim-canvas" width="100%" height="100%"></svg>
</div> </div>
<div id="sim-info" class="w3-small w3-light-grey">Simulator</div> <div id="sim-info" class="w3-small w3-light-grey">Simulator</div>
</div> </div>
......
...@@ -120,12 +120,13 @@ export class Simulator { ...@@ -120,12 +120,13 @@ export class Simulator {
if (keepSeed) { if (keepSeed) {
this.tileWorker.postMessage({ msg: 'set-seed', seed: this.seedTiles}); this.tileWorker.postMessage({ msg: 'set-seed', seed: this.seedTiles});
this.tileBlockAtlas.add_many(this.seedTiles);
for (const tile of this.seedTiles) { // for (const tile of this.seedTiles) {
// this.addTile(tile.type, tile.coords); // // this.addTile(tile.type, tile.coords);
// this.tileWorker.postMessage({ msg: 'add-tile', tid: tile.type.id, x: tile.coords.x, y: tile.coords.y}); // // this.tileWorker.postMessage({ msg: 'add-tile', tid: tile.type.id, x: tile.coords.x, y: tile.coords.y});
this.tileBlockAtlas.add(tile.type, tile.coords); // this.tileBlockAtlas.add(tile.type, tile.coords);
} // }
Logger.log(Logger.INFO, "reset system to seed"); Logger.log(Logger.INFO, "reset system to seed");
...@@ -224,7 +225,7 @@ export class Simulator { ...@@ -224,7 +225,7 @@ export class Simulator {
if (e.data.msg === "tile-added") { if (e.data.msg === "tile-added") {
const type = this.tileset.getTileTypeById(e.data.tid); const type = this.tileset.getTileTypeById(e.data.tid);
const coords = new Vector2D(e.data.x, e.data.y); const coords = new Vector2D(e.data.x, e.data.y);
this.tileBlockAtlas.add(type, coords); this.tileBlockAtlas.add_one(type, coords);
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;
...@@ -382,8 +383,9 @@ export class Simulator { ...@@ -382,8 +383,9 @@ export class Simulator {
this.renderer.render(this.scene, this.camera); this.renderer.render(this.scene, this.camera);
} }
this.selectedTile.render(); this.selectedTile.render();
let infoStr = `Simulator: ${this.tileBlockAtlas.numTiles} tiles`; let time = this.tileBlockAtlas.history.length;
let infoStr = `Simulator: ${this.tileBlockAtlas.numTiles} tiles, Simulation time: ${time}`;
if (this.mouseoverQuad.visible) { if (this.mouseoverQuad.visible) {
infoStr += ` --- Mouse Coordinates: (${this.mouseoverQuad.position.x}, ${this.mouseoverQuad.position.y})` infoStr += ` --- Mouse Coordinates: (${this.mouseoverQuad.position.x}, ${this.mouseoverQuad.position.y})`
} }
...@@ -527,7 +529,17 @@ export class Simulator { ...@@ -527,7 +529,17 @@ export class Simulator {
} else if (this.simulation_mode === 'SyncTAM') { } else if (this.simulation_mode === 'SyncTAM') {
this.tileWorker.postMessage({ msg: 'mode-SyncTAM' }); this.tileWorker.postMessage({ msg: 'mode-SyncTAM' });
} }
this.tileWorker.postMessage({ msg: 'set-seed', seed: 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)];
let origin = new Vector2D(0, 0);
this.tileBlockAtlas.add(tile, origin);
this.seedTiles.push({type: tile, coords: origin});
}
this.tileWorker.postMessage({ msg: 'set-seed', seed: this.seedTiles});
Logger.log(Logger.INFO, `loaded ${this.simulation_mode} system file "${data.tdp.name}" with a seed of size ${this.seedTiles.length}`); Logger.log(Logger.INFO, `loaded ${this.simulation_mode} system file "${data.tdp.name}" with a seed of size ${this.seedTiles.length}`);
......
...@@ -246,32 +246,49 @@ export class TileBlockAtlas { ...@@ -246,32 +246,49 @@ export class TileBlockAtlas {
} }
stepBackward() { stepBackward() {
const coords = this.history.pop(); const attachments = this.history.pop();
return this.remove(coords); for (let coords of attachments) {
let success = this.remove(coords);
if (!success) return false;
}
return true;
} }
add(type, coords) { add_inner(type, coords) {
const blockIndex = this.getBlockIndex(coords); const blockIndex = this.getBlockIndex(coords);
if (!this.tileBlocks.has(blockIndex.y)) if (!this.tileBlocks.has(blockIndex.y))
this.tileBlocks.set(blockIndex.y, new Map()); this.tileBlocks.set(blockIndex.y, new Map());
const subMap = this.tileBlocks.get(blockIndex.y); const subMap = this.tileBlocks.get(blockIndex.y);
if (!subMap.has(blockIndex.x)) { if (!subMap.has(blockIndex.x)) {
const tileBlock = new TileBlock(blockIndex.mul(BLOCK_DIMS)); const tileBlock = new TileBlock(blockIndex.mul(BLOCK_DIMS));
this.tileGroup.add(tileBlock.tileMesh); this.tileGroup.add(tileBlock.tileMesh);
this.outlineGroup.add(tileBlock.outlineMesh); this.outlineGroup.add(tileBlock.outlineMesh);
subMap.set(blockIndex.x, tileBlock); subMap.set(blockIndex.x, tileBlock);
} }
const tileBlock = subMap.get(blockIndex.x); const tileBlock = subMap.get(blockIndex.x);
tileBlock.add(type, coords);
tileBlock.add(type, coords); this.numTiles++;
}
add_one(type, coords) {
this.add_inner(type, coords);
this.history.push([coords]);
}
this.history.push(coords); add_many(attachments) {
this.numTiles++; var all_coords = [];
for (let a of attachments) {
this.add_inner(a.type, a.coords);
all_coords.push(a.coords);
}
this.history.push(all_coords);
} }
remove(coords) { remove(coords) {
......
...@@ -589,86 +589,86 @@ function removeTile(x, y) { ...@@ -589,86 +589,86 @@ function removeTile(x, y) {
function stepForward(recursion_level = 0) { function stepForward(recursion_level = 0) {
const ret_list = Array(); const ret_list = Array();
if ((simulation_mode === 'aTAM') || (simulation_mode === 'BlockTAM')) { if ((simulation_mode === 'aTAM') || (simulation_mode === 'BlockTAM')) {
let tid; let tid;
let loc; let loc;
while (tid === undefined) { while (tid === undefined) {
if (frontierMap.size === 0) { if (frontierMap.size === 0) {
if (simulation_mode === 'BlockTAM') { if (simulation_mode === 'BlockTAM') {
postMessage({msg: "frontier-empty"}); postMessage({msg: "frontier-empty"});
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 stepForward(recursion_level);
}
}
}
return null; // no more tiles can be added
}
const frontierList = Array.from(frontierMap.keys());
const key = frontierList[Math.floor(Math.random() * frontierList.length)];
const sig = signatureMap.get(key);
const fitting = getFittingTileTypes(sig);
tid = fitting[Math.floor(Math.random() * fitting.length)];
loc = frontierMap.get(key);
if (tid === undefined) {
postMessage({msg: 'tid-undefined'});
frontierMap.delete(key);
} }
}
} }
return null; // no more tiles can be added
}
addTile(tid, loc[0], loc[1]); const frontierList = Array.from(frontierMap.keys());
history.push({tid: tid, x: loc[0], y: loc[1]}); const key = frontierList[Math.floor(Math.random() * frontierList.length)];
ret_list.push([tid, loc[0], loc[1]]); const sig = signatureMap.get(key);
const fitting = getFittingTileTypes(sig);
} else { tid = fitting[Math.floor(Math.random() * fitting.length)];
const frontierList = Array.from(frontierMap.keys()); loc = frontierMap.get(key);
for (let i=0; i<frontierList.length; i++) { if (tid === undefined) {
let tid; postMessage({msg: 'tid-undefined'});
let loc; frontierMap.delete(key);
}
}
while (tid === undefined) { addTile(tid, loc[0], loc[1]);
if (i === frontierList.length) { history.push([{tid: tid, x: loc[0], y: loc[1]}]);
break; // no more tiles can be added ret_list.push([tid, loc[0], loc[1]]);
}
const key = frontierList[i]; } else {
loc = frontierMap.get(key); const frontierList = Array.from(frontierMap.keys());
var history_step = [];
for (let i=0; i<frontierList.length; i++) {
let tid;
let loc;
const sig = signatureMap.get(key); while (tid === undefined) {
const fitting = getFittingTileTypes(sig); if (i === frontierList.length) {
if ((fitting.length > 1) && (b_report_nondeterminism === true)) { break; // no more tiles can be added
const type_list = Array(); }
for (let t=0; t<fitting.length; t++) {
type_list.push(tileTypes[fitting[t]].name);
}
postMessage({ msg: 'nondeterminism', loc: loc, types: type_list});
}
tid = fitting[Math.floor(Math.random() * fitting.length)]; const key = frontierList[i];
if (tid === undefined) { loc = frontierMap.get(key);
postMessage({ msg: 'tid-undefined'});
i++; const sig = signatureMap.get(key);
} const fitting = getFittingTileTypes(sig);
} if ((fitting.length > 1) && (b_report_nondeterminism === true)) {
if (tid !== undefined) { const type_list = Array();
addTile(tid, loc[0], loc[1], false); for (let t=0; t<fitting.length; t++) {
history.push({tid: tid, x: loc[0], y: loc[1]}); type_list.push(tileTypes[fitting[t]].name);
ret_list.push([tid, loc[0], loc[1]]); }
} postMessage({ msg: 'nondeterminism', loc: loc, types: type_list});
} }
for (let r = 0; r < ret_list.length; r++) { tid = fitting[Math.floor(Math.random() * fitting.length)];
addNbrsToFrontier(ret_list[r][0], ret_list[r][1], ret_list[r][2]); if (tid === undefined) {
postMessage({ msg: 'tid-undefined'});
i++;
} }
}
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]]);
}
} }
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]);
}
}
// console.log('tile added', history, seedSize); // console.log('tile added', history, seedSize);
...@@ -681,7 +681,9 @@ function stepBackward() { ...@@ -681,7 +681,9 @@ function stepBackward() {
} }
const last = history.pop(); const last = history.pop();
removeTile(last.x, last.y); for (coords of last) {
removeTile(coords.x, coords.y);
}
// console.log('tile removed', history, seedSize); // console.log('tile removed', history, seedSize);
......
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