From 653f05012a6589f2f27157aea00cdc1a0822c1d2 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Sat, 26 Feb 2022 14:58:38 +0200 Subject: [PATCH] Reversed the order of the creature compute dependency graph traversal By doing this the traversal happens mostly in tree order, which is a better assumption of starting point in cases where there are dependency loops --- .../api/engine/computation/computeCreatureComputation.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/imports/api/engine/computation/computeCreatureComputation.js b/app/imports/api/engine/computation/computeCreatureComputation.js index fbaafe28..be866e1b 100644 --- a/app/imports/api/engine/computation/computeCreatureComputation.js +++ b/app/imports/api/engine/computation/computeCreatureComputation.js @@ -13,6 +13,12 @@ export default function computeCreatureComputation(computation){ node._visitedChildren = false; stack.push(node) }); + + // The graph nodes in the stack are ordered, by reversing the order we + // compute higher nodes in the tree first, which for dep loops is more likely + // to be a good guess of where to start thant the inverse + stack.reverse(); + // Depth first traversal of nodes while (stack.length){ let top = stack[stack.length - 1];