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

Method swapComponents

src/components/BodyComponents.cpp:147–176  ·  view source on GitHub ↗

Swap two components in the array

Source from the content-addressed store, hash-verified

145
146// Swap two components in the array
147void BodyComponents::swapComponents(uint32 index1, uint32 index2) {
148
149 // Copy component 1 data
150 Entity entity1(mBodiesEntities[index1]);
151 Body* body1 = mBodies[index1];
152 Array<Entity> colliders1(mColliders[index1]);
153 bool isActive1 = mIsActive[index1];
154 void* userData1 = mUserData[index1];
155 bool hasSimulationCollider = mHasSimulationCollider[index1];
156
157 // Destroy component 1
158 destroyComponent(index1);
159
160 moveComponentToIndex(index2, index1);
161
162 // Reconstruct component 1 at component 2 location
163 new (mBodiesEntities + index2) Entity(entity1);
164 new (mColliders + index2) Array<Entity>(colliders1);
165 mBodies[index2] = body1;
166 mIsActive[index2] = isActive1;
167 mUserData[index2] = userData1;
168 mHasSimulationCollider[index2] = hasSimulationCollider;
169
170 // Update the entity to component index mapping
171 mMapEntityToComponentIndex.add(Pair<Entity, uint32>(entity1, index2));
172
173 assert(mMapEntityToComponentIndex[mBodiesEntities[index1]] == index1);
174 assert(mMapEntityToComponentIndex[mBodiesEntities[index2]] == index2);
175 assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size()));
176}
177
178// Destroy a component at a given index
179void BodyComponents::destroyComponent(uint32 index) {

Callers

nothing calls this directly

Calls 2

addMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected