Chipmunk is too slow?

Member
Posts: 39
Joined: 2008.09
Post: #1
I've been playing around a little with chipmunk, included into cocos2d lib. I only have 12 objects, they are connected using slide joints, and that's it - it's already too much to perform at maximum speed, which is 60 FPS. Compile for thumb thing didn't make much difference, its just as slow, and the samples provided run slow, too (only the simple run at maximum speed).
I've changed box shapes to circles, and surprisingly, this didn't make much difference (doc said it's the fastest shape), so it's probably slide joints which are slow.

I pretty much like the chipmunk, so I'd rather stick with it, but I need some ideas how to optimize the whole thing. Or please suggest another nice 2d phisics engine, which can handle sliding joints.

Happy New Year! Smile.
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #2
Chipmunk has been around forever. But I am afraid the dev hasn't been keeping up with the changes in the OS.

You might want to look at KBasic and TNT Basic. TNT was shareware and now open source. It is aimed at games. Of course, there is also FutureBasic and Realbasic.

Or try your hand at PyGame (based on Python)

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #3
I think he means Chipmunk (physics)...

Chipmunk is not slow in my experience, but the iPhone hardware can only handle so much. There are some good Chipmunk and general optimization tips in this old thread.
Quote this message in a reply
Member
Posts: 39
Joined: 2008.09
Post: #4
Frank C. Wrote:Chipmunk is not slow in my experience, but the iPhone hardware can only handle so much.

Well it's not particularly slow, it's even quite nice when dealing with shapes like boxes - I remember my own box physics was even slower. But I'm sure it could perform much faster with circular shapes. It's no big deal to have 100 colliding balls in stage, because circle collision is extremely simple, and things like slide joints are pretty simple too, so I just don't understand why circles are almost as slow as shapes do.

Sadly, the link you provided didn't help me much - I tried more compiler optimization options, but it's useless.

PS: Funny though, yesterday I looked at another cocos2d chipmunk sample, and it's just like your game, except that you have some nice heads instead of that guy Smile.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #5
What makes you think the physics are the bottleneck?
Where does Shark tell you the time is being spent?
Quote this message in a reply
Member
Posts: 39
Joined: 2008.09
Post: #6
arekkusu Wrote:What makes you think the physics are the bottleneck?
Where does Shark tell you the time is being spent?

Because there's just physics and a few opengl lines, nothing else. This is something you don't need Shark for.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #7
That doesn't follow at all, from the description you originally gave. Unless you've actually profiled the application, you're just guessing.

For example, if you have 12 objects, but each uses a different 1024x1024 texture, your bottleneck could very easily be drawing, not physics. And you could very easily see a performance drop going from 11 to 12 objects, based strictly on the GL memory footprint, completely unrelated to CPU time.

Did you at least do the trivial experiment of disabling all drawing, so your entire loop consists of just physics?
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #8
jaguard Wrote:Sadly, the link you provided didn't help me much - I tried more compiler optimization options, but it's useless.
You might want to double check that post - particularly Skorche's comments. If Chipmunk is indeed the bottle neck then Skorche will have the best advice. If you've misdiagnosed the problem then ya, that thread might not be much help.

jaguard Wrote:PS: Funny though, yesterday I looked at another cocos2d chipmunk sample, and it's just like your game, except that you have some nice heads instead of that guy Smile.
I checked it out and they both use Chipmunk with zero-gravity but "just like" is a gross exaggeration. BTW - they're not heads, they're mutant cuttlefish Wink
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #9
Frank C. Wrote:BTW - they're not heads, they're mutant cuttlefish Wink

Wouldn't happen to be in reference to this, would it? http://xkcd.com/520/

Grin
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #10
ThemsAllTook Wrote:Wouldn't happen to be in reference to this, would it? http://xkcd.com/520/

Grin

Never seen that before, but I for one welcome our new cephalopod overlords Grin
Quote this message in a reply
Member
Posts: 39
Joined: 2008.09
Post: #11
Frank C. Wrote:You might want to double check that post - particularly Skorche's comments. If Chipmunk is indeed the bottle neck then Skorche will have the best advice. If you've misdiagnosed the problem then ya, that thread might not be much help.
Well, I checked it again. I'm not good enough to rewrite parts of the algorithm (it's easier for me to write the whole thing from scratch), but other things like -O3 compilation didn't work.

Quote:I checked it out and they both use Chipmunk with zero-gravity but "just like" is a gross exaggeration.
Maybe just a little Smile.
The dynamics is the same as in Chipmunk_accel - there are some objects and they are added pushing the others. So actually with a little modification I could make a game out of this example quite easily.
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #12
jaguard Wrote:Well, I checked it again. I'm not good enough to rewrite parts of the algorithm (it's easier for me to write the whole thing from scratch), but other things like -O3 compilation didn't work.

Didn't work *at all*? Or, just didn't help performance?
Quote this message in a reply
Member
Posts: 39
Joined: 2008.09
Post: #13
AnotherJake Wrote:Didn't work *at all*? Or, just didn't help performance?

Sorry, I mean didn't help of course. The biggest boost was obviously from release configuration and disabling THUMB.

After a while I decided I can live with this performance after all, sadly though I won't be able to do some neat thing I like. Well, it's better than implementing my own physics.
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2008.12
Post: #14
Sorry if this is an old thread, I just thought I should inform you that I've been porting chipmunk physics over, and it's running fairly smooth. The 12 objects on the screen should be no problem at all. I'm new to most of the compiler options, but adding -ffast-math and -fomit-pointer-frame to the CFLAGS helped with a speed boost. Along with that, it's recommended in chipmunk.h you change:

Code:
typedef double cpFloat;

to

Code:
typedef float cpFloat;

if not already done. I'm probably going to release the port (it's more of a template, I didn't have to do any actual modifications to the code) in due time. Hope that helped, and please correct any assumptions I may have made compiler-wise above.

-Al
Quote this message in a reply
Member
Posts: 39
Joined: 2008.09
Post: #15
After playing around with chipmunk for a while, I'm now pretty sure I can make a great game with little limitation. The problem was that I had a chain-like objects, they were connected like this: =.=.=.=.=, and been colliding every frame. I disabled collisions between them and now it's much faster. It's also got a great hashing mechanism - I tried with 50 rectangle shape objects on a big distance (plus several other objects) - they would lag if they were on a single screen, but when they're on a big length (imagine a long level), so only 2-3 are colliding, they work just fine.

There's a major flaw with chipmunk though - you can go thru collision object if your speed is very high. Another one is that on a big speed connections would slide, even if they are not set to sliding. I.e. O-------B becomes O- - - - - - - - B. Apart from that, an awesome physics lib!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  XML too slow, best way to go binary markhula 9 8,269 Jan 14, 2011 06:58 AM
Last Post: markhula
  Why is my iPad game so slow? Applewood 53 27,905 Jan 3, 2011 04:54 PM
Last Post: Applewood
  emulator slow when rendering from a second thread captainfreedom 1 2,858 Jan 30, 2010 05:05 PM
Last Post: ChrisD
  Simple application slow down, FPS drops Newbrof 15 7,838 Sep 2, 2009 12:51 PM
Last Post: AnotherJake
  mac mini simulator - slow frame rate sumiguchi 3 3,808 Dec 18, 2008 08:56 AM
Last Post: SafariAl