Ejemplo n.º 1
0
        public Item GetItemFor(InputPipeNode input)
        {
            Item item = null;

            item = ConnectedContainer.GetItemForInput(input, Flux);
            return(item);
        }
Ejemplo n.º 2
0
        public bool AddConnectedInput(InputPipeNode input)
        {
            bool added = false;

            if (Globals.UltraDebug)
            {
                Printer.Info($"[N{ParentNetwork.ID}] Does {Print()} have a valid adjacent container? " + (ConnectedContainer != null).ToString());
            }
            if (Globals.UltraDebug)
            {
                Printer.Info($"[N{ParentNetwork.ID}] Does {input.Print()} have a valid adjacent container? " + (input.ConnectedContainer != null).ToString());
            }
            if (ConnectedContainer != null && input.ConnectedContainer != null)
            {
                List <PipeNode> path;
                path = GetPath(input);
                if (path.Count > 0)
                {
                    added = true;
                    ConnectedInputs.Add(input, path);
                    var t = new Thread(() => AnimateConnection(path));
                    t.Start();
                    DataAccess.GetDataAccess().Threads.Add(t);
                }
            }
            return(added);
        }
Ejemplo n.º 3
0
        public bool IsInputConnected(InputPipeNode input)
        {
            bool connected = false;

            if (ConnectedInputs.Keys.Contains(input))
            {
                connected = true;
            }
            return(connected);
        }
Ejemplo n.º 4
0
        public bool RemoveConnectedInput(InputPipeNode input)
        {
            bool removed = false;

            if (ConnectedInputs.Keys.Contains(input))
            {
                removed = true;
                ConnectedInputs.Remove(input);
            }
            return(removed);
        }
Ejemplo n.º 5
0
        public bool CanSendItems(InputPipeNode input)
        {
            bool canSend = false;

            if (ConnectedContainer != null && ConnectedContainer.CanSendItems() &&
                (input.CanRecieveItems() || input.ConnectedContainer.CanStackItems()) &&
                StoredItem == null)
            {
                canSend = true;
            }
            return(canSend);
        }
Ejemplo n.º 6
0
        public bool TryConnectNodes(OutputPipeNode output, InputPipeNode input)
        {
            bool connected = false;

            if (output != null && input != null)
            {
                if (!output.IsInputConnected(input))
                {
                    if (output.CanConnectedWith(input))
                    {
                        output.AddConnectedInput(input);

                        connected = true;
                    }
                }
            }
            return(connected);
        }
Ejemplo n.º 7
0
        public bool TryDisconnectInput(InputPipeNode input)
        {
            bool canDisconnect = false;

            if (input != null)
            {
                if (Globals.UltraDebug)
                {
                    Printer.Info($"[N{ID}] Trying disconnecting {input.Print()}");
                }
                foreach (OutputPipeNode output in Outputs)
                {
                    if (output.IsInputConnected(input))
                    {
                        if (Globals.UltraDebug)
                        {
                            Printer.Info($"[N{ID}] {input.Print()} already connected");
                        }
                        if (!output.CanConnectedWith(input) || input.ConnectedContainer == null)
                        {
                            canDisconnect = output.RemoveConnectedInput(input);
                            if (Globals.UltraDebug)
                            {
                                Printer.Info($"[N{ID}] Can disconnect with {input.Print()}? -> {canDisconnect}");
                            }
                        }
                        else
                        {
                            if (Globals.UltraDebug)
                            {
                                Printer.Info($"[N{ID}] Cannot disconnect with {input.Print()}");
                            }
                        }
                    }
                    output.UpdateSignal();
                }
                input.UpdateSignal();
            }
            return(canDisconnect);
        }
Ejemplo n.º 8
0
 public abstract Item GetItemForInput(InputPipeNode input, int flux);
Ejemplo n.º 9
0
        public void StartExchage()
        {
            if (Globals.UltraDebug)
            {
                Printer.Info($"[T{Thread.CurrentThread.ManagedThreadId}][N{ParentNetwork.ID}] Number of inputs: " + ConnectedInputs.Count.ToString());
            }
            Item item  = null;
            int  index = 0;
            Dictionary <InputPipeNode, List <PipeNode> > priorityInputs = ConnectedInputs;

            priorityInputs = priorityInputs.
                             OrderByDescending(pair => pair.Key.Priority).
                             ThenBy(pair => pair.Value.Count).
                             ToDictionary(x => x.Key, x => x.Value);
            //Mirar para hacer round robin
            if (!RoundRobin)
            {
                while (index < priorityInputs.Count && item == null)
                {
                    InputPipeNode input = priorityInputs.Keys.ToList()[index];
                    if (input.Signal.Equals("on"))
                    {
                        List <PipeNode> path = priorityInputs.Values.ToList()[index];
                        input.UpdateFilter();
                        if (CanSendItems(input))
                        {
                            item = GetItemFor(input);
                            if (item != null && StoredItem == null)
                            {
                                //Printer.Info($"Item to send: {item.Name}({item.Stack})");
                                Node ret = SendItem(item, input);
                                if (ret == null)
                                {
                                    input.SendItem(item, this);
                                }
                            }
                            else if (StoredItem != null)
                            {
                                //Printer.Info($"Output locked");
                                //Output locked
                            }
                            else if (item == null)
                            {
                                //Printer.Info($"Item is null");
                                //Item is null
                            }
                        }
                    }
                    index++;
                }
            }
            else
            {
                //RoundRobin
            }
            try
            {
                if (DataAccess.GetDataAccess().Threads.Contains(Thread.CurrentThread))
                {
                    DataAccess.GetDataAccess().Threads.Remove(Thread.CurrentThread);
                    //Printer.Info("Removing T" + Thread.CurrentThread.ManagedThreadId);
                }
            }
            catch (Exception e)
            {
                DataAccess.GetDataAccess().Threads.Clear();
            }
        }