mirror of
https://github.com/wisplite/BLE-mesh-sim.git
synced 2026-10-30 05:22:23 -05:00
Add cancel button to markNeighbor walkthrough mode (it can take forever on large networks)
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
<input type="checkbox" id="quickPlace" class="simToggle">
|
<input type="checkbox" id="quickPlace" class="simToggle">
|
||||||
<label for="quickPlace">Quick Place</label>
|
<label for="quickPlace">Quick Place</label>
|
||||||
</div>
|
</div>
|
||||||
|
<button id="cancelMarkNeighbor">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="centerColumn" style="display: flex; flex-direction: column; align-items: center; justify-content: center; width: 70%; height: 100%; margin: 0 auto;">
|
<div id="centerColumn" style="display: flex; flex-direction: column; align-items: center; justify-content: center; width: 70%; height: 100%; margin: 0 auto;">
|
||||||
<div id="simContainer"></div>
|
<div id="simContainer"></div>
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ var MAX_CONNECTIONS = 6;
|
|||||||
var warningModalShown = false;
|
var warningModalShown = false;
|
||||||
var displayWarningWhenDone = false;
|
var displayWarningWhenDone = false;
|
||||||
var stillRouting = false;
|
var stillRouting = false;
|
||||||
|
var markNeighborInterval = null;
|
||||||
|
// Track all active intervals for marking neighbors, and a cancel flag
|
||||||
|
var markNeighborIntervals = new Set();
|
||||||
|
var cancelMarkNeighborRequested = false;
|
||||||
|
|
||||||
function smoothColorTransition(color1, color2, min, max, current) {
|
function smoothColorTransition(color1, color2, min, max, current) {
|
||||||
// Clamp current between min and max
|
// Clamp current between min and max
|
||||||
@@ -311,6 +315,9 @@ async function routePacket(currentNode, goalNode, packetInfo, first=false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => {
|
const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => {
|
||||||
|
if (cancelMarkNeighborRequested) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (visited.has(nodeId)) {
|
if (visited.has(nodeId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -318,10 +325,22 @@ const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => {
|
|||||||
|
|
||||||
if (warningModalShown) {
|
if (warningModalShown) {
|
||||||
// enable walkthrough mode to prevent browser from freezing
|
// enable walkthrough mode to prevent browser from freezing
|
||||||
|
if (markNeighborIntervals.size === 0) {
|
||||||
|
cancelMarkNeighborRequested = false;
|
||||||
|
}
|
||||||
|
document.getElementById('cancelMarkNeighbor').style.display = 'block';
|
||||||
const neighborsSnapshot = (nodeTable[nodeId]?.connections?.slice()) || [];
|
const neighborsSnapshot = (nodeTable[nodeId]?.connections?.slice()) || [];
|
||||||
const neighborsLength = neighborsSnapshot.length;
|
const neighborsLength = neighborsSnapshot.length;
|
||||||
let currentIdx = 0;
|
let currentIdx = 0;
|
||||||
const intervalId = setInterval(() => {
|
const intervalId = setInterval(() => {
|
||||||
|
if (cancelMarkNeighborRequested) {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
markNeighborIntervals.delete(intervalId);
|
||||||
|
if (markNeighborIntervals.size === 0) {
|
||||||
|
document.getElementById('cancelMarkNeighbor').style.display = 'none';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (currentIdx < neighborsLength) {
|
if (currentIdx < neighborsLength) {
|
||||||
const neighbor = neighborsSnapshot[currentIdx];
|
const neighbor = neighborsSnapshot[currentIdx];
|
||||||
if (!visited.has(neighbor) &&
|
if (!visited.has(neighbor) &&
|
||||||
@@ -335,8 +354,13 @@ const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => {
|
|||||||
currentIdx++;
|
currentIdx++;
|
||||||
} else {
|
} else {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
|
markNeighborIntervals.delete(intervalId);
|
||||||
|
if (markNeighborIntervals.size === 0) {
|
||||||
|
document.getElementById('cancelMarkNeighbor').style.display = 'none';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 10);
|
}, 1);
|
||||||
|
markNeighborIntervals.add(intervalId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -905,8 +929,22 @@ window.onload = function() {
|
|||||||
consoleContainer.appendChild(consoleOutput);
|
consoleContainer.appendChild(consoleOutput);
|
||||||
|
|
||||||
document.getElementById('simContainer').appendChild(openConsoleButton);
|
document.getElementById('simContainer').appendChild(openConsoleButton);
|
||||||
|
|
||||||
|
// Ensure cancel button is hidden on load
|
||||||
|
document.getElementById('cancelMarkNeighbor').style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById('cancelMarkNeighbor').addEventListener('click', function() {
|
||||||
|
consoleLog('Cancelling mark neighbor...');
|
||||||
|
cancelMarkNeighborRequested = true;
|
||||||
|
// Clear any tracked intervals
|
||||||
|
for (let id of Array.from(markNeighborIntervals)) {
|
||||||
|
clearInterval(id);
|
||||||
|
markNeighborIntervals.delete(id);
|
||||||
|
}
|
||||||
|
document.getElementById('cancelMarkNeighbor').style.display = 'none';
|
||||||
|
});
|
||||||
|
|
||||||
function consoleLog(message) {
|
function consoleLog(message) {
|
||||||
const consoleOutput = document.getElementById('consoleOutput');
|
const consoleOutput = document.getElementById('consoleOutput');
|
||||||
consoleOutput.innerHTML = `${message}`;
|
consoleOutput.innerHTML = `${message}`;
|
||||||
|
|||||||
@@ -301,4 +301,10 @@ input[type="checkbox"], input[type="radio"] {
|
|||||||
height: 50%;
|
height: 50%;
|
||||||
background-color: #000000;
|
background-color: #000000;
|
||||||
color: #e0e0e0;
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelMarkNeighbor {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 10px;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user