public void Execute() { while (movingParticles.Count > 0) { MovingEntity movingParticle = movingParticles.Dequeue(); // remove from old cell: int cellIndex; if (grid.TryGetCellIndex(movingParticle.oldCellCoord, out cellIndex)) { var oldCell = grid.usedCells[cellIndex]; oldCell.Remove(movingParticle.entity); grid.usedCells[cellIndex] = oldCell; } // add to new cell: cellIndex = grid.GetOrCreateCell(movingParticle.newCellCoord); var newCell = grid.usedCells[cellIndex]; newCell.Add(movingParticle.entity); grid.usedCells[cellIndex] = newCell; } grid.RemoveEmpty(); }
public void Execute() { while (movingColliders.Count > 0) { MovingCollider movingCollider = movingColliders.Dequeue(); // remove from old cells: grid.RemoveFromCells(movingCollider.oldSpan, movingCollider.entity); // insert in new cells, as long as the index is below the amount of colliders. // otherwise, the collider is at the "tail" and there's no need to add it back. if (movingCollider.entity < colliderCount) grid.AddToCells(movingCollider.newSpan, movingCollider.entity); } // remove all empty cells from the grid: grid.RemoveEmpty(); }