public bool Disconnect(MyCubeGrid grid, MySlimBlock testBlock = null, bool testDisconnect = false)
        {
            ProfilerShort.Begin("Collect+IsInVoxels");
            m_largestGroupWithPhysics = default(Group);
            m_groups.Clear();
            m_sortedBlocks.Clear();
            m_disconnectHelper.Clear();
            foreach (var block in grid.GetBlocks())
            {
                if (block == testBlock)
                {
                    continue;
                }

                m_disconnectHelper.Add(block);
            }
            ProfilerShort.End();

            ProfilerShort.Begin("GroupBy");
            while (m_disconnectHelper.Count > 0)
            {
                Group group = default(Group);
                group.FirstBlockIndex = m_sortedBlocks.Count;
                AddNeighbours(m_disconnectHelper.FirstElement(), out group.IsValid, testBlock);
                group.BlockCount = m_sortedBlocks.Count - group.FirstBlockIndex;

                if (group.IsValid && group.BlockCount > m_largestGroupWithPhysics.BlockCount)
                {
                    if (m_largestGroupWithPhysics.BlockCount > 0) // Is valid
                    {
                        // order matters, insert in correct place
                        int i = 0;
                        for (i = 0; i < m_groups.Count; i++)
                        {
                            if (m_groups[i].FirstBlockIndex > m_largestGroupWithPhysics.FirstBlockIndex)
                            {
                                m_groups.Insert(i, m_largestGroupWithPhysics);
                                break;
                            }
                        }

                        if (i == m_groups.Count)
                        {
                            m_groups.Add(m_largestGroupWithPhysics);
                        }
                    }

                    m_largestGroupWithPhysics = group;
                }
                else
                {
                    m_groups.Add(group);
                }
            }
            ProfilerShort.End();

            ProfilerShort.Begin("RemoveLargestGroup");
            m_sortedBlocks.RemoveRange(m_largestGroupWithPhysics.FirstBlockIndex, m_largestGroupWithPhysics.BlockCount);
            for (int i = 0; i < m_groups.Count; i++)
            {
                var g = m_groups[i];
                if (g.FirstBlockIndex > m_largestGroupWithPhysics.FirstBlockIndex)
                {
                    g.FirstBlockIndex -= m_largestGroupWithPhysics.BlockCount;
                    m_groups[i]        = g;
                }
            }
            ProfilerShort.End();

            ProfilerShort.Begin("CreateSplits");
            if (m_groups.Count > 0)
            {
                if (testDisconnect)
                {
                    m_groups.Clear();
                    m_sortedBlocks.Clear();
                    m_disconnectHelper.Clear();
                    ProfilerShort.End();
                    return(true);
                }
                MyCubeGrid.CreateSplits(grid, m_sortedBlocks, m_groups);
            }
            else
            {
                if (!MySession.Static.Settings.StationVoxelSupport)
                {
                    if (grid.IsStatic)
                    {
                        grid.TestDynamic = MyCubeGrid.MyTestDynamicReason.GridSplit;
                    }
                }
            }
            ProfilerShort.End();

            m_groups.Clear();
            m_sortedBlocks.Clear();
            m_disconnectHelper.Clear();
            return(false);
        }
Example #2
0
        public void Disconnect(MyCubeGrid grid)
        {
            ProfilerShort.Begin("Collect+IsInVoxels");
            m_largestGroupWithPhysics = default(Group);
            m_groups.Clear();
            m_sortedBlocks.Clear();
            m_disconnectHelper.Clear();
            foreach (var block in grid.GetBlocks())
            {
                m_disconnectHelper.Add(block);
            }
            ProfilerShort.End();

            ProfilerShort.Begin("GroupBy");
            while (m_disconnectHelper.Count > 0)
            {
                Group group = default(Group);
                group.FirstBlockIndex = m_sortedBlocks.Count;
                AddNeighbours(m_disconnectHelper.FirstElement(), out group.IsValid);
                group.BlockCount = m_sortedBlocks.Count - group.FirstBlockIndex;

                if (group.IsValid && group.BlockCount > m_largestGroupWithPhysics.BlockCount)
                {
                    if (m_largestGroupWithPhysics.BlockCount > 0) // Is valid
                    {
                        // order matters, insert in correct place
                        int i = 0;
                        for (i = 0; i < m_groups.Count; i++)
                        {
                            if (m_groups[i].FirstBlockIndex > m_largestGroupWithPhysics.FirstBlockIndex)
                            {
                                m_groups.Insert(i, m_largestGroupWithPhysics);
                                break;
                            }
                        }

                        if (i == m_groups.Count)
                        {
                            m_groups.Add(m_largestGroupWithPhysics);
                        }
                    }

                    m_largestGroupWithPhysics = group;
                }
                else
                {
                    m_groups.Add(group);
                }
            }
            ProfilerShort.End();

            ProfilerShort.Begin("RemoveLargestGroup");
            m_sortedBlocks.RemoveRange(m_largestGroupWithPhysics.FirstBlockIndex, m_largestGroupWithPhysics.BlockCount);
            for (int i = 0; i < m_groups.Count; i++)
            {
                var g = m_groups[i];
                if (g.FirstBlockIndex > m_largestGroupWithPhysics.FirstBlockIndex)
                {
                    g.FirstBlockIndex -= m_largestGroupWithPhysics.BlockCount;
                    m_groups[i]        = g;
                }
            }
            ProfilerShort.End();

            ProfilerShort.Begin("CreateSplits");
            if (m_groups.Count > 0)
            {
                MyCubeGrid.CreateSplits(grid, m_sortedBlocks, m_groups);
            }
            ProfilerShort.End();



            m_groups.Clear();
            m_sortedBlocks.Clear();
            m_disconnectHelper.Clear();
        }