Added dependency grouping, but commented out for now until it's needed
This commit is contained in:
@@ -15,6 +15,7 @@ import linkTypeDependencies from './buildComputation/linkTypeDependencies.js';
|
||||
import computeSlotQuantityFilled from './buildComputation/computeSlotQuantityFilled.js';
|
||||
import CreatureComputation from './CreatureComputation.js';
|
||||
import removeSchemaFields from './buildComputation/removeSchemaFields.js';
|
||||
// import assignDependencyGroups from '/imports/api/engine/computation/utility/assignDependencyGroups.js';
|
||||
|
||||
/**
|
||||
* Store index of properties
|
||||
@@ -37,12 +38,30 @@ export default function buildCreatureComputation(creatureId){
|
||||
return computation;
|
||||
}
|
||||
|
||||
function getProperties(creatureId){
|
||||
export function buildDependencyGroupComputation(depGroupIds, creatureId) {
|
||||
const creature = getCreature(creatureId);
|
||||
const properties = getGroupProperties(depGroupIds);
|
||||
const computation = buildComputationFromProps(properties, creature);
|
||||
return computation;
|
||||
}
|
||||
|
||||
function getProperties(creatureId) {
|
||||
return CreatureProperties.find({
|
||||
'ancestors.id': creatureId,
|
||||
'removed': {$ne: true},
|
||||
}, {
|
||||
sort: {order: 1}
|
||||
sort: { order: 1 },
|
||||
fields: { icon: 0 },
|
||||
}).fetch();
|
||||
}
|
||||
|
||||
function getGroupProperties(depGroupIds) {
|
||||
return CreatureProperties.find({
|
||||
depGroupId: { $in: depGroupIds },
|
||||
'removed': { $ne: true },
|
||||
}, {
|
||||
sort: { order: 1 },
|
||||
fields: { icon: 0 },
|
||||
}).fetch();
|
||||
}
|
||||
|
||||
@@ -82,7 +101,7 @@ export function buildComputationFromProps(properties, creature){
|
||||
// Process the properties one by one
|
||||
properties.forEach(prop => {
|
||||
|
||||
let computedSchema = computedOnlySchemas[prop.type];
|
||||
const computedSchema = computedOnlySchemas[prop.type];
|
||||
removeSchemaFields([computedSchema, denormSchema], prop);
|
||||
|
||||
// Add a place to store all the computation details
|
||||
@@ -114,5 +133,9 @@ export function buildComputationFromProps(properties, creature){
|
||||
linkTypeDependencies(dependencyGraph, prop, computation);
|
||||
linkCalculationDependencies(dependencyGraph, prop, computation);
|
||||
});
|
||||
|
||||
// Store the connected groups of the dependency graph
|
||||
// assignDependencyGroups(dependencyGraph);
|
||||
|
||||
return computation;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
export default function assignDependencyGroups(graph) {
|
||||
// Iterate through all the nodes
|
||||
graph.forEachNode(node => {
|
||||
if (node._depGroupVisited) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DFS all the connected nodes to this node, mark visited, put in a group,
|
||||
// store the lowest ordered id
|
||||
const group = [];
|
||||
const stack = [node];
|
||||
let top, lowestOrderId, lowestOrder;
|
||||
while (stack.length) {
|
||||
top = stack.pop();
|
||||
if (top._depGroupVisited) continue;
|
||||
if (
|
||||
(lowestOrderId === undefined && top.data?._id) ||
|
||||
(top.data?._id && top.data?.order < lowestOrder)
|
||||
) {
|
||||
lowestOrderId = top.data?._id;
|
||||
lowestOrder = top.data?.order;
|
||||
}
|
||||
if (top.data?._id) {
|
||||
group.push(top)
|
||||
}
|
||||
top._depGroupVisited = true;
|
||||
graph.forEachLinkedNode(top.id, linkedNode => stack.push(linkedNode));
|
||||
}
|
||||
// Assign group id
|
||||
group.forEach(node => {
|
||||
if (!lowestOrderId) return;
|
||||
if (group.length > 1) {
|
||||
node.data.depGroupId = lowestOrderId;
|
||||
} else {
|
||||
delete node.data.depGroupId;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -20,6 +20,7 @@ export default function writeAlteredProperties(computation){
|
||||
'deactivatedBySelf',
|
||||
'deactivatedByAncestor',
|
||||
'deactivatedByToggle',
|
||||
'depGroupId',
|
||||
'damage',
|
||||
...schema.objectKeys(),
|
||||
];
|
||||
@@ -28,7 +29,8 @@ export default function writeAlteredProperties(computation){
|
||||
bulkWriteOperations.push(op);
|
||||
}
|
||||
});
|
||||
writePropertiesSequentially(bulkWriteOperations);
|
||||
bulkWriteProperties(bulkWriteOperations);
|
||||
if (bulkWriteOperations.length) console.log(`Wrote ${bulkWriteOperations.length} props`);
|
||||
}
|
||||
|
||||
function addChangedKeysToOp(op, keys, original, changed) {
|
||||
@@ -79,10 +81,10 @@ function addUnsetOp(op, key){
|
||||
}
|
||||
}
|
||||
|
||||
// We use this instead of bulkWriteProperties because it functions with latency
|
||||
// compensation without needing to roll back changes, which causes multiple
|
||||
// expensive redraws of the character sheet
|
||||
function writePropertiesSequentially(bulkWriteOps){
|
||||
// If we re-enable client-side sheet recalculation, this needs to be run on
|
||||
// both client and server to preserve latency compensation. Bulkwrite breaks
|
||||
// latency compensation and causes flickering
|
||||
function writePropertiesSequentially(bulkWriteOps) {
|
||||
bulkWriteOps.forEach(op => {
|
||||
let updateOneOrMany = op.updateOne || op.updateMany;
|
||||
CreatureProperties.update(updateOneOrMany.filter, updateOneOrMany.update, {
|
||||
@@ -101,7 +103,7 @@ function writePropertiesSequentially(bulkWriteOps){
|
||||
function bulkWriteProperties(bulkWriteOps){
|
||||
if (!bulkWriteOps.length) return;
|
||||
// bulkWrite is only available on the server
|
||||
if (Meteor.isServer){
|
||||
if (Meteor.isServer) {
|
||||
CreatureProperties.rawCollection().bulkWrite(
|
||||
bulkWriteOps,
|
||||
{ordered : false},
|
||||
|
||||
Reference in New Issue
Block a user