| 103 | } |
| 104 | |
| 105 | void BehaviorTreeGraph::SetupRecursive(Node& node) |
| 106 | { |
| 107 | // Count total states memory size |
| 108 | ASSERT_LOW_LAYER(node.Instance); |
| 109 | node.Instance->_memoryOffset = NodesStatesSize; |
| 110 | node.Instance->_executionIndex = NodesCount; |
| 111 | NodesStatesSize += node.Instance->GetStateSize(); |
| 112 | NodesCount++; |
| 113 | |
| 114 | if (node.TypeID == 1 && node.Values.Count() >= 3) |
| 115 | { |
| 116 | // Load node decorators |
| 117 | const auto& decoratorIds = node.Values[2]; |
| 118 | if (decoratorIds.Type.Type == VariantType::Blob && decoratorIds.AsBlob.Length) |
| 119 | { |
| 120 | const Span<uint32> ids((uint32*)decoratorIds.AsBlob.Data, decoratorIds.AsBlob.Length / sizeof(uint32)); |
| 121 | for (int32 i = 0; i < ids.Length(); i++) |
| 122 | { |
| 123 | Node* decorator = GetNode(ids[i]); |
| 124 | if (decorator && decorator->Instance && decorator->Instance->Is<BehaviorTreeDecorator>()) |
| 125 | { |
| 126 | node.Instance->_decorators.Add((BehaviorTreeDecorator*)decorator->Instance); |
| 127 | decorator->Instance->_parent = node.Instance; |
| 128 | SetupRecursive(*decorator); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | if (auto* nodeCompound = ScriptingObject::Cast<BehaviorTreeCompoundNode>(node.Instance)) |
| 134 | { |
| 135 | auto& children = node.Boxes[1].Connections; |
| 136 | |
| 137 | // Sort children from left to right (based on placement on a graph surface) |
| 138 | Sorting::QuickSort(children.Get(), children.Count(), SortBehaviorTreeChildren); |
| 139 | |
| 140 | // Find all children (of output box) |
| 141 | for (const GraphBox* childBox : children) |
| 142 | { |
| 143 | Node* child = childBox ? (Node*)childBox->Parent : nullptr; |
| 144 | if (child && child->Instance) |
| 145 | { |
| 146 | nodeCompound->Children.Add(child->Instance); |
| 147 | child->Instance->_parent = nodeCompound; |
| 148 | SetupRecursive(*child); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | BehaviorTree::BehaviorTree(const SpawnParams& params, const AssetInfo* info) |
| 155 | : BinaryAsset(params, info) |