Add a component
| 97 | |
| 98 | // Add a component |
| 99 | void BodyComponents::addComponent(Entity bodyEntity, bool isDisabled, const BodyComponent& component) { |
| 100 | |
| 101 | // Prepare to add new component (allocate memory if necessary and compute insertion index) |
| 102 | uint32 index = prepareAddComponent(isDisabled); |
| 103 | |
| 104 | // Insert the new component data |
| 105 | new (mBodiesEntities + index) Entity(bodyEntity); |
| 106 | mBodies[index] = component.body; |
| 107 | new (mColliders + index) Array<Entity>(mMemoryAllocator); |
| 108 | mIsActive[index] = true; |
| 109 | mUserData[index] = nullptr; |
| 110 | mHasSimulationCollider[index] = false; |
| 111 | |
| 112 | // Map the entity with the new component lookup index |
| 113 | mMapEntityToComponentIndex.add(Pair<Entity, uint32>(bodyEntity, index)); |
| 114 | |
| 115 | mNbComponents++; |
| 116 | |
| 117 | assert(mDisabledStartIndex <= mNbComponents); |
| 118 | assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size())); |
| 119 | } |
| 120 | |
| 121 | // Move a component from a source to a destination index in the components array |
| 122 | // The destination location must contain a constructed object |
no test coverage detected