MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / initMap

Method initMap

physx/source/scenequery/src/SqAABBTreeUpdateMap.cpp:38–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36static const PxU32 SHRINK_THRESHOLD = 1024;
37
38void 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
92void AABBTreeUpdateMap::invalidate(PoolIndex prunerIndex0, PoolIndex prunerIndex1, AABBTree& tree)
93{

Callers 5

commitMethod · 0.80
buildStepMethod · 0.80
fullRebuildAABBTreeMethod · 0.80
addTreeMethod · 0.80
buildMainAABBTreeMethod · 0.80

Calls 11

releaseFunction · 0.50
capacityMethod · 0.45
resetMethod · 0.45
reserveMethod · 0.45
forceSize_UnsafeMethod · 0.45
getNbNodesMethod · 0.45
getNodesMethod · 0.45
getIndicesMethod · 0.45
isLeafMethod · 0.45
getPrimitivesMethod · 0.45

Tested by

no test coverage detected