Adding lots of static shapes in Chipmunk - performance question

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
Hey everybody,

I'm adding a lot of static shapes (sensors) at level load, and it's showing up as a big performance hit. Now, once loaded, it runs fantastically well. But loading them all is slow.

I'm adding them via cpSpaceAddStaticShape()

I'm wondering if there's a way to tell chipmunk to wait while I add a batch of shapes, and then do its rehashing and other expensive computation once I've finished.

Note: In my profiling I find the hotspot is the function cpSpaceActivateShapesTouchingShape -- which seems spurious since the shapes I'm adding are sensors.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
I just released Chipmunk 6.0.0 a week ago. You might want to consider upgrading to that. This was one of the problems it fixed. There have been a few small API changes though.

In Chipmunk 5.3.x it would run a shape query when inserting or removing static shapes to see if it needed to wake anything up to deal with the newly inserted static shape. In Chipmunk 6, it actually keeps a contact graph, so it can efficiently (and more accurately) wake objects resting on a static shape. I removed the query for insertions completely as it was ridiculously expensive and a pretty specific border case.

If you want to stick with 5.3.5, it wouldn't be the worst thing to modify the Chipmunk source to get rid of the cpSpaceActivateShapesTouchingShape() call. I don't plan on releasing a Chipmunk 5.3.6, so you'd never have to merge changes or anything.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
Wow, awesome! Is there any transition information, any gotchas about switching from 5.3.whatevs to 6.0?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
The release notes should be pretty thorough. We just created an updates feed, that's probably the easiest way to get to the release notes other than downloading and looking at the readme:
feed://chipmunk-physics.net/updates.rss

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  chipmunk sensor question TomorrowPlusX 7 7,395 Jun 22, 2011 06:40 AM
Last Post: Skorche
  cocos2d: memory question adding child to scenes sefiroths 8 9,879 Apr 19, 2011 08:06 AM
Last Post: OneSadCookie
  To STATIC or not to STATIC... Elphaba 10 4,193 Aug 6, 2009 09:17 AM
Last Post: Elphaba
  Chipmunk Static Friction Piazzolla 0 2,667 Jul 21, 2009 11:06 AM
Last Post: Piazzolla
  Adding static gravity object game_ding 4 4,908 Mar 28, 2008 05:25 PM
Last Post: Skorche