Add a component
| 81 | |
| 82 | // Add a component |
| 83 | void TransformComponents::addComponent(Entity bodyEntity, bool isDisabled, const TransformComponent& component) { |
| 84 | |
| 85 | // Prepare to add new component (allocate memory if necessary and compute insertion index) |
| 86 | uint32 index = prepareAddComponent(isDisabled); |
| 87 | |
| 88 | // Insert the new component data |
| 89 | new (mBodies + index) Entity(bodyEntity); |
| 90 | new (mTransforms + index) Transform(component.transform); |
| 91 | |
| 92 | // Map the entity with the new component lookup index |
| 93 | mMapEntityToComponentIndex.add(Pair<Entity, uint32>(bodyEntity, index)); |
| 94 | |
| 95 | mNbComponents++; |
| 96 | |
| 97 | assert(mDisabledStartIndex <= mNbComponents); |
| 98 | assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size())); |
| 99 | } |
| 100 | |
| 101 | // Move a component from a source to a destination index in the components array |
| 102 | // The destination location must contain a constructed object |