private void ComputeMountPoints(MyObjectBuilder_CubeGrid primaryGrid, IEnumerable <MyObjectBuilder_CubeGrid> allGrids, BlockSetInfo info) { m_mountPoints.Clear(); foreach (var block in primaryGrid.CubeBlocks) { foreach (var name in block.ConfigNames()) { if (!name.StartsWithICase(MountPrefix)) { continue; } var parts = PartDummyUtils.ConfigArguments(name.Substring(MountPrefix.Length)).ToArray(); if (parts.Length < 3) { continue; } var spec = parts[0].Split(':'); if (spec.Length != 2) { continue; } var mountType = spec[0]; var mountPiece = spec[1]; var mountName = parts[1]; Dictionary <string, PartMount> partsOfType; if (!m_mountPoints.TryGetValue(mountType, out partsOfType)) { partsOfType = m_mountPoints[mountType] = new Dictionary <string, PartMount>(); } PartMount mount; if (!partsOfType.TryGetValue(mountName, out mount)) { mount = partsOfType[mountName] = new PartMount(this, mountType, mountName); } var args = new string[parts.Length - 2]; for (var i = 2; i < parts.Length; i++) { args[i - 2] = parts[i]; } var pmpb = new PartMountPointBlock(mount); pmpb.Init(block, mountPiece, args); mount.Add(pmpb); } } m_mountPointBlocks.Clear(); foreach (var mount in MountPoints) { foreach (var block in mount.Blocks) { m_mountPointBlocks[block.AnchorLocation] = block; } } }
public IEnumerable <MatrixI> GetTransform(PartMount otherMount) { HashSet <MatrixI> output; if (MountCache.TryGet(MyTuple.Create(otherMount, this), out output)) { return(output?.Select(x => { MatrixI val; MatrixI.Invert(ref x, out val); return val; })); } return(MountCache.GetOrCreate(MyTuple.Create(this, otherMount), GetTransformInternal)); }
public PartMount MountPoint(string typeID, string instanceID) { using (LockSharedUsing()) { Dictionary <string, PartMount> instan; if (!m_mountPoints.TryGetValue(typeID, out instan)) { return(null); } PartMount part = null; if (instan?.TryGetValue(instanceID, out part) ?? false) { return(part); } return(null); } }
public virtual void Init(Ob_Part v) { BlockSetInfo.BlockCountByType.Clear(); foreach (var kv in v.BlockCountByType) { BlockSetInfo.BlockCountByType[kv.Item1] = kv.Item2; } BlockSetInfo.ComponentCost.Clear(); foreach (var kv in v.ComponentCost) { BlockSetInfo.ComponentCost[MyDefinitionManager.Static.GetComponentDefinition(kv.Item1)] = kv.Item2; } m_blocks.Clear(); foreach (var kv in v.OccupiedLocations) { m_blocks[kv] = null; } BlockSetInfo.PowerConsumptionByGroup.Clear(); foreach (var kv in v.PowerConsumptionByGroup) { BlockSetInfo.PowerConsumptionByGroup[kv.Item1] = kv.Item2; } m_reservedSpaces.Clear(); m_reservedSpaces.AddRange(v.ReservedSpaces.Select(x => new ReservedSpace(x))); m_mountPoints.Clear(); m_mountPointBlocks.Clear(); foreach (var mp in v.MountPoints) { var block = new PartMount(this, mp.Type, mp.Name); block.Init(mp); Dictionary <string, PartMount> partsOfType; if (!m_mountPoints.TryGetValue(mp.Type, out partsOfType)) { partsOfType = m_mountPoints[mp.Type] = new Dictionary <string, PartMount>(); } partsOfType[mp.Name] = block; foreach (var kv in block.Blocks) { m_mountPointBlocks[kv.AnchorLocation] = kv; } } // Load AABBs BoundingBox = BoundingBox.CreateInvalid(); foreach (var p in v.OccupiedLocations) { BoundingBox = BoundingBox.Include((Vector3I)p); } ReservedSpace = BoundingBox.CreateInvalid(); foreach (var r in v.ReservedSpaces) { ReservedSpace = ReservedSpace.Include(r.Min); ReservedSpace = ReservedSpace.Include(r.Max); } BlockSetInfo.UpdateCache(); Logger.Info("Loaded {0} lazily with {1} mount points, {2} reserved spaces, and {3} occupied cubes.", Name, MountPoints.Count(), m_reservedSpaces.Count, m_blocks.Count); foreach (var type in MountPointTypes) { Logger.Info(" ...of type \"{0}\" there are {1}", type, MountPointsOfType(type).Count()); } }
public PartMountPointBlock(PartMount owner) { Owner = owner; }