| 97 | } |
| 98 | |
| 99 | PxU32 PruningPool::addObjects(PrunerHandle* results, const PxBounds3* bounds, const PrunerPayload* payload, PxU32 count) |
| 100 | { |
| 101 | for(PxU32 i=0;i<count;i++) |
| 102 | { |
| 103 | if(mNbObjects==mMaxNbObjects) // increase the capacity on overflow |
| 104 | { |
| 105 | if(!resize(PxMax<PxU32>(mMaxNbObjects*2, 64))) |
| 106 | { |
| 107 | // pool can return an invalid handle if memory alloc fails |
| 108 | // should probably have an error here or not handle this |
| 109 | results[i] = INVALID_PRUNERHANDLE; // PT: we need to write the potentially invalid handle to let users know which object failed first |
| 110 | return i; |
| 111 | } |
| 112 | } |
| 113 | PX_ASSERT(mNbObjects!=mMaxNbObjects); |
| 114 | |
| 115 | const PoolIndex index = mNbObjects++; |
| 116 | |
| 117 | // update mHandleToIndex and mIndexToHandle mappings |
| 118 | PrunerHandle handle; |
| 119 | if(mFirstRecycledHandle != INVALID_PRUNERHANDLE) |
| 120 | { |
| 121 | // mFirstRecycledHandle is an entry into a freelist for removed slots |
| 122 | // this path is only taken if we have any removed slots |
| 123 | handle = mFirstRecycledHandle; |
| 124 | mFirstRecycledHandle = mHandleToIndex[handle]; |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | handle = index; |
| 129 | } |
| 130 | |
| 131 | // PT: TODO: investigate why we added mIndexToHandle/mHandleToIndex. The initial design with 'Prunable' objects didn't need these arrays. |
| 132 | |
| 133 | // PT: these 3 arrays are "parallel" |
| 134 | mWorldBoxes [index] = bounds[i]; // store the payload and AABB in parallel arrays |
| 135 | mObjects [index] = payload[i]; |
| 136 | mIndexToHandle [index] = handle; |
| 137 | |
| 138 | mHandleToIndex[handle] = index; |
| 139 | results[i] = handle; |
| 140 | } |
| 141 | return count; |
| 142 | } |
| 143 | |
| 144 | PoolIndex PruningPool::removeObject(PrunerHandle h) |
| 145 | { |