Swap two components in the array
| 121 | |
| 122 | // Swap two components in the array |
| 123 | void TransformComponents::swapComponents(uint32 index1, uint32 index2) { |
| 124 | |
| 125 | // Copy component 1 data |
| 126 | Entity entity1(mBodies[index1]); |
| 127 | Transform transform1(mTransforms[index1]); |
| 128 | |
| 129 | // Destroy component 1 |
| 130 | destroyComponent(index1); |
| 131 | |
| 132 | moveComponentToIndex(index2, index1); |
| 133 | |
| 134 | // Reconstruct component 1 at component 2 location |
| 135 | new (mBodies + index2) Entity(entity1); |
| 136 | new (mTransforms + index2) Transform(transform1); |
| 137 | |
| 138 | // Update the entity to component index mapping |
| 139 | mMapEntityToComponentIndex.add(Pair<Entity, uint32>(entity1, index2)); |
| 140 | |
| 141 | assert(mMapEntityToComponentIndex[mBodies[index1]] == index1); |
| 142 | assert(mMapEntityToComponentIndex[mBodies[index2]] == index2); |
| 143 | assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size())); |
| 144 | } |
| 145 | |
| 146 | // Destroy a component at a given index |
| 147 | void TransformComponents::destroyComponent(uint32 index) { |