Find islands, integrate and solve constraints, solve position constraints
| 384 | |
| 385 | // Find islands, integrate and solve constraints, solve position constraints |
| 386 | void b2World::Solve(const b2TimeStep& step) |
| 387 | { |
| 388 | m_profile.solveInit = 0.0f; |
| 389 | m_profile.solveVelocity = 0.0f; |
| 390 | m_profile.solvePosition = 0.0f; |
| 391 | |
| 392 | // Size the island for the worst case. |
| 393 | b2Island island(m_bodyCount, |
| 394 | m_contactManager.m_contactCount, |
| 395 | m_jointCount, |
| 396 | &m_stackAllocator, |
| 397 | m_contactManager.m_contactListener); |
| 398 | |
| 399 | // Clear all the island flags. |
| 400 | for (b2Body* b = m_bodyList; b; b = b->m_next) |
| 401 | { |
| 402 | b->m_flags &= ~b2Body::e_islandFlag; |
| 403 | } |
| 404 | for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next) |
| 405 | { |
| 406 | c->m_flags &= ~b2Contact::e_islandFlag; |
| 407 | } |
| 408 | for (b2Joint* j = m_jointList; j; j = j->m_next) |
| 409 | { |
| 410 | j->m_islandFlag = false; |
| 411 | } |
| 412 | |
| 413 | // Build and simulate all awake islands. |
| 414 | int32 stackSize = m_bodyCount; |
| 415 | b2Body** stack = (b2Body**)m_stackAllocator.Allocate(stackSize * sizeof(b2Body*)); |
| 416 | for (b2Body* seed = m_bodyList; seed; seed = seed->m_next) |
| 417 | { |
| 418 | if (seed->m_flags & b2Body::e_islandFlag) |
| 419 | { |
| 420 | continue; |
| 421 | } |
| 422 | |
| 423 | if (seed->IsAwake() == false || seed->IsActive() == false) |
| 424 | { |
| 425 | continue; |
| 426 | } |
| 427 | |
| 428 | // The seed can be dynamic or kinematic. |
| 429 | if (seed->GetType() == b2_staticBody) |
| 430 | { |
| 431 | continue; |
| 432 | } |
| 433 | |
| 434 | // Reset island and stack. |
| 435 | island.Clear(); |
| 436 | int32 stackCount = 0; |
| 437 | stack[stackCount++] = seed; |
| 438 | seed->m_flags |= b2Body::e_islandFlag; |
| 439 | |
| 440 | // Perform a depth first search (DFS) on the constraint graph. |
| 441 | while (stackCount > 0) |
| 442 | { |
| 443 | // Grab the next body off the stack and add it to the island. |
no test coverage detected