cpSpaceAddCollisionPairFunc performance

Official forum for the Chipmunk2D Physics Library.
Post Reply
matiasmak
Posts: 1
Joined: Sun Jul 26, 2009 4:49 pm
Contact:

cpSpaceAddCollisionPairFunc performance

Post 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);
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpSpaceAddCollisionPairFunc performance

Post 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?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
rfkrakora
Posts: 12
Joined: Mon Jun 29, 2009 10:53 pm
Contact:

Re: cpSpaceAddCollisionPairFunc performance

Post 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
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpSpaceAddCollisionPairFunc performance

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests