2

this is my first post here (wish me luck)

Im building a side-scrolling iOS-game (cocos2d) that uses the chipmunk physics engine (v 5.3.4). The games framerate is dropping dramatically when I move around waking up sleeping dynamic bodies. When playing the level without touching any dynamic bodies the frame rate stayes high and stable.

Initially my frame rate is 60. But after I have moved around touching all bodies in a level at least once my frame rate is down to 19!

I set the sleepTimeThreshold to 0.4 and the idleSpeedThreshold to 1 and for all dynamic bodies that I create I force them to sleep from the start of the simulation using cpBodySleep(body).

Any clue?

I have about 35 bodies spread around the level (about 10 5 by 5 screens). All bodies are simple rectangles and circles

I can tell from debugging that the bodies goes back to sleep but chipmunks timestep (solver/query) initially takes 25% of the running time and 50% after playing a level according to instruments time profiler.

What am I missing here? Is the sleeping of bodies working alright in chipmunk? Or do I need to do something "manually"? Is there anything more I need to do to regain my initial high and stable frame rate? BTW I'm using SpaceManager to work with chipmunk.

1 Answers1

0

So the bodies aren't falling back asleep ever? How are they falling asleep the first time, or are you starting the in a sleeping state? What are the values stored in the "node" struct of the cpBodies, that is where it tracks how long an object has been idle for.

Also, you should be able to get a lot more than 35 moving objects on the screen before running into performance problems even without sleeping. Are you building Chipmunk with the recommended flags? -O3 or -Os for optimization level, -ffast-math to disable unnecessary NaN checks, -DNDEBUG to disable assertions. That can make a huge difference in performance if you are missing some or all of those. I would recommend using the script that comes with Chipmunk to build yourself a static library.

slembcke
  • 1,359
  • 7
  • 7