Move a component from a source to a destination index in the components array The destination location must contain a constructed object
| 101 | // Move a component from a source to a destination index in the components array |
| 102 | // The destination location must contain a constructed object |
| 103 | void TransformComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) { |
| 104 | |
| 105 | const Entity entity = mBodies[srcIndex]; |
| 106 | |
| 107 | // Copy the data of the source component to the destination location |
| 108 | new (mBodies + destIndex) Entity(mBodies[srcIndex]); |
| 109 | new (mTransforms + destIndex) Transform(mTransforms[srcIndex]); |
| 110 | |
| 111 | // Destroy the source component |
| 112 | destroyComponent(srcIndex); |
| 113 | |
| 114 | assert(!mMapEntityToComponentIndex.containsKey(entity)); |
| 115 | |
| 116 | // Update the entity to component index mapping |
| 117 | mMapEntityToComponentIndex.add(Pair<Entity, uint32>(entity, destIndex)); |
| 118 | |
| 119 | assert(mMapEntityToComponentIndex[mBodies[destIndex]] == destIndex); |
| 120 | } |
| 121 | |
| 122 | // Swap two components in the array |
| 123 | void TransformComponents::swapComponents(uint32 index1, uint32 index2) { |
nothing calls this directly
no test coverage detected