Ejemplo n.º 1
0
        private static void EnqueueChildren(Queue <ElementPair> queue, ElementValue element, global::Part part)
        {
            if (!part.children.Any())
            {
                return;
            }

            foreach (var child in part.children)
            {
                queue.Enqueue(new ElementPair(element, child));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the first element in the queue
        /// </summary>
        /// <param name="vessel">The vessel that you want to crawl for elements</param>
        /// <param name="elements">The final element list, is it included here to have the root element added</param>
        /// <param name="shared">the ever present shared object</param>
        /// <returns>a queue with a starting entry</returns>
        private static Queue <ElementPair> InitQueue(Vessel vessel, Dictionary <uint, ElementValue> elements, SharedObjects shared)
        {
            var toReturn = new Queue <ElementPair>();

            var rootUid  = vessel.rootPart.flightID;
            var rootInfo = new DockedVesselInfo
            {
                name        = vessel.vesselName,
                rootPartUId = rootUid,
                vesselType  = vessel.vesselType
            };
            var rootElement = new ElementValue(rootInfo, shared);

            elements.Add(rootUid, rootElement);
            toReturn.Enqueue(new ElementPair(rootElement, vessel.rootPart));
            return(toReturn);
        }
Ejemplo n.º 3
0
        private static void WorkQueue(Queue <ElementPair> queue, Dictionary <uint, ElementValue> elements, SharedObjects shared)
        {
            var visitedFlightIds = new HashSet <uint>();

            while (queue.Any())
            {
                ElementPair pair = queue.Dequeue();
                if (AlreadyVisited(pair.Part, visitedFlightIds))
                {
                    continue;
                }

                var dockingNodes = pair.Part.Modules.OfType <ModuleDockingNode>().ToList();

                if (dockingNodes.Any())
                {
                    foreach (var dockingNode in dockingNodes)
                    {
                        ElementValue element;
                        if (dockingNode.vesselInfo == null)
                        {
                            element = pair.Element;
                        }
                        else
                        {
                            DockedVesselInfo info = dockingNode.vesselInfo;

                            if (!elements.TryGetValue(info.rootPartUId, out element))
                            {
                                element = new ElementValue(info, shared);
                                elements.Add(info.rootPartUId, element);
                            }
                        }

                        element.AddPart(pair.Part);
                        EnqueueChildren(queue, element, pair.Part);
                    }
                }
                else
                {
                    pair.Element.AddPart(pair.Part);
                    EnqueueChildren(queue, pair.Element, pair.Part);
                }
            }
        }
Ejemplo n.º 4
0
 public ElementPair(ElementValue element, global::Part part) : this()
 {
     Element = element;
     Part    = part;
 }
Ejemplo n.º 5
0
        private static void WorkQueue(Queue<ElementPair> queue, Dictionary<uint, ElementValue> elements, SharedObjects shared)
        {
            var visitedFlightIds = new HashSet<uint>();

            while (queue.Any())
            {
                ElementPair pair = queue.Dequeue();
                if (AlreadyVisited(pair.Part, visitedFlightIds)) continue;

                var dockingNodes = pair.Part.Modules.OfType<ModuleDockingNode>().ToList();

                if (dockingNodes.Any())
                {
                    foreach (var dockingNode in dockingNodes)
                    {
                        ElementValue element;
                        if (dockingNode.vesselInfo == null)
                        {
                            element = pair.Element;
                        }
                        else
                        {
                            DockedVesselInfo info = dockingNode.vesselInfo;

                            if (!elements.TryGetValue(info.rootPartUId, out element))
                            {
                                element = new ElementValue(info, shared);
                                elements.Add(info.rootPartUId, element);
                            }
                        }

                        element.AddPart(pair.Part);
                        EnqueueChildren(queue, element, pair.Part);
                    }
                }
                else
                {
                    pair.Element.AddPart(pair.Part);
                    EnqueueChildren(queue, pair.Element, pair.Part);                    
                }
            }
        }
Ejemplo n.º 6
0
 public ElementPair(ElementValue element, global::Part part) : this()
 {
     Element = element;
     Part = part;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Builds the first element in the queue
        /// </summary>
        /// <param name="vessel">The vessel that you want to crawl for elements</param>
        /// <param name="elements">The final element list, is it included here to have the root element added</param>
        /// <param name="shared">the ever present shared object</param>
        /// <returns>a queue with a starting entry</returns>
        private static Queue<ElementPair> InitQueue(Vessel vessel, Dictionary<uint, ElementValue> elements, SharedObjects shared)
        {
            var toReturn = new Queue<ElementPair>();

            var rootUid = vessel.rootPart.flightID;
            var rootInfo = new DockedVesselInfo
            {
                name = vessel.vesselName,
                rootPartUId = rootUid,
                vesselType = vessel.vesselType
            };
            var rootElement = new ElementValue(rootInfo, shared);
            elements.Add(rootUid, rootElement);
            toReturn.Enqueue(new ElementPair(rootElement, vessel.rootPart));
            return toReturn;
        }
Ejemplo n.º 8
0
        private static void EnqueueChildren(Queue<ElementPair> queue, ElementValue element, global::Part part)
        {
            if (!part.children.Any()) return;

            foreach (var child in part.children)
            {
                queue.Enqueue(new ElementPair(element,child));
            }
        }