Question about contact listener

In my game I have square bodies for tiles, round bodies for players, balls and bullets and polygonal shapes for various other objects.

In my contact listener so far I've always duplicated all my code.

For example:

Code:
var actor1:Actor = point.shape1.GetBody().GetUserData() as Actor;
var actor2:Actor = point.shape2.GetBody().GetUserData() as Actor;

if ( ( actor1.ident == "ter" || actor1.ident == "object" ) && actor2.ident == "player" ){

   //do stuff with actor2

} else if ( actor1.ident == "player" && ( actor2.ident == "ter" || actor2.ident == "object" ) ){

   //do same stuff with actor1

}


Needless to say my contact listener file is getting huge with a lot of duplicate code. It works fine though. But it's getting pretty much unreadable...

I've been putting in some traces and came to the conclusion that my code duplicates seem to be useless. In the example above, the else statement never fires the player is always actor2 when it comes in contact with terrain or objects. So I was wondering what determines which body becomes shape1 and which becomes shape2 in the b2ContactPoint. Could it hurt for me to remove all the duplicate code, or is there a possibility that at some freak moments it will fire?

Alternatively I could I guess see which identity each actor has first, then swap them if need be. That would also save on code.
vedder wrote:
Alternatively I could I guess see which identity each actor has first, then swap them if need be. That would also save on code.

This. You should never be copy and pasting code.

Order of shapes is determined by order of creation, amongst other things, which might explain your results. Please don't rely on it always being so, you're setting yourself up for frustration.

Original thread: https://box2d.org/forum/viewtopic.php?t=3312