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

Method prepareAddComponent

src/components/Components.cpp:68–99  ·  view source on GitHub ↗

Compute the index where we need to insert the new component

Source from the content-addressed store, hash-verified

66
67// Compute the index where we need to insert the new component
68uint32 Components::prepareAddComponent(bool isDisabled) {
69
70 // If we need to allocate more components
71 if (mNbComponents == mNbAllocatedComponents) {
72 allocate(mNbAllocatedComponents * 2);
73 }
74
75 uint32 index;
76
77 // If the component to add is part of a disabled entity or there are no disabled entity
78 if (isDisabled) {
79
80 // Add the component at the end of the array
81 index = mNbComponents;
82 }
83 // If the component to add is not part of a disabled entity
84 else {
85
86 // If there already are disabled components
87 if (mDisabledStartIndex != mNbComponents) {
88
89 // Move the first disabled component to the end of the array
90 moveComponentToIndex(mDisabledStartIndex, mNbComponents);
91 }
92
93 index = mDisabledStartIndex;
94
95 mDisabledStartIndex++;
96 }
97
98 return index;
99}
100
101// Destroy a component at a given index
102void Components::destroyComponent(uint32 index) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected