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

Method addComponent

src/components/BodyComponents.cpp:99–119  ·  view source on GitHub ↗

Add a component

Source from the content-addressed store, hash-verified

97
98// Add a component
99void 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

Callers 4

createRigidBodyMethod · 0.45
createJointMethod · 0.45
addColliderMethod · 0.45
addColliderMethod · 0.45

Calls 2

addMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected