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

Method swapComponents

src/components/TransformComponents.cpp:123–144  ·  view source on GitHub ↗

Swap two components in the array

Source from the content-addressed store, hash-verified

121
122// Swap two components in the array
123void 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
147void TransformComponents::destroyComponent(uint32 index) {

Callers

nothing calls this directly

Calls 2

addMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected