Swap two components in the array
| 156 | |
| 157 | // Swap two components in the array |
| 158 | void JointComponents::swapComponents(uint32 index1, uint32 index2) { |
| 159 | |
| 160 | // Copy component 1 data |
| 161 | Entity jointEntity1(mJointEntities[index1]); |
| 162 | Entity body1Entity1(mBody1Entities[index1]); |
| 163 | Entity body2Entity1(mBody2Entities[index1]); |
| 164 | Joint* joint1 = mJoints[index1]; |
| 165 | JointType jointType1(mTypes[index1]); |
| 166 | JointsPositionCorrectionTechnique positionCorrectionTechnique1(mPositionCorrectionTechniques[index1]); |
| 167 | bool isCollisionEnabled1 = mIsCollisionEnabled[index1]; |
| 168 | bool isAlreadyInIsland = mIsAlreadyInIsland[index1]; |
| 169 | |
| 170 | // Destroy component 1 |
| 171 | destroyComponent(index1); |
| 172 | |
| 173 | moveComponentToIndex(index2, index1); |
| 174 | |
| 175 | // Reconstruct component 1 at component 2 location |
| 176 | new (mJointEntities + index2) Entity(jointEntity1); |
| 177 | new (mBody1Entities + index2) Entity(body1Entity1); |
| 178 | new (mBody2Entities + index2) Entity(body2Entity1); |
| 179 | mJoints[index2] = joint1; |
| 180 | new (mTypes + index2) JointType(jointType1); |
| 181 | new (mPositionCorrectionTechniques + index2) JointsPositionCorrectionTechnique(positionCorrectionTechnique1); |
| 182 | mIsCollisionEnabled[index2] = isCollisionEnabled1; |
| 183 | mIsAlreadyInIsland[index2] = isAlreadyInIsland; |
| 184 | |
| 185 | // Update the entity to component index mapping |
| 186 | mMapEntityToComponentIndex.add(Pair<Entity, uint32>(jointEntity1, index2)); |
| 187 | |
| 188 | assert(mMapEntityToComponentIndex[mJointEntities[index1]] == index1); |
| 189 | assert(mMapEntityToComponentIndex[mJointEntities[index2]] == index2); |
| 190 | assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size())); |
| 191 | } |
| 192 | |
| 193 | // Destroy a component at a given index |
| 194 | void JointComponents::destroyComponent(uint32 index) { |