Commit b1b0721b authored by Florent Becker's avatar Florent Becker

draft: improved tracking of simulation time

parent a33cf7d9
...@@ -312,6 +312,7 @@ ...@@ -312,6 +312,7 @@
<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>
......
...@@ -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;
...@@ -383,7 +384,8 @@ export class Simulator { ...@@ -383,7 +384,8 @@ export class Simulator {
} }
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,8 +529,18 @@ export class Simulator { ...@@ -527,8 +529,18 @@ 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' });
} }
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}); 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}`);
// Determine if we're in v1 or v2. V1 should use this.blockerDict and v2 should use this.tileset.tileGlueBlockers // Determine if we're in v1 or v2. V1 should use this.blockerDict and v2 should use this.tileset.tileGlueBlockers
......
...@@ -246,11 +246,15 @@ export class TileBlockAtlas { ...@@ -246,11 +246,15 @@ 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))
...@@ -270,10 +274,23 @@ export class TileBlockAtlas { ...@@ -270,10 +274,23 @@ export class TileBlockAtlas {
tileBlock.add(type, coords); tileBlock.add(type, coords);
this.history.push(coords);
this.numTiles++; this.numTiles++;
} }
add_one(type, coords) {
this.add_inner(type, coords);
this.history.push([coords]);
}
add_many(attachments) {
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) {
const blockIndex = this.getBlockIndex(coords); const blockIndex = this.getBlockIndex(coords);
......
...@@ -624,12 +624,12 @@ function stepForward(recursion_level = 0) { ...@@ -624,12 +624,12 @@ 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]}); history.push([{tid: tid, x: loc[0], y: loc[1]}]);
ret_list.push([tid, loc[0], loc[1]]); ret_list.push([tid, loc[0], loc[1]]);
} else { } else {
const frontierList = Array.from(frontierMap.keys()); const frontierList = Array.from(frontierMap.keys());
var history_step = [];
for (let i=0; i<frontierList.length; i++) { for (let i=0; i<frontierList.length; i++) {
let tid; let tid;
let loc; let loc;
...@@ -660,11 +660,11 @@ function stepForward(recursion_level = 0) { ...@@ -660,11 +660,11 @@ function stepForward(recursion_level = 0) {
} }
if (tid !== undefined) { if (tid !== undefined) {
addTile(tid, loc[0], loc[1], false); addTile(tid, loc[0], loc[1], false);
history.push({tid: tid, x: loc[0], y: loc[1]}); history_step.push({tid: tid, x: loc[0], y: loc[1]});
ret_list.push([tid, loc[0], loc[1]]); ret_list.push([tid, loc[0], loc[1]]);
} }
} }
history.push(history_step);
for (let r = 0; r < ret_list.length; r++) { for (let r = 0; r < ret_list.length; r++) {
addNbrsToFrontier(ret_list[r][0], ret_list[r][1], ret_list[r][2]); addNbrsToFrontier(ret_list[r][0], ret_list[r][1], ret_list[r][2]);
} }
...@@ -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