Swap two components in the array
| 201 | |
| 202 | // Swap two components in the array |
| 203 | void ColliderComponents::swapComponents(uint32 index1, uint32 index2) { |
| 204 | |
| 205 | // Copy component 1 data |
| 206 | Entity colliderEntity1(mCollidersEntities[index1]); |
| 207 | Entity bodyEntity1(mBodiesEntities[index1]); |
| 208 | Collider* collider1 = mColliders[index1]; |
| 209 | int32 broadPhaseId1 = mBroadPhaseIds[index1]; |
| 210 | Transform localToBodyTransform1 = mLocalToBodyTransforms[index1]; |
| 211 | CollisionShape* collisionShape1 = mCollisionShapes[index1]; |
| 212 | unsigned short collisionCategoryBits1 = mCollisionCategoryBits[index1]; |
| 213 | unsigned short collideWithMaskBits1 = mCollideWithMaskBits[index1]; |
| 214 | Transform localToWorldTransform1 = mLocalToWorldTransforms[index1]; |
| 215 | Array<uint64> overlappingPairs = mOverlappingPairs[index1]; |
| 216 | bool hasCollisionShapeChangedSize = mHasCollisionShapeChangedSize[index1]; |
| 217 | bool isTrigger = mIsTrigger[index1]; |
| 218 | bool isSimulationCollider = mIsSimulationCollider[index1]; |
| 219 | bool isWorldQueryCollider = mIsWorldQueryCollider[index1]; |
| 220 | Material material = mMaterials[index1]; |
| 221 | |
| 222 | // Destroy component 1 |
| 223 | destroyComponent(index1); |
| 224 | |
| 225 | moveComponentToIndex(index2, index1); |
| 226 | |
| 227 | // Reconstruct component 1 at component 2 location |
| 228 | new (mCollidersEntities + index2) Entity(colliderEntity1); |
| 229 | new (mBodiesEntities + index2) Entity(bodyEntity1); |
| 230 | mColliders[index2] = collider1; |
| 231 | new (mBroadPhaseIds + index2) int32(broadPhaseId1); |
| 232 | new (mLocalToBodyTransforms + index2) Transform(localToBodyTransform1); |
| 233 | mCollisionShapes[index2] = collisionShape1; |
| 234 | new (mCollisionCategoryBits + index2) unsigned short(collisionCategoryBits1); |
| 235 | new (mCollideWithMaskBits + index2) unsigned short(collideWithMaskBits1); |
| 236 | new (mLocalToWorldTransforms + index2) Transform(localToWorldTransform1); |
| 237 | new (mOverlappingPairs + index2) Array<uint64>(overlappingPairs); |
| 238 | mHasCollisionShapeChangedSize[index2] = hasCollisionShapeChangedSize; |
| 239 | mIsTrigger[index2] = isTrigger; |
| 240 | mIsSimulationCollider[index2] = isSimulationCollider; |
| 241 | mIsWorldQueryCollider[index2] = isWorldQueryCollider; |
| 242 | mMaterials[index2] = material; |
| 243 | |
| 244 | // Update the entity to component index mapping |
| 245 | mMapEntityToComponentIndex.add(Pair<Entity, uint32>(colliderEntity1, index2)); |
| 246 | |
| 247 | assert(mMapEntityToComponentIndex[mCollidersEntities[index1]] == index1); |
| 248 | assert(mMapEntityToComponentIndex[mCollidersEntities[index2]] == index2); |
| 249 | assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size())); |
| 250 | } |
| 251 | |
| 252 | // Destroy a component at a given index |
| 253 | void ColliderComponents::destroyComponent(uint32 index) { |