public OutputPair(NodeSet set, NodeHandle sourceHandle, OutputPortID sourcePort) { Handle = set.Validate(sourceHandle); var table = set.GetForwardingTable(); for (var fH = set.GetNode(Handle).ForwardedPortHead; fH != ForwardPortHandle.Invalid; fH = table[fH].NextIndex) { ref var forwarding = ref table[fH]; if (forwarding.IsInput) { continue; } var port = forwarding.GetOriginOutputPortID(); // Forwarded port list are monotonically increasing by port, so we can break out early if (forwarding.GetOriginPortCounter() > sourcePort.Port) { break; } if (port != sourcePort) { continue; } if (!set.StillExists(forwarding.Replacement)) { throw new InvalidOperationException("Replacement node for previously registered forward doesn't exist anymore"); } Handle = forwarding.Replacement; Port = forwarding.GetReplacedOutputPortID(); return; }
public static void AddInput(NodeSet set, ref DynamicMixer dynamicMixer, DynamicBuffer <DynamicMixerInput> inputs, Entity sourceEntity, NodeHandle sourceNode, OutputPortID sourcePortId) { // Attempt to find unsused input for (int i = 0; i < inputs.Length; i++) { var input = inputs[i]; if (input.SourceEntity == Entity.Null) { // GameDebug.Log("Added input at index:" + i); input.SourceEntity = sourceEntity; input.SourceNode = sourceNode; input.SourcePortId = sourcePortId; inputs[i] = input; set.Connect(sourceNode, sourcePortId, input.AddNode, (InputPortID)MixerAddNode.KernelPorts.Add); return; } } // Create new input // GameDebug.Log("Added input. New input index:" + inputs.Length); var newNode = set.Create <MixerAddNode>(); set.SendMessage(newNode, MixerAddNode.SimulationPorts.RigDefinition, dynamicMixer.Rig); set.Connect(sourceNode, sourcePortId, newNode, (InputPortID)MixerAddNode.KernelPorts.Add); // First node if (inputs.Length == 0) { set.Disconnect(dynamicMixer.MixerBegin, MixerBeginNode.KernelPorts.Output, dynamicMixer.MixerEnd, MixerEndNode.KernelPorts.Input); // Connect begin to add node set.Connect(dynamicMixer.MixerBegin, MixerBeginNode.KernelPorts.Output, newNode, MixerAddNode.KernelPorts.Input); set.Connect(dynamicMixer.MixerBegin, MixerBeginNode.KernelPorts.SumWeight, newNode, MixerAddNode.KernelPorts.SumWeightInput); // Connect Add node to end set.Connect(newNode, MixerAddNode.KernelPorts.Output, dynamicMixer.MixerEnd, MixerEndNode.KernelPorts.Input); set.Connect(newNode, MixerAddNode.KernelPorts.SumWeightOutput, dynamicMixer.MixerEnd, MixerEndNode.KernelPorts.SumWeight); } else { var prevInput = inputs[inputs.Length - 1]; // Disconnect prev from end set.Disconnect(prevInput.AddNode, MixerAddNode.KernelPorts.Output, dynamicMixer.MixerEnd, MixerEndNode.KernelPorts.Input); set.Disconnect(prevInput.AddNode, MixerAddNode.KernelPorts.SumWeightOutput, dynamicMixer.MixerEnd, MixerEndNode.KernelPorts.SumWeight); // Connect prev to new node set.Connect(prevInput.AddNode, MixerAddNode.KernelPorts.Output, newNode, MixerAddNode.KernelPorts.Input); set.Connect(prevInput.AddNode, MixerAddNode.KernelPorts.SumWeightOutput, newNode, MixerAddNode.KernelPorts.SumWeightInput); // Connect new node to end set.Connect(newNode, MixerAddNode.KernelPorts.Output, dynamicMixer.MixerEnd, MixerEndNode.KernelPorts.Input); set.Connect(newNode, MixerAddNode.KernelPorts.SumWeightOutput, dynamicMixer.MixerEnd, MixerEndNode.KernelPorts.SumWeight); } var newInput = new DynamicMixerInput { SourceEntity = sourceEntity, SourceNode = sourceNode, SourcePortId = sourcePortId, AddNode = newNode, }; inputs.Add(newInput); }
public static ValidatedHandle GetNthConnection(this Topology.Database.OutputTopologyEnumerable e, OutputPortID port, int index) { var currIndex = 0; foreach (var filtered in e[port]) { if (currIndex == index) { return(filtered); } currIndex++; } throw new IndexOutOfRangeException("Index of connection or port does not exist"); }