Chipmunk uses an iterative solver to figure out the forces between objects in the space. What this means is that it builds a big list of all of the collisions, joints, and other constraints between the bodies and makes several passes over the list considering each one individually. The number of passes it makes is the iteration count, and each iteration makes the solution more accurate. If you use too many iterations, the physics should look nice and solid, but may use up too much CPU time. If you use too few iterations, the simulation may seem mushy or bouncy when the objects should be solid. Setting the number of iterations lets you balance between CPU usage and the accuracy of the physics. Chipmunk’s default of 10 iterations is sufficient for most simple games.

(我的见解) chipmunk采用迭代器来计算和解决space里物体之间力的互相作用。这意味着chipmunk为所有物体body之间的相互作用建立了一个很大很大的表,并为每个物体都单独地进行了一定迭代次数地计算。每次迭代都会使计算结果更加准确与真实,更多的迭代次数会使物理效果更加真实,同时花费更多的CPU时间。请适当地定位迭代次数,chipmunk一般默认定义为10次。

 

(原文)Sleeping

 

New in Chipmunk 5.3 is the ability of spaces to disable entire groups of objects that have stopped moving to save CPU time as well as battery life. In order to use this feature you must do 2 things. The first is that you must attach all your static geometry to static bodies. Objects cannot fall asleep if they are touching a non-static rogue body even if it’s shapes were added as static shapes. The second is that you must enable sleeping explicitly by choosing a time threshold value for cpSpace.sleepTimeThreshold. If you do not set cpSpace.idleSpeedThreshold explicitly, a value will be chosen automatically based on the current amount of gravity.

 

(我的见解)在5.3的版本中添加了新的特性,使space能使那些早已停止运动的body失效(意思就是不再放入List里进行计算),以节省CPU时间。为了使用这一特性,你需要做2件事情。首先,你必须把所有的静止的几何物体(如关卡中静止的边界线,地面,悬崖等)绑定到static body中(static body可以用cpSpaceGetStaticBody(space)得到)
。如果物体是与非static的body绑定,物体将一直无法变成“睡眠”状态,甚至物体的shape是与static shape绑在一起的。接着,你必须明确一个时间值cpSpace.sleepTimeThreshold(单位为秒),确保过了这个时间物体能变成"睡眠"状态。如果没设置这个值,chipmunk将自动根据最近的重力值设定?(最后一句是这样理解么。。)

 

 

cpFloat cpSpaceGetSleepTimeThreshold(const cpSpace *space) 
void cpSpaceSetSleepTimeThreshold(cpSpace *space, cpFloat value)
设置物体的失效时间,单位为秒。默认属性为INFINITY的body无此特性。