Chipmunk static SegementShape efficiency problem

Official forum for the Chipmunk2D Physics Library.
Post Reply
sleepers
Posts: 2
Joined: Mon Mar 12, 2012 4:16 am
Contact:

Chipmunk static SegementShape efficiency problem

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

Re: Chipmunk static SegementShape efficiency problem

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
sleepers
Posts: 2
Joined: Mon Mar 12, 2012 4:16 am
Contact:

Re: Chipmunk static SegementShape efficiency problem

Post by sleepers »

problem solved, thanks a lot,
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests