Ejemplo n.º 1
0
        internal void OnDeviceRemoved(ISignalNodeProvider device)
        {
            Dictionary <NodePos, ISignalNode> nodes = device.GetNodes();

            foreach (ISignalNode node in nodes.Values)
            {
                SignalNetwork net = GetNetworkAt(node.Pos, false);
                if (net == null)
                {
                    return;
                }
                net.RemoveNode(node.Pos);
            }
        }
Ejemplo n.º 2
0
        public void OnWireAdded(WireConnection con)
        {
            ISignalNodeProvider dev1 = GetDeviceAt(con.pos1.blockPos);
            ISignalNodeProvider dev2 = GetDeviceAt(con.pos2.blockPos);

            if (dev1 == null || dev2 == null)
            {
                return;
            }
            //wireConnections.Add(con);
            GetDeviceAt(con.pos1.blockPos)?.GetNodeAt(con.pos1)?.Connections.Add(con);
            GetDeviceAt(con.pos2.blockPos)?.GetNodeAt(con.pos2)?.Connections.Add(con.GetReversed());
            TryToAddConnection(con);
            TryToAddConnection(con.GetReversed());
        }
Ejemplo n.º 3
0
        public ISignalNodeProvider GetDeviceAt(BlockPos pos)
        {
            BlockEntity be = Api.World.BlockAccessor.GetBlockEntity(pos);

            if (be == null)
            {
                return(null);
            }
            ISignalNodeProvider device = be as ISignalNodeProvider;

            if (device != null)
            {
                return(device);
            }
            return(be.GetBehavior <BEBehaviorSignalNodeProvider>() as ISignalNodeProvider);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Compute values at nodes and notify the devices
        /// </summary>
        public void Simulate()
        {
            List <ISignalNode> sources = nodes.Values.Where(v => v.isSource).ToList();

            foreach (ISignalNode source in sources)
            {
                HashSet <NodePos> openList = new HashSet <NodePos> {
                    source.Pos
                };
                HashSet <NodePos> closedList = new HashSet <NodePos>();

                mod.Api.Logger.Debug("Network {0}: Simulation from source at {1}", this.networkId, source.Pos);
                byte startValue = (byte)15;



                while (openList.Count > 0 && closedList.Count <= nodes.Count + 1)
                {
                    if (closedList.Count == nodes.Count + 1)
                    {
                        mod.Api.Logger.Error("Network simulation: closed list larger than number of nodes in net!"); break;
                    }

                    NodePos pos = openList.Last();

                    ISignalNode currentNode = nodes[pos];

                    currentNode.value = startValue;
                    ISignalNodeProvider device = mod.GetDeviceAt(pos.blockPos);
                    device.OnNodeUpdate(pos);

                    mod.Api.Logger.Debug("Network {0}: Asigning value {1} at node {2}", this.networkId, startValue, pos);

                    openList.Remove(pos);
                    currentNode.Connections.ForEach(c => {
                        NodePos otherPos = c.pos1 == pos ? c.pos2 : c.pos1;
                        if (!closedList.Contains(otherPos) && nodes.ContainsKey(otherPos))
                        {
                            openList.Add(otherPos);
                        }
                    });
                    closedList.Add(pos);
                }
            }

            isValid = true;
        }
Ejemplo n.º 5
0
 public SNDeviceProxy(ISignalNodeProvider device)
 {
     nodes = device.GetNodes();
 }
Ejemplo n.º 6
0
 internal void OnDeviceInitialized(ISignalNodeProvider device)
 {
     devicesToLoad.Add(device);
 }
Ejemplo n.º 7
0
 internal void OnDeviceUnloaded(ISignalNodeProvider device)
 {
 }