public void RetrieveNonAlloc(List <QTCircleCollider> toFill, QTCircleCollider collider) { Rect bounds = collider.GetGlobalBounds(); dynamicQT.RetrieveNonAlloc(toFill, bounds); staticQT.RetrieveNonAlloc(toFill, bounds); }
// ------------------------------------------------ // This algo remove objects in O(n) // ------------------------------------------------ void FilterListWithCircleCircleCollision(List <QTCircleCollider> list, QTCircleCollider collider) { int removeIndex = -1; int removeCount = 0; for (int i = 0; i < list.Count; i++) { QTCircleCollider c = list[i]; if (!Overlap(collider, c)) { removeCount++; if (removeIndex == -1) { removeIndex = i; } } else { if (removeIndex != -1) { // swap with the first remove item list[removeIndex] = c; removeIndex++; } } } if (removeIndex > -1) { list.RemoveRange(removeIndex, removeCount); } }
public List <QTCircleCollider> Retrieve(QTCircleCollider collider) { _buffer.Clear(); QuadTrees qt = _quadTrees[collider.layer]; qt.RetrieveNonAlloc(_buffer, collider); FilterListWithCircleCircleCollision(_buffer, collider); return(_buffer); }
public void Insert(QTCircleCollider collider) { QuadTree <QTCircleCollider> quadTree = collider.@static ? staticQT : dynamicQT; quadTree.Insert(collider, collider.GetGlobalBounds()); }
bool Overlap(QTCircleCollider a, QTCircleCollider b) { return(Vector2.Distance(a.center, b.center) < a.radius + b.radius); }
public void Register(QTCircleCollider collider) { QuadTrees qt = _quadTrees[collider.layer]; qt.Insert(collider); }