Exemple #1
0
        internal bool TryGetCell(ref Int2 cellIndex, out GridCell2D cell)
        {
            int index;
            int sortingHash;

            if (TryGetIndex(ref cellIndex, out index, out sortingHash))
            {
                cell = cells.Elements[index];
                return(true);
            }

            cell = null;
            return(false);
        }
Exemple #2
0
        internal void Add(ref Int2 index, Grid2DEntry entry)
        {
            int cellIndex;
            int sortingHash;

            if (TryGetIndex(ref index, out cellIndex, out sortingHash))
            {
                cells.Elements[cellIndex].Add(entry);
                return;
            }

            GridCell2D cell = cellPool.Take();

            cell.Initialize(ref index, sortingHash);
            cell.Add(entry);
            cells.Insert(cellIndex, cell);
            count++;
        }
Exemple #3
0
        internal void Remove(ref Int2 index, Grid2DEntry entry)
        {
            int cellIndex;
            int sortingHash;

            if (TryGetIndex(ref index, out cellIndex, out sortingHash))
            {
                cells.Elements[cellIndex].Remove(entry);
                if (cells.Elements[cellIndex].entries.Count == 0)
                {
                    //The cell is now empty.  Give it back to the pool.
                    GridCell2D toRemove = cells.Elements[cellIndex];
                    //There's no cleanup to do on the grid cell.
                    //Its list is empty, and the rest is just value types.
                    cells.RemoveAt(cellIndex);
                    cellPool.GiveBack(toRemove);
                    count--;
                }
            }
        }