| 36 | static const PxU32 SHRINK_THRESHOLD = 1024; |
| 37 | |
| 38 | void AABBTreeUpdateMap::initMap(PxU32 nbObjects, const AABBTree& tree) |
| 39 | { |
| 40 | if(!nbObjects) |
| 41 | { |
| 42 | release(); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | // Memory management |
| 47 | { |
| 48 | const PxU32 mapSize = nbObjects; |
| 49 | const PxU32 targetCapacity = mapSize + (mapSize>>2); |
| 50 | |
| 51 | PxU32 currentCapacity = mMapping.capacity(); |
| 52 | if( ( targetCapacity < (currentCapacity>>1) ) && ( (currentCapacity-targetCapacity) > SHRINK_THRESHOLD ) ) |
| 53 | { |
| 54 | // trigger reallocation of a smaller array, there is enough memory to save |
| 55 | currentCapacity = 0; |
| 56 | } |
| 57 | |
| 58 | if(mapSize > currentCapacity) |
| 59 | { |
| 60 | // the mapping values are invalid and reset below in any case |
| 61 | // so there is no need to copy the values at all |
| 62 | mMapping.reset(); |
| 63 | mMapping.reserve(targetCapacity); // since size is 0, reserve will also just allocate |
| 64 | } |
| 65 | |
| 66 | mMapping.forceSize_Unsafe(mapSize); |
| 67 | |
| 68 | for(PxU32 i=0;i<mapSize;i++) |
| 69 | mMapping[i] = INVALID_NODE_ID; |
| 70 | } |
| 71 | |
| 72 | const PxU32 nbNodes = tree.getNbNodes(); |
| 73 | const AABBTreeRuntimeNode* nodes = tree.getNodes(); |
| 74 | const PxU32* indices = tree.getIndices(); |
| 75 | for(TreeNodeIndex i=0;i<nbNodes;i++) |
| 76 | { |
| 77 | if(nodes[i].isLeaf()) |
| 78 | { |
| 79 | const PxU32 nbPrims = nodes[i].getNbRuntimePrimitives(); |
| 80 | // PT: with multiple primitives per node, several mapping entries will point to the same node. |
| 81 | PX_ASSERT(nbPrims<=16); |
| 82 | for(PxU32 j=0;j<nbPrims;j++) |
| 83 | { |
| 84 | const PxU32 index = nodes[i].getPrimitives(indices)[j]; |
| 85 | PX_ASSERT(index<nbObjects); |
| 86 | mMapping[index] = i; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void AABBTreeUpdateMap::invalidate(PoolIndex prunerIndex0, PoolIndex prunerIndex1, AABBTree& tree) |
| 93 | { |
no test coverage detected