Not only there are two useful broad-phase algorithms and a lot of useful narrowphase algorithms, there are also multiple code styles.
Arrays vs. calling
Make an array of broadphase checks, then filter them with narrowphase checks, then resolve them.
function resolveCollisions(thingyStructure * a,thingyStructure * b,int index){
possibleCollisions = getPossibleCollisions(b,a->get(index));
for(i=0; i<possibleCollitionsNumber; i++){
if(narrowphase(possibleCollisions[i],a[index])) {
collisions->push(possibleCollisions[i]);
};
};
for(i=0; i<collitionsNumber; i++){
//CODE FOR RESOLUTION
};
};
Make the broadphase call the narrowphase, and the narrowphase call the resolution
function resolveCollisions(thingyStructure * a,thingyStructure * b,int index){
broadphase(b,a->get(index));
};
function broadphase(thingy * with, thingy * what){
while(blah){
//blahcode
narrowphase(what,collidingThing);
};
};
Events vs. in-the-loop
Fire an event. This abstracts the check away, but it's trickier to make an equal interaction.
a[index] -> collisionEvent(eventdata);
//much later
int collisionEvent(eventdata){
//resolution gets here
}
Resolve the collision inside the loop. This glues narrowphase and resolution into one layer.
if(narrowphase(possibleCollisions[i],a[index])) {
//CODE GOES HERE
};
The questions are: Which of the first two is better, and how am I supposed to make a zero-sum Newtonian interaction under B1.