Skip to content

Commit

Permalink
refactor: Improve propagation logic to fix animation and color spread…
Browse files Browse the repository at this point in the history
…ing issues
  • Loading branch information
sanity committed Nov 30, 2024
1 parent d2f0345 commit 3ecbfbf
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions hugo-site/static/html/eventual_convergence_viz.html
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ <h1 class="title">Freenet Eventual Convergence Simulation</h1>
while (iteration < MAX_ITERATIONS) {
let hasUpdates = false;
const nodePairs = getAllConnectedPairs();
const propagations = [];

// Process pairs sequentially to avoid animation conflicts
for (const [nodeA, nodeB] of nodePairs) {
// Clean up undefined colors
nodeA.data.receivedColors = nodeA.data.receivedColors.filter(color => color !== undefined);
Expand All @@ -308,12 +308,12 @@ <h1 class="title">Freenet Eventual Convergence Simulation</h1>

if (colorsAtoB.length > 0) {
hasUpdates = true;
propagations.push(animateMessage(nodeA, nodeB, colorsAtoB));
await animateMessage(nodeA, nodeB, colorsAtoB);
}

if (colorsBtoA.length > 0) {
hasUpdates = true;
propagations.push(animateMessage(nodeB, nodeA, colorsBtoA));
await animateMessage(nodeB, nodeA, colorsBtoA);
}
}

Expand All @@ -322,12 +322,8 @@ <h1 class="title">Freenet Eventual Convergence Simulation</h1>
break;
}

// Wait for all propagations in this timestep to complete
if (propagations.length > 0) {
await Promise.all(propagations);
// Add a small delay between iterations to prevent UI freezing
await new Promise(resolve => setTimeout(resolve, 50));
}
// Add a small delay between iterations
await new Promise(resolve => setTimeout(resolve, 50));

iteration++;
}
Expand Down

0 comments on commit 3ecbfbf

Please sign in to comment.