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

Method moveComponentToIndex

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

Move a component from a source to a destination index in the components array The destination location must contain a constructed object

Source from the content-addressed store, hash-verified

121// Move a component from a source to a destination index in the components array
122// The destination location must contain a constructed object
123void BodyComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) {
124
125 const Entity entity = mBodiesEntities[srcIndex];
126
127 // Copy the data of the source component to the destination location
128 new (mBodiesEntities + destIndex) Entity(mBodiesEntities[srcIndex]);
129 mBodies[destIndex] = mBodies[srcIndex];
130 new (mColliders + destIndex) Array<Entity>(mColliders[srcIndex]);
131 mIsActive[destIndex] = mIsActive[srcIndex];
132 mUserData[destIndex] = mUserData[srcIndex];
133 mHasSimulationCollider[destIndex] = mHasSimulationCollider[srcIndex];
134
135 // Destroy the source component
136 destroyComponent(srcIndex);
137
138 assert(!mMapEntityToComponentIndex.containsKey(entity));
139
140 // Update the entity to component index mapping
141 mMapEntityToComponentIndex.add(Pair<Entity, uint32>(entity, destIndex));
142
143 assert(mMapEntityToComponentIndex[mBodiesEntities[destIndex]] == destIndex);
144}
145
146// Swap two components in the array
147void BodyComponents::swapComponents(uint32 index1, uint32 index2) {

Callers

nothing calls this directly

Calls 2

containsKeyMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected