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)); } }
/// <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); }
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); } } }
public ElementPair(ElementValue element, global::Part part) : this() { Element = element; Part = part; }
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); } } }
public ElementPair(ElementValue element, global::Part part) : this() { Element = element; Part = part; }
/// <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; }
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)); } }