Page 1 of 1

Chipmunk static SegementShape efficiency problem

Posted: Fri Mar 30, 2012 9:00 pm
by sleepers
I was trying to make a game like "where is my water" through chipmunk.
I've already add the water(the bodies) and the mud(something can be removed from the screen).
Here is my problem, when removing the mud, I add at least 8 lines(through this function, AddSegementShapeToSpace() ) which forms an polygon to the space.
and when trying to remove more mud, more and more static segmentshape were added to the space.
thus created an efficiency problem. It has 15-18 fps at beginning , as we add more polygons, the fps drops down to 3-5, which is unacceptable. Here is the pseudo code:

// Every frame

Code: Select all

if (userTouchScreen)
{
    updatePolygons(); // this produce a lot of points.
}


cpSpaceEachShape(, RemoveShape,); // removes all the shape

foreach line in polygon:      // more and more static shapes were added to space.
  all line to space.               //AddSegementShapeToSpace()

stepSpace;

Chipmunk is the first physics engine I met and I think it is awesome. It runs on the MTK platform. I have an arm cpu has 400MHZ, and enough memory.

forgive my poor english.

thanks, guys..

Re: Chipmunk static SegementShape efficiency problem

Posted: Sat Mar 31, 2012 12:35 pm
by slembcke
It's fairly expensive to add and remove all of the shapes from a space each frame. You need to change your code so that it only adds or removes shapes that have changed.

Re: Chipmunk static SegementShape efficiency problem

Posted: Thu Apr 05, 2012 1:12 am
by sleepers
problem solved, thanks a lot,