Example #1
0
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">Command line arguments that are ignored.</param>
        private static void Main(String[] args)
        {
            var inputNode2    = new OnlyOutput();
            var splitterNode1 = new Splitter();
            var maxNode1      = new MaxFinder();
            var splitterNode2 = new Splitter();
            var maxNode2      = new MaxFinder();
            var outputNode1   = new LogicConsoleWriter <byte>();
            var outputNode2   = new LogicConsoleWriter <byte>();

            inputNode2.ConnectToHead(0, splitterNode1, 0);
            splitterNode1.ConnectToHead(0, maxNode1, 1);
            splitterNode1.ConnectToHead(1, maxNode2, 1);
            maxNode1.ConnectToHead(0, splitterNode2, 0);
            splitterNode2.ConnectToHead(2, maxNode1, 0);
            splitterNode2.ConnectToHead(0, maxNode2, 0);
            splitterNode2.ConnectToHead(1, outputNode1, 0);
            maxNode2.ConnectToHead(0, outputNode2, 0);

            Graph graph = new Graph();

            graph.AddNode(inputNode2);
            graph.AddNode(splitterNode1);
            graph.AddNode(splitterNode2);
            graph.AddNode(maxNode1);
            graph.AddNode(maxNode2);
            graph.AddNode(outputNode1);
            graph.AddNode(outputNode2);

            inputNode2.SetOutput(13);
            graph.Step();
            inputNode2.SetOutput(32);
            graph.Step();
            graph.Step();
        }
        private void UpdateTarget()
        {
            Int64   targetX = mnX - _sourceXOffset;
            Int64   targetY = mnY - _sourceYOffset;
            Int64   targetZ = mnZ - _sourceZOffset;
            Segment segment = AttemptGetSegment(targetX, targetY, targetZ);

            if (segment == null)
            {
                return;
            }
            UInt16 cubeType = segment.GetCube(targetX, targetY, targetZ);

            ILogicReceiver logicReciever;
            Int32          inputIndex;

            if (CubeHelper.HasEntity(cubeType) &&
                (logicReciever = segment.SearchEntity(targetX, targetY, targetZ) as ILogicReceiver) != null &&
                (inputIndex = logicReciever.FindFaceInputIndex(_targetDirection)) != -1)
            {
                // There is a connectable logic node at the target location
                var targetNode = logicReciever.GetLogicNode();
                if (_node.OutNodes[OutIndex] == targetNode)
                {
                    return;
                }

                // The node is not the same, so remove the old node and connect to the new one.
                _node.DisconnectFromHead(OutIndex);

                if (!targetNode.IsInputActive(inputIndex))
                {
                    try
                    {
                        _node.ConnectToHead(OutIndex, targetNode, inputIndex);
                    }
                    catch (InputEdgeAlreadyActiveException ex)
                    {
                        Debug.LogWarning(
                            "Sensor attempted to connect to index that was already in use!\n" +
                            $"\nTarget type: {targetNode.GetType()} inindex: {inputIndex} Active input count: {targetNode.ActiveInputCount}" +
                            "\nException: " + ex);
                    }
                }

                // Else, the current node is the same, no changes needed
            }
            else
            {
                // No connectable logic node at the target location, make sure we're disconnected
                _node.DisconnectFromHead(OutIndex);
            }
        }