I'm wondering if perhaps b2Body::SetType should call SetAwake(false) for bodies being set to static? Currently it does this:
I was seeing a problem in Farseer where static bodies added to the world would be woken by this and never go to sleep so they were always processed by contact manager. I didn't expect static bodies to ever be awake and only discovered this while looking at some other performance issues. I'm not currently set up to test this in Box2D but I thought I'd mention it in case Box2D behaved the same way. I made a small local change to make it set the body asleep when it is being set to a static object and awake otherwise and the static objects no longer caused wasted cycles and everything seemed to behave correctly. I suppose I could have just manually set the objects asleep after creating them but it seems like static objects should never be awake in the first place. Does this seem like a valid change, or is there ever a reason that static bodies need to be tagged as awake?
Thanks for any feedback,
Code:
void b2Body::SetType(b2BodyType type)
{
if (m_type == type)
{
return;
}
m_type = type;
ResetMassData();
if (m_type == b2_staticBody)
{
m_linearVelocity.SetZero();
m_angularVelocity = 0.0f;
}
SetAwake(true);
{
if (m_type == type)
{
return;
}
m_type = type;
ResetMassData();
if (m_type == b2_staticBody)
{
m_linearVelocity.SetZero();
m_angularVelocity = 0.0f;
}
SetAwake(true);
I was seeing a problem in Farseer where static bodies added to the world would be woken by this and never go to sleep so they were always processed by contact manager. I didn't expect static bodies to ever be awake and only discovered this while looking at some other performance issues. I'm not currently set up to test this in Box2D but I thought I'd mention it in case Box2D behaved the same way. I made a small local change to make it set the body asleep when it is being set to a static object and awake otherwise and the static objects no longer caused wasted cycles and everything seemed to behave correctly. I suppose I could have just manually set the objects asleep after creating them but it seems like static objects should never be awake in the first place. Does this seem like a valid change, or is there ever a reason that static bodies need to be tagged as awake?
Thanks for any feedback,