public void CloseAndCacheCell(ref ClosedCellInfo output)
        {
            Debug.Assert(m_cellOpen, "Closing a cell in TriangleComponentMapping, but no cell is open!");

            CellInfo info = new CellInfo();
            bool     reallocateIndices = true;

            if (m_cellInfos.TryGetValue(m_cellCoord, out info))
            {
                output.NewCell          = false;
                output.OldComponentNum  = info.ComponentNum;
                output.OldStartingIndex = info.StartingIndex;

                if (info.ComponentNum == m_componentNum)
                {
                    reallocateIndices  = false;
                    info.ComponentNum  = output.OldComponentNum;
                    info.StartingIndex = output.OldStartingIndex;
                }
            }
            else
            {
                output.NewCell = true;
            }

            if (reallocateIndices)
            {
                info.ComponentNum  = m_componentNum;
                info.StartingIndex = AllocateComponentStartingIndex(m_componentNum);

                // Remove containing cell information from the old cell indices
                if (output.NewCell == false)
                {
                    DeallocateComponentStartingIndex(output.OldStartingIndex, output.OldComponentNum);
                    for (int i = 0; i < output.OldComponentNum; i++)
                    {
                        m_componentCells.Remove(output.OldStartingIndex + i);
                    }
                }

                // Save information about containing cell to the newly allocated cell indices
                for (int i = 0; i < info.ComponentNum; ++i)
                {
                    m_componentCells[info.StartingIndex + i] = m_cellCoord;
                }
            }

            m_cellInfos[m_cellCoord] = info;

            output.ComponentNum       = info.ComponentNum;
            output.ExploredDirections = info.ExploredDirections;
            output.StartingIndex      = info.StartingIndex;

            m_components   = null;
            m_componentNum = 0;
            m_cellOpen     = false;
        }
Exemple #2
0
        public void CloseAndCacheCell(ref ClosedCellInfo output)
        {
            CellInfo info = new CellInfo();
            bool     flag = true;

            if (!this.m_cellInfos.TryGetValue(this.m_cellCoord, out info))
            {
                output.NewCell = true;
            }
            else
            {
                output.NewCell          = false;
                output.OldComponentNum  = info.ComponentNum;
                output.OldStartingIndex = info.StartingIndex;
                if (info.ComponentNum == this.m_componentNum)
                {
                    flag = false;
                    info.ComponentNum  = output.OldComponentNum;
                    info.StartingIndex = output.OldStartingIndex;
                }
            }
            if (flag)
            {
                info.ComponentNum  = this.m_componentNum;
                info.StartingIndex = this.AllocateComponentStartingIndex(this.m_componentNum);
                if (!output.NewCell)
                {
                    this.DeallocateComponentStartingIndex(output.OldStartingIndex, output.OldComponentNum);
                    for (int j = 0; j < output.OldComponentNum; j++)
                    {
                        this.m_componentCells.Remove(output.OldStartingIndex + j);
                    }
                }
                for (int i = 0; i < info.ComponentNum; i++)
                {
                    this.m_componentCells[info.StartingIndex + i] = this.m_cellCoord;
                }
            }
            this.m_cellInfos[this.m_cellCoord] = info;
            output.ComponentNum       = info.ComponentNum;
            output.ExploredDirections = info.ExploredDirections;
            output.StartingIndex      = info.StartingIndex;
            this.m_components         = null;
            this.m_componentNum       = 0;
            this.m_cellOpen           = false;
        }
        public void CloseAndCacheCell(ref ClosedCellInfo output)
        {
            Debug.Assert(m_cellOpen, "Closing a cell in TriangleComponentMapping, but no cell is open!");

            CellInfo info = new CellInfo();

            if (m_cellInfos.TryGetValue(m_cellCoord, out info))
            {
                // CH: TODO: Check this assert.
                Debug.Assert(m_componentNum == info.ComponentNum);

                output.NewCell = false;
            }
            else
            {
                info.ComponentNum  = m_componentNum;
                info.StartingIndex = m_currentStartingComponent;

                if (m_currentStartingComponent + m_componentNum > m_nextComponentIndex)
                {
                    m_nextComponentIndex = m_currentStartingComponent + m_componentNum;
                }

                output.NewCell = true;
            }

            // Save information about containing cell
            for (int i = 0; i < info.ComponentNum; ++i)
            {
                m_componentCells[info.StartingIndex + i] = m_cellCoord;
            }

            m_cellInfos[m_cellCoord] = info;

            output.ComponentNum       = info.ComponentNum;
            output.ExploredDirections = info.ExploredDirections;
            output.StartingIndex      = info.StartingIndex;

            m_components   = null;
            m_componentNum = 0;
            m_cellOpen     = false;
        }
        public void CloseAndCacheCell(ref ClosedCellInfo output)
        {
            Debug.Assert(m_cellOpen, "Closing a cell in TriangleComponentMapping, but no cell is open!");

            CellInfo info = new CellInfo();
            bool reallocateIndices = true;
            if (m_cellInfos.TryGetValue(m_cellCoord, out info))
            {
                output.NewCell = false;
                output.OldComponentNum = info.ComponentNum;
                output.OldStartingIndex = info.StartingIndex;

                if (info.ComponentNum == m_componentNum)
                {
                    reallocateIndices = false;
                    info.ComponentNum = output.OldComponentNum;
                    info.StartingIndex = output.OldStartingIndex;
                }
            }
            else
            {
                output.NewCell = true;
            }

            if (reallocateIndices)
            {
                info.ComponentNum = m_componentNum;
                info.StartingIndex = AllocateComponentStartingIndex(m_componentNum);
                
                // Remove containing cell information from the old cell indices
                if (output.NewCell == false)
                {
                    DeallocateComponentStartingIndex(output.OldStartingIndex, output.OldComponentNum);
                    for (int i = 0; i < output.OldComponentNum; i++)
                    {
                        m_componentCells.Remove(output.OldStartingIndex + i);
                    }
                }

                // Save information about containing cell to the newly allocated cell indices
                for (int i = 0; i < info.ComponentNum; ++i)
                {
                    m_componentCells[info.StartingIndex + i] = m_cellCoord;
                }
            }

            m_cellInfos[m_cellCoord] = info;

            output.ComponentNum = info.ComponentNum;
            output.ExploredDirections = info.ExploredDirections;
            output.StartingIndex = info.StartingIndex;

            m_components = null;
            m_componentNum = 0;
            m_cellOpen = false;
        }
        public void CloseAndCacheCell(ref ClosedCellInfo output)
        {
            Debug.Assert(m_cellOpen, "Closing a cell in TriangleComponentMapping, but no cell is open!");

            CellInfo info = new CellInfo();
            if (m_cellInfos.TryGetValue(m_cellCoord, out info))
            {
                // CH: TODO: Check this assert.
                Debug.Assert(m_componentNum == info.ComponentNum);

                output.NewCell = false;
            }
            else
            {
                info.ComponentNum = m_componentNum;
                info.StartingIndex = m_currentStartingComponent;

                if (m_currentStartingComponent + m_componentNum > m_nextComponentIndex)
                {
                    m_nextComponentIndex = m_currentStartingComponent + m_componentNum;
                }

                output.NewCell = true;
            }

            // Save information about containing cell
            for (int i = 0; i < info.ComponentNum; ++i)
            {
                m_componentCells[info.StartingIndex + i] = m_cellCoord;
            }

            m_cellInfos[m_cellCoord] = info;

            output.ComponentNum = info.ComponentNum;
            output.ExploredDirections = info.ExploredDirections;
            output.StartingIndex = info.StartingIndex;

            m_components = null;
            m_componentNum = 0;
            m_cellOpen = false;
        }