Beispiel #1
0
 private void DisconnectSmallToLargeBlock(MySlimBlock smallBlock, MyCubeGrid smallGrid, MySlimBlock largeBlock, MyCubeGrid largeGrid)
 {
     if (((GetCubeSize(smallBlock) == MyCubeSize.Small) && ((GetCubeSize(largeBlock) == MyCubeSize.Large) && !(smallBlock.FatBlock is MyCompoundCubeBlock))) && !(largeBlock.FatBlock is MyCompoundCubeBlock))
     {
         HashSet <MySlimBlockPair> set;
         HashSet <MySlimBlockPair> set2;
         long linkId = (largeBlock.UniqueId << 0x20) + smallBlock.UniqueId;
         MyCubeGridGroups.Static.SmallToLargeBlockConnections.BreakLink(linkId, largeBlock, null);
         MyCubeGridGroups.Static.Physical.BreakLink(linkId, largeGrid, null);
         MyCubeGridGroups.Static.Logical.BreakLink(linkId, largeGrid, null);
         MySlimBlockPair item = new MySlimBlockPair {
             Parent = largeBlock,
             Child  = smallBlock
         };
         if (this.m_mapLargeGridToConnectedBlocks.TryGetValue(largeGrid, out set))
         {
             set.Remove(item);
             if (set.Count == 0)
             {
                 this.m_mapLargeGridToConnectedBlocks.Remove(largeGrid);
                 largeGrid.OnClosing -= new Action <VRage.Game.Entity.MyEntity>(this.CubeGrid_OnClosing);
             }
         }
         if (this.m_mapSmallGridToConnectedBlocks.TryGetValue(smallGrid, out set2))
         {
             set2.Remove(item);
             if (set2.Count == 0)
             {
                 this.m_mapSmallGridToConnectedBlocks.Remove(smallGrid);
                 smallGrid.OnClosing -= new Action <VRage.Game.Entity.MyEntity>(this.CubeGrid_OnClosing);
             }
         }
     }
 }
Beispiel #2
0
 private void ConnectSmallToLargeBlock(MySlimBlock smallBlock, MySlimBlock largeBlock)
 {
     if (((GetCubeSize(smallBlock) == MyCubeSize.Small) && ((GetCubeSize(largeBlock) == MyCubeSize.Large) && !(smallBlock.FatBlock is MyCompoundCubeBlock))) && !(largeBlock.FatBlock is MyCompoundCubeBlock))
     {
         long linkId = (largeBlock.UniqueId << 0x20) + smallBlock.UniqueId;
         if (!MyCubeGridGroups.Static.SmallToLargeBlockConnections.LinkExists(linkId, largeBlock, null))
         {
             HashSet <MySlimBlockPair> set;
             HashSet <MySlimBlockPair> set2;
             MyCubeGridGroups.Static.SmallToLargeBlockConnections.CreateLink(linkId, largeBlock, smallBlock);
             MyCubeGridGroups.Static.Physical.CreateLink(linkId, largeBlock.CubeGrid, smallBlock.CubeGrid);
             MyCubeGridGroups.Static.Logical.CreateLink(linkId, largeBlock.CubeGrid, smallBlock.CubeGrid);
             MySlimBlockPair item = new MySlimBlockPair {
                 Parent = largeBlock,
                 Child  = smallBlock
             };
             if (!this.m_mapLargeGridToConnectedBlocks.TryGetValue(largeBlock.CubeGrid, out set))
             {
                 set = new HashSet <MySlimBlockPair>();
                 this.m_mapLargeGridToConnectedBlocks.Add(largeBlock.CubeGrid, set);
                 largeBlock.CubeGrid.OnClosing += new Action <VRage.Game.Entity.MyEntity>(this.CubeGrid_OnClosing);
             }
             set.Add(item);
             if (!this.m_mapSmallGridToConnectedBlocks.TryGetValue(smallBlock.CubeGrid, out set2))
             {
                 set2 = new HashSet <MySlimBlockPair>();
                 this.m_mapSmallGridToConnectedBlocks.Add(smallBlock.CubeGrid, set2);
                 smallBlock.CubeGrid.OnClosing += new Action <VRage.Game.Entity.MyEntity>(this.CubeGrid_OnClosing);
             }
             set2.Add(item);
         }
     }
 }
        /// <summary>
        /// Adds small/large block connection.
        /// </summary>
        private void ConnectSmallToLargeBlock(MySlimBlock smallBlock, MySlimBlock largeBlock)
        {
            Debug.Assert(GetCubeSize(smallBlock) == MyCubeSize.Small);
            Debug.Assert(GetCubeSize(largeBlock) == MyCubeSize.Large);
            Debug.Assert(!(smallBlock.FatBlock is MyCompoundCubeBlock));
            Debug.Assert(!(largeBlock.FatBlock is MyCompoundCubeBlock));

            if (GetCubeSize(smallBlock) != MyCubeSize.Small || GetCubeSize(largeBlock) != MyCubeSize.Large ||
                (smallBlock.FatBlock is MyCompoundCubeBlock) || (largeBlock.FatBlock is MyCompoundCubeBlock))
            {
                return;
            }

            // Block link
            long linkId = ((long)largeBlock.UniqueId << 32) + smallBlock.UniqueId;

            if (MyCubeGridGroups.Static.SmallToLargeBlockConnections.LinkExists(linkId, largeBlock, null))
            {
                //Debug.WriteLine("Link exist id: "  + linkId + " " + largeBlock + " " + smallBlock);
                return;
            }
            MyCubeGridGroups.Static.SmallToLargeBlockConnections.CreateLink(linkId, largeBlock, smallBlock);

            // Grid link
            MyCubeGridGroups.Static.Physical.CreateLink(linkId, largeBlock.CubeGrid, smallBlock.CubeGrid);
            MyCubeGridGroups.Static.Logical.CreateLink(linkId, largeBlock.CubeGrid, smallBlock.CubeGrid);

            // Remember link
            MySlimBlockPair pair = new MySlimBlockPair();

            pair.Parent = largeBlock;
            pair.Child  = smallBlock;

            {
                HashSet <MySlimBlockPair> slimBlockPairs;
                if (!m_mapLargeGridToConnectedBlocks.TryGetValue(largeBlock.CubeGrid, out slimBlockPairs))
                {
                    slimBlockPairs = new HashSet <MySlimBlockPair>();
                    m_mapLargeGridToConnectedBlocks.Add(largeBlock.CubeGrid, slimBlockPairs);
                    largeBlock.CubeGrid.OnClosing += CubeGrid_OnClosing;
                }
                slimBlockPairs.Add(pair);
            }

            {
                HashSet <MySlimBlockPair> slimBlockPairs;
                if (!m_mapSmallGridToConnectedBlocks.TryGetValue(smallBlock.CubeGrid, out slimBlockPairs))
                {
                    slimBlockPairs = new HashSet <MySlimBlockPair>();
                    m_mapSmallGridToConnectedBlocks.Add(smallBlock.CubeGrid, slimBlockPairs);
                    smallBlock.CubeGrid.OnClosing += CubeGrid_OnClosing;
                }
                slimBlockPairs.Add(pair);
            }

            //Debug.WriteLine("Link created id: " + linkId + " " + largeBlock + " " + smallBlock);
        }
        /// <summary>
        /// Removes small/large block connection. Note that grids in parameters can be different from the ones in slimblock! Used for grid splits, etc.
        /// </summary>
        private void DisconnectSmallToLargeBlock(MySlimBlock smallBlock, MyCubeGrid smallGrid, MySlimBlock largeBlock, MyCubeGrid largeGrid)
        {
            Debug.Assert(smallGrid.GridSizeEnum == MyCubeSize.Small);
            Debug.Assert(largeGrid.GridSizeEnum == MyCubeSize.Large);
            Debug.Assert(!(smallBlock.FatBlock is MyCompoundCubeBlock));
            Debug.Assert(!(largeBlock.FatBlock is MyCompoundCubeBlock));

            if (smallBlock.CubeGrid.GridSizeEnum != MyCubeSize.Small || largeBlock.CubeGrid.GridSizeEnum != MyCubeSize.Large ||
                (smallBlock.FatBlock is MyCompoundCubeBlock) || (largeBlock.FatBlock is MyCompoundCubeBlock))
            {
                return;
            }

            // Block link
            long linkId = ((long)largeBlock.UniqueId << 32) + smallBlock.UniqueId;

            MyCubeGridGroups.Static.SmallToLargeBlockConnections.BreakLink(linkId, largeBlock, null);

            // Grid link
            bool removedPhysical = MyCubeGridGroups.Static.Physical.BreakLink(linkId, largeGrid, null);
            bool removedLogical  = MyCubeGridGroups.Static.Logical.BreakLink(linkId, largeGrid, null);

            // Remove link from maps
            MySlimBlockPair pair = new MySlimBlockPair();

            pair.Parent = largeBlock;
            pair.Child  = smallBlock;

            {
                HashSet <MySlimBlockPair> slimBlockPairs;
                if (m_mapLargeGridToConnectedBlocks.TryGetValue(largeGrid, out slimBlockPairs))
                {
                    bool removed = slimBlockPairs.Remove(pair);
                    Debug.Assert(removed);
                    if (slimBlockPairs.Count == 0)
                    {
                        m_mapLargeGridToConnectedBlocks.Remove(largeGrid);
                    }
                }
                else
                {
                    Debug.Fail("Small to large block connection not found in map");
                }
            }

            {
                HashSet <MySlimBlockPair> slimBlockPairs;
                if (m_mapSmallGridToConnectedBlocks.TryGetValue(smallGrid, out slimBlockPairs))
                {
                    bool removed = slimBlockPairs.Remove(pair);
                    Debug.Assert(removed);
                    if (slimBlockPairs.Count == 0)
                    {
                        m_mapSmallGridToConnectedBlocks.Remove(smallGrid);
                    }
                }
                else
                {
                    Debug.Fail("Small to large block connection not found in map");
                }
            }

            //Debug.WriteLine("Link removed id: " + linkId + " " + largeBlock + " " + smallBlock);
        }