Page 1 of 1

cpSpaceAddCollisionPairFunc performance

Posted: Sun Jul 26, 2009 4:57 pm
by matiasmak
I'm developing a game on the iPhone and use Chipmunk. I've noticed something about cpSpaceAddCollisionPairFunc. When I implemented more than one CollisionPairFunc the performance was suffering alot. But as soon as a only use one of the below the fps goes up.

Is this expected behavour? Should I only use one and inside that function determine what kind of collision it is? I can go either way but I want to know what is best from a performance point?

Code: Select all

cpSpaceAddCollisionPairFunc(space, 2, 1, &Damage, self);
cpSpaceAddCollisionPairFunc(space, 3, 1, &DamageMine, self);
cpSpaceAddCollisionPairFunc(space, 2, 0, &EnemyCollision, self);

Re: cpSpaceAddCollisionPairFunc performance

Posted: Mon Jul 27, 2009 9:14 am
by slembcke
I guess I've never really stress tested how much collision callbacks impact speed, but I would not expect it to be that much really. Do you have some numbers to back that up? Also, are you sure it's not your collision callbacks themselves that are expensive?

Re: cpSpaceAddCollisionPairFunc performance

Posted: Wed Aug 05, 2009 10:33 am
by rfkrakora
I've noticed this as well, but I have been looking into it and what I have is four walls ( top, right, left, bottom ) all of coll type = 6, and four bodies of coll type 1. What I think is going on for me is when the bodies are sitting on the bottom wall ( floor ) - I get tons of collisions all the time, so my fps when all bodies are on the floor is much lower than it is when they are all not touching the floor. I just have to figure out how to get one collision when they hit the floor and then not "bounce".

Maybe something similar is happening for you?

-RK

Re: cpSpaceAddCollisionPairFunc performance

Posted: Wed Aug 05, 2009 1:13 pm
by slembcke
That's a different issue. When objects are touching it means that Chipmunk has to process the collisions. When they are all in the air and not touching the most expensive part of the physics, the impulse solver, doesn't have anything to do.