run method
void
run()
Run collision detection for the current state of items.
Implementation
void run() {
broadphase.update();
final potentials = broadphase.query();
_currentPotentials.clear();
for (final potential in potentials) {
_currentPotentials.add(potential);
final itemA = potential.a;
final itemB = potential.b;
if (itemA.possiblyIntersects(itemB)) {
final intersectionPoints = intersections(itemA, itemB);
if (intersectionPoints.isNotEmpty) {
if (!itemA.collidingWith(itemB)) {
handleCollisionStart(intersectionPoints, itemA, itemB);
}
handleCollision(intersectionPoints, itemA, itemB);
} else if (itemA.collidingWith(itemB)) {
handleCollisionEnd(itemA, itemB);
}
} else if (itemA.collidingWith(itemB)) {
handleCollisionEnd(itemA, itemB);
}
}
// Handles callbacks for an ended collision that the broadphase didn't
// report as a potential collision anymore.
for (final prospect in _lastProspectPool) {
if (!_currentPotentials.contains(prospect) &&
prospect.a.collidingWith(prospect.b)) {
handleCollisionEnd(prospect.a, prospect.b);
}
}
_updateLastPotentials(potentials);
// Let all listeners know that the collision detection step has completed
collisionsCompletedNotifier.notifyListeners();
}