Computations now occupy their own nodes on the dependency graph

This mitigates most issues with properties having self-loops, 
particularly in cases like Strength where the value `strength` is used 
in the description of Strength
This commit is contained in:
Stefan Zermatten
2021-12-07 21:05:24 +02:00
parent 6698d2fd74
commit e34f29f952
17 changed files with 247 additions and 110 deletions

View File

@@ -1,6 +1,6 @@
import computeCalculations from '/imports/api/engine/computation/computeComputation/computeCalculations.js';
import computeToggles from '/imports/api/engine/computation/computeComputation/computeToggles.js';
import computeByType from '/imports/api/engine/computation/computeComputation/computeByType.js';
import embedInlineCalculations from './utility/embedInlineCalculations.js';
export default function computeCreatureComputation(computation){
const stack = [];
@@ -22,7 +22,7 @@ export default function computeCreatureComputation(computation){
// Mark the object as visited and remove from stack
top._visited = true;
stack.pop();
// Compute the top object of the stack
// Compute the top object of the stack
compute(computation, top);
} else {
top._visitedChildren = true;
@@ -30,13 +30,14 @@ export default function computeCreatureComputation(computation){
pushDependenciesToStack(top.id, graph, stack);
}
}
// Finish the props after the dependency graph has been traversed
computation.props.forEach(finalizeProp);
}
function compute(computation, node){
// Determine the prop's active status by its toggles
computeToggles(computation, node);
computeCalculations(computation, node);
if (node.data) delete node.data._computationDetails;
// Compute the property by type
computeByType[node.data?.type || '_variable']?.(computation, node);
}
@@ -46,3 +47,12 @@ function pushDependenciesToStack(nodeId, graph, stack){
stack.push(linkedNode);
}, true);
}
function finalizeProp(prop){
// Embed the inline calculations
prop._computationDetails?.inlineCalculations?.forEach(inlineCalcObj => {
embedInlineCalculations(inlineCalcObj);
});
// Clean up the computation details
delete prop._computationDetails;
}