MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / createIslands

Method createIslands

src/engine/PhysicsWorld.cpp:695–869  ·  view source on GitHub ↗

Compute the islands using potential contacts and joints We compute the islands before creating the actual contacts here because we want all the contact manifolds and contact points of the same island to be packed together into linear arrays of manifolds and contacts for better caching. An island is an isolated group of rigid bodies that have constraints (joints or contacts) between each other. Thi

Source from the content-addressed store, hash-verified

693/// find all the bodies that are connected with it (the bodies that share joints or contacts with
694/// it). Then, we create an island with this group of connected bodies.
695void PhysicsWorld::createIslands() {
696
697 RP3D_PROFILE("PhysicsWorld::createIslands()", mProfiler);
698
699 assert(mProcessContactPairsOrderIslands.size() == 0);
700
701 // Reset all the isAlreadyInIsland variables of bodies and joints
702 const uint32 nbRigidBodyComponents = mRigidBodyComponents.getNbComponents();
703 for (uint32 b=0; b < nbRigidBodyComponents; b++) {
704 mRigidBodyComponents.mIsAlreadyInIsland[b] = false;
705 }
706 const uint32 nbJointsComponents = mJointsComponents.getNbComponents();
707 for (uint32 i=0; i < nbJointsComponents; i++) {
708 mJointsComponents.mIsAlreadyInIsland[i] = false;
709 }
710
711 // Reserve memory for the islands
712 mIslands.reserveMemory();
713
714 // Create a stack for the bodies to visit during the Depth First Search
715 Stack<Entity> bodyEntitiesToVisit(mMemoryManager.getSingleFrameAllocator(), mIslands.getNbMaxBodiesInIslandPreviousFrame());
716
717 // Array of static bodies added to the current island (used to reset the isAlreadyInIsland variable of static bodies)
718 Array<Entity> staticBodiesAddedToIsland(mMemoryManager.getSingleFrameAllocator(), 16);
719
720 uint32 nbTotalManifolds = 0;
721
722 // For each rigid body component
723 for (uint32 b=0; b < mRigidBodyComponents.getNbEnabledComponents(); b++) {
724
725 // If the body has already been added to an island, we go to the next body
726 if (mRigidBodyComponents.mIsAlreadyInIsland[b]) continue;
727
728 // If the body is static, we go to the next body
729 if (mRigidBodyComponents.mBodyTypes[b] == BodyType::STATIC) continue;
730
731 // If the body does not have any simulation collider, we skip it
732 if (!mBodyComponents.getHasSimulationCollider(mRigidBodyComponents.mRigidBodies[b]->getEntity())) continue;
733
734 // Reset the stack of bodies to visit
735 bodyEntitiesToVisit.clear();
736
737 // Add the body into the stack of bodies to visit
738 mRigidBodyComponents.mIsAlreadyInIsland[b] = true;
739 bodyEntitiesToVisit.push(mRigidBodyComponents.mBodiesEntities[b]);
740
741 // Create the new island
742 uint32 islandIndex = mIslands.addIsland(nbTotalManifolds);
743
744 // While there are still some bodies to visit in the stack
745 while (bodyEntitiesToVisit.size() > 0) {
746
747 // Get the body entity
748 const Entity bodyToVisitEntity = bodyEntitiesToVisit.pop();
749
750 // Add the body into the island
751 mIslands.addBodyToIsland(bodyToVisitEntity);
752

Callers

nothing calls this directly

Calls 15

getNbComponentsMethod · 0.80
pushMethod · 0.80
addIslandMethod · 0.80
popMethod · 0.80
addBodyToIslandMethod · 0.80
getEntityIndexMethod · 0.80
hasComponentGetIndexMethod · 0.80
getBodyTypeMethod · 0.80
removeAllContacPairsMethod · 0.80

Tested by

no test coverage detected