Edge wrote:Keep up the good work. I like where this is going 😀
Thanks!
Edge wrote:While you're plugging away in there, was wondering if you could explain this. From Island.solve(), seems like all this cares about is the minSleepTime from the last dynamic body, but it loops through all of them to get at it. In most cases that doesn't seem like a big deal as most islands only have 1-2 bodies, but some occasionally get into the 170+ range. Can we break out of the loop when we set min to 0.0f in a couple places?
Code: Select all
[snip]
if ((b.m_flags & Body.e_allowSleepFlag) == 0) {
b.m_sleepTime = 0.0f;
minSleepTime = 0.0f;
}
if ((b.m_flags & Body.e_allowSleepFlag) == 0 ||
b.m_angularVelocity * b.m_angularVelocity > angTolSqr ||
Vec2.dot(b.m_linearVelocity, b.m_linearVelocity) > linTolSqr) {
b.m_sleepTime = 0.0f;
minSleepTime = 0.0f;
} else {
b.m_sleepTime += step.dt;
minSleepTime = MathUtils.min(minSleepTime, b.m_sleepTime);
}
}
if (minSleepTime >= Settings.timeToSleep) {
for (int i = 0; i < m_bodyCount; ++i) {
final Body b = m_bodies[i];
b.m_flags |= Body.e_sleepFlag;
b.m_linearVelocity = new Vec2(0.0f, 0.0f); // gotcha!
b.m_angularVelocity = 0.0f;
}
}
}
[snip]
I see what you're saying, but the only thing I notice is that the sleep time of each body is incremented in that last else statement. So it's purpose isn't only to find the minSleepTime, it also increments the time an object has been "sleeping", even if the group isn't. That way, when the "active" object leaves, the "sleeping" object can populate that minSleepTime field with it's sleeping time. But I think we can remove two things here, that middle if statement (the one at the top of the snip), and I also see where I can eliminate a Vec2 creation
😀 can't believe I missed that.
Edge wrote:Also, how much do the bitflags speed things up? Are they worth keeping (can be a pain to work with)? Lot of other duplicated code in Body as well (ex. set mass logic as a separate method and in the constructor).
I'm not really sure, but they're easy to work with, and removing them will be a hassle, especially when we start updating the engine. Also, in my optimizations, I've generally tried to not change anything structurally, as I'm not recreating the engine, I'm just optimizing what's there. I would only bother about any structural changes after ewjordan and I have fully updated the engine to the current box2d build, as I'm sure Erin's made optimizations too (I think we're based around build 142, and box2d is on 210, and from what I've seen a lot has changed).
But thanks for looking into it, and I'll definitely take out that if statement and remove that creation. And if I didn't quite understand what you were suggesting, please elaborate, as I can miss things.