/// <summary> /// Removes all items from the given cell. /// If the items don't occupy another cell, they are removed as well. /// </summary> /// <param name="cell">The cell to remove items from</param> public void Remove(Point cell) { lock (lockObject) { Point c = Clamp(cell); List <T> l; Grid.TryGetValue(c, out l); if (l != null) { foreach (T i in l) { List <Point> pl; ItemDictionary.TryGetValue(i, out pl); if (pl != null) { pl.Remove(c); if (pl.Count == 0) { ListOfPointQueue.Enqueue(pl); ItemDictionary.Remove(i); } } } l.Clear(); ListOfItemQueue.Enqueue(l); Grid.Remove(cell); } } }
private void AddToItems(T item, Point cell) { List <Point> pl; ItemDictionary.TryGetValue(item, out pl); if (pl == null) { if (ListOfPointQueue.Count > 0) { pl = ListOfPointQueue.Dequeue(); } else { pl = new List <Point>(); } pl.Add(cell); ItemDictionary.Add(item, pl); } else { if (!pl.Contains(cell)) { pl.Add(cell); } } }
public void Dispose() { lock (lockObject) { ListOfPointQueue.Clear(); ListOfPointQueue = null; ListOfItemQueue.Clear(); ListOfItemQueue = null; Grid.Clear(); Grid = null; ItemDictionary.Clear(); ItemDictionary = null; } }
/// <summary> /// Removes the given item from the grid. /// </summary> /// <param name="item">The item to remove</param> public void Remove(T item) { lock (lockObject) { List <Point> pl; ItemDictionary.TryGetValue(item, out pl); if (pl == null) { return; } foreach (Point p in pl) { RemoveFromGrid(item, p); } pl.Clear(); ListOfPointQueue.Enqueue(pl); ItemDictionary.Remove(item); } }