Add a component
| 104 | |
| 105 | // Add a component |
| 106 | void JointComponents::addComponent(Entity jointEntity, bool isDisabled, const JointComponent& component) { |
| 107 | |
| 108 | // Prepare to add new component (allocate memory if necessary and compute insertion index) |
| 109 | uint32 index = prepareAddComponent(isDisabled); |
| 110 | |
| 111 | // Insert the new component data |
| 112 | new (mJointEntities + index) Entity(jointEntity); |
| 113 | new (mBody1Entities + index) Entity(component.body1Entity); |
| 114 | new (mBody2Entities + index) Entity(component.body2Entity); |
| 115 | mJoints[index] = component.joint; |
| 116 | new (mTypes + index) JointType(component.jointType); |
| 117 | new (mPositionCorrectionTechniques + index) JointsPositionCorrectionTechnique(component.positionCorrectionTechnique); |
| 118 | mIsCollisionEnabled[index] = component.isCollisionEnabled; |
| 119 | mIsAlreadyInIsland[index] = false; |
| 120 | |
| 121 | // Map the entity with the new component lookup index |
| 122 | mMapEntityToComponentIndex.add(Pair<Entity, uint32>(jointEntity, index)); |
| 123 | |
| 124 | mNbComponents++; |
| 125 | |
| 126 | assert(mDisabledStartIndex <= mNbComponents); |
| 127 | assert(mNbComponents == static_cast<uint32>(mMapEntityToComponentIndex.size())); |
| 128 | } |
| 129 | |
| 130 | // Move a component from a source to a destination index in the components array |
| 131 | // The destination location must contain a constructed object |