Low fps with Chipmunk

Official forum for the Chipmunk2D Physics Library.
korki696
Posts: 24
Joined: Wed Jul 15, 2009 2:15 am
Contact:

Low fps with Chipmunk

Post by korki696 »

Hey all,
So i got my game working pretty well on the simulator so i decided to pay the $99 and i put it on my iphone and i noticed during gameplay i only get 30fps and i narrowed it down to being chipmunk thats causing it. What i have right now are 6 larger active shapes that are players, 3 larger static shapes that are objects and 30 total projectiles. i never add more i only remove players when they die.

My first question is does chipmunk slow down if bodies are touching eventhough there is no collision callback on them? for example my projectiles are al in the same place. could this slow down my game?

Second is the cpSpaceResizeActiveHash and StaticHash. I understand that dim should be 1/2 the size of the average size? my question is how do i find the size? and the count i understand.

Is there anything else i could change?
Thanks
-Lars
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Low fps with Chipmunk

Post by slembcke »

First, you should read the draft of the new wiki page I wrote, it might answer some questions: http://code.google.com/p/chipmunk-physi ... nDetection

You don't really find the size, you just estimate what you think it will be on average. It's not going to be that sensitive exactly.

The most expensive part in Chipmunk is processing touching objects, so that should answer your other question. ;) Have you tried using fewer solver iterations? (space->iterations)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
korki696
Posts: 24
Joined: Wed Jul 15, 2009 2:15 am
Contact:

Re: Low fps with Chipmunk

Post by korki696 »

Hey,
So having touching objects be the most memory expensive makes sense but i am doing it slightly different. what i do is move my sprites and then update the bodies to the position of the sprite. This allows me to use the moveTo function of cocos2d and use the physics engine of chipmunk to see if two touch and all of my collision callbacks return 0 because i just move them off of the screen. and either remove them or reset them. would the way i move my bodies cause a slow down?

And also i guess i wasnt really asking how to get the size but more of what does 100 mean? w*h? or what?

Thanks
-Lars
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Low fps with Chipmunk

Post by slembcke »

So you are just using Chipmunk for the collision detection and moving all of your "dead" objects to the same place instead of removing them from the space? That would also be bad because it would force Chipmunk to check a ton of collisions between objects that you don't even care about. Every object would have to be checked against every other object in that area.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
korki696
Posts: 24
Joined: Wed Jul 15, 2009 2:15 am
Contact:

Re: Low fps with Chipmunk

Post by korki696 »

WHat im doing is in the collision callback if there health is 0 then move them out of the screen and change their state to dead and then in my main loop after i step chipmunk it checks if any are dead and if so it deletes them. when i move them i also give them a random number to add to it so they dont touch. but i do have my projectiles that get created in the same location but i have no colision call back on them does chipmunk stll do math for those?

Thanks
-Lars
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Low fps with Chipmunk

Post by slembcke »

Still not quite sure what you mean exactly, but the answer is likely yes.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
korki696
Posts: 24
Joined: Wed Jul 15, 2009 2:15 am
Contact:

Re: Low fps with Chipmunk

Post by korki696 »

Ok what im doing is creating 15 projectiles all with the same collision_type on the same location lets say -100, -100. there is no collision function for them hitting each other only other objects such as enemies but does chipmunk still do calculations for those? If so how can i make it so it doesnt?
Thanks
-Lars
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Low fps with Chipmunk

Post by maximile »

I don't think Chipmunk checks whether the collision function is NULL before it does the costly stuff. Putting the projectiles into a group would sort it out.
korki696
Posts: 24
Joined: Wed Jul 15, 2009 2:15 am
Contact:

Re: Low fps with Chipmunk

Post by korki696 »

Ok, so i played around with my code a lot and ended up making all of my shapes into circles, which if i remember right are the fastest. which gave me a boost of about .5fps. i then decided to see if its my projectiles so i went from making 20 total to just 2 and it runs at 60 fps. so then i went to 10 total and it drops to 40fps. the projectiles are all in a group and they are just circles with a radius of 6. so they are quite small. how could they be slowing down the game so much?
Thanks
-Lars
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Low fps with Chipmunk

Post by slembcke »

Have you tried profiling and what compiler flags are you using? Disable thumb compilation, and use -O3 and -ffast-math for Chipmunk. That should make a pretty big difference.
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 18 guests