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

Method staticSort

physx/source/lowlevelaabb/src/BpBroadPhaseMBP.cpp:721–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

719 #define DEFAULT_NUM_DYNAMIC_BOXES 1024
720
721void Region::staticSort()
722{
723 // For now this version is only compatible with:
724 // MBP_USE_WORDS
725 // MBP_USE_SENTINELS
726
727 mNeedsSorting = false;
728
729 const PxU32 nbStaticBoxes = mNbStaticBoxes;
730 if(!nbStaticBoxes)
731 {
732 mStaticBits.empty();
733 return;
734 }
735
736// PxU32 Time;
737// StartProfile(Time);
738
739 // Roadmap:
740 // - gather updated/modified static boxes
741 // - sort those, and those only
742 // - merge sorted set with previously existing (and previously sorted set)
743
744 // Separate things-to-sort and things-already-sorted
745 const PxU32 totalSize = sizeof(PxU32)*nbStaticBoxes*4;
746 PxU8 stackBuffer[STACK_BUFFER_SIZE_STATIC_SORT];
747 PxU8* tempMemory = totalSize<=STACK_BUFFER_SIZE_STATIC_SORT ? stackBuffer : reinterpret_cast<PxU8*>(MBP_ALLOC_TMP(totalSize));
748 PxU32* minPosList_ToSort = reinterpret_cast<PxU32*>(tempMemory);
749 PxU32* minPosList_Sorted = reinterpret_cast<PxU32*>(tempMemory + sizeof(PxU32)*nbStaticBoxes);
750 PxU32* boxIndices_ToSort = reinterpret_cast<PxU32*>(tempMemory + sizeof(PxU32)*nbStaticBoxes*2);
751 PxU32* boxIndices_Sorted = reinterpret_cast<PxU32*>(tempMemory + sizeof(PxU32)*nbStaticBoxes*3);
752 PxU32 nbToSort = 0;
753 PxU32 nbSorted = 0;
754 for(PxU32 i=0;i<nbStaticBoxes;i++)
755 {
756 if(mStaticBits.isSetChecked(i)) // ### optimize check in that thing
757 {
758 minPosList_ToSort[nbToSort] = mStaticBoxes[i].mMinX;
759 boxIndices_ToSort[nbToSort] = i;
760 nbToSort++;
761 }
762 else
763 {
764 minPosList_Sorted[nbSorted] = mStaticBoxes[i].mMinX;
765 boxIndices_Sorted[nbSorted] = i;
766 PX_ASSERT(nbSorted==0 || minPosList_Sorted[nbSorted-1]<=minPosList_Sorted[nbSorted]);
767 nbSorted++;
768 }
769 }
770 PX_ASSERT(nbSorted+nbToSort==nbStaticBoxes);
771
772// EndProfile(Time);
773// printf("Part1: %d\n", Time);
774
775// StartProfile(Time);
776
777 // Sort things that need sorting
778 const PxU32* sorted;

Callers

nothing calls this directly

Calls 3

initSentinelFunction · 0.85
isStaticMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected