public Node Clear( IsoIPool <Node> node_pool, IsoIPool <Item> item_pool) { ClearNodes(node_pool, item_pool); ClearItems(item_pool); return(Init(null, IsoRect.zero)); }
public bool AddItem( IsoRect bounds, T content, out Item item, IsoIPool <Node> node_pool, IsoIPool <Item> item_pool) { if (!SelfBounds.Contains(bounds)) { item = null; return(false); } for (int i = 0, e = Nodes.Length; i < e; ++i) { var node = Nodes[i]; if (node != null) { if (node.AddItem(bounds, content, out item, node_pool, item_pool)) { return(true); } } else if (Items.Count >= MinChildCountPerNode && NodeBounds[i].Contains(bounds)) { Nodes[i] = node = node_pool.Take().Init(this, NodeBounds[i]); if (node.AddItem(bounds, content, out item, node_pool, item_pool)) { return(true); } } } item = item_pool.Take().Init(this, bounds, content); Items.Add(item); return(true); }
// --------------------------------------------------------------------- // // Public // // --------------------------------------------------------------------- public IsoQuadTree(int capacity) { _qtId = ++_genQTId; _rootNode = null; _nodePool = new NodePool(capacity); _itemPool = new ItemPool(_qtId, capacity); }
void ClearItems(IsoIPool <Item> item_pool) { for (int i = 0, e = Items.Count; i < e; ++i) { var item = Items[i]; item_pool.Release(item.Clear()); } Items.Clear(); }
public void RemoveItem(Item item, IsoIPool <Item> item_pool) { if (item != null && item.Owner == this && Items.Remove(item)) { item_pool.Release(item.Clear()); } else { throw new System.ArgumentException("IsoQuadTree logic error", "item"); } }
void ClearNodes(IsoIPool <Node> node_pool, IsoIPool <Item> item_pool) { for (int i = 0, e = Nodes.Length; i < e; ++i) { var node = Nodes[i]; if (node != null) { node_pool.Release(node.Clear(node_pool, item_pool)); } } System.Array.Clear(Nodes, 0, Nodes.Length); }
public bool CleanUpNodes( IsoIPool <Node> node_pool, IsoIPool <Item> item_pool) { var has_any_busy_nodes = false; for (int i = 0, e = Nodes.Length; i < e; ++i) { var node = Nodes[i]; if (node != null) { if (node.CleanUpNodes(node_pool, item_pool)) { node_pool.Release( node.Clear(node_pool, item_pool)); Nodes[i] = null; } else { has_any_busy_nodes = true; } } } return(!has_any_busy_nodes && Items.Count == 0); }