Where should the collision response/resolution code go?

I've got a collision response/resolution function that does the same for any pair of two entities. It's is in the World class right now.

But right before that function is invoked, I have some entity-specific logic:

1. A specific pair of entities should never have their collisions resolved (this is literally to keep the player from hitting itself with a carried object)
2. When two specific entities collide, an event should be triggered

Because of this, I'm starting to wonder if I should move the collision resolution function as a method into Entity, that'd allow me to use polymorphism. However, this sound very messy to me: If both entities involved in a collision can resolve it, how can I figure out which one should do it?

Is there another way to move these special cases out of World?

• I would move this entire system into PhysicsEngine and let World be just the data storage & IO. Regardless, perhaps you could create a CollisionCallback class store a multi-map indexed by canonical pairs of entities. – MickLH Feb 3 '14 at 14:59

                    Contacts         Reduced Contacts

Instead of calling two virtual methods for each contact pair, I'd build a table mapping predicates and events to a pair of collision types (which are stored in the contact data). For example, if you wanted to have an item that disabled collisions between the player and certain walls, you could add a predicate to the table that always returned False (destroying the contact in the process) for contacts between Players and PassThroughWalls. If you needed it, adding scripting support to this contact modification table would be quite easy.