Esempio n. 1
0
 /// <summary>
 /// Determines whether the given interval lies within the tick interval for the given network .
 /// </summary>
 /// <param name="network">The network.</param>
 /// <param name="interval">The interval.</param>
 /// <returns>
 ///   <c>true</c> if [is hash interval tick] [the specified interval]; otherwise, <c>false</c>.
 /// </returns>
 /// <exception cref="ArgumentNullException">network</exception>
 public static bool IsHashIntervalTick([NotNull] this SlurryNet network, int interval)
 {
     if (network == null)
     {
         throw new ArgumentNullException(nameof(network));
     }
     return(network.HashOffsetTicks() % interval == 0);
 }
Esempio n. 2
0
 /// <summary>
 /// gets the hash offset for ticks
 /// </summary>
 /// <param name="network">The network.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">network</exception>
 public static int HashOffsetTicks([NotNull] this SlurryNet network)
 {
     if (network == null)
     {
         throw new ArgumentNullException(nameof(network));
     }
     return(Find.TickManager.TicksGame + network.GetHashCode().HashOffset());
 }
        /// <summary>
        ///     notifies this instance that a connector was added
        /// </summary>
        /// <param name="comp">The comp.</param>
        /// <exception cref="ArgumentNullException">comp</exception>
        public void NotifyConnectorAdded([NotNull] SlurryNetComp comp)
        {
            if (comp == null)
            {
                throw new ArgumentNullException(nameof(comp));
            }

            DebugLogUtils.LogMsg(LogLevel.Messages, $"adding connector for '{comp.parent.Label}'");

            if (comp.Network != null || Nets.Any(n => n.Connectors.Contains(comp)))
            {
                Log.Error($"adding slurry comp {comp.parent.Label} which is already part of a network");
                return;
            }

            List <SlurryNet> neighbors = comp.GetAdjacentSlurryComps()
                                         .Select(n => n.Network)
                                         .Where(n => n != null)
                                         .Distinct()
                                         .ToList();

            if (neighbors.Count == 1)
            {
                neighbors[0].Register(comp);
            }
            else
            {
                foreach (SlurryNet slurryNet in neighbors)
                {
                    DestroyNet(slurryNet);
                }

                SlurryNet net = CreateSlurryNetFrom(comp, null);
                _nets.Add(net);
            }
        }
 private void DestroyNet(SlurryNet slurryNet)
 {
     _nets.Remove(slurryNet);
     slurryNet.Destroy();
 }