Changeset 2908 for code/branches/questsystem5/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
- Timestamp:
- Apr 8, 2009, 12:58:47 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
r2907 r2908 101 101 btDbvtProxy* pb=(btDbvtProxy*)nb->data; 102 102 #if DBVT_BP_SORTPAIRS 103 if(pa->m_uniqueId>pb->m_uniqueId) 104 btSwap(pa,pb); 103 if(pa>pb) btSwap(pa,pb); 105 104 #endif 106 105 pbp->m_paircache->addOverlappingPair(pa,pb); … … 134 133 m_updates_done = 0; 135 134 m_updates_ratio = 0; 136 m_paircache = paircache? paircache : new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache(); 135 m_paircache = paircache? 136 paircache : 137 new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache(); 137 138 m_gid = 0; 138 139 m_pid = 0; … … 210 211 } 211 212 212 struct BroadphaseRayTester : btDbvt::ICollide213 {214 btBroadphaseRayCallback& m_rayCallback;215 BroadphaseRayTester(btBroadphaseRayCallback& orgCallback)216 :m_rayCallback(orgCallback)217 {218 }219 void Process(const btDbvtNode* leaf)220 {221 btDbvtProxy* proxy=(btDbvtProxy*)leaf->data;222 m_rayCallback.process(proxy);223 }224 };225 226 213 void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback,const btVector3& aabbMin,const btVector3& aabbMax) 227 214 { 215 216 struct BroadphaseRayTester : btDbvt::ICollide 217 { 218 btBroadphaseRayCallback& m_rayCallback; 219 BroadphaseRayTester(btBroadphaseRayCallback& orgCallback) 220 :m_rayCallback(orgCallback) 221 { 222 } 223 void Process(const btDbvtNode* leaf) 224 { 225 btDbvtProxy* proxy=(btDbvtProxy*)leaf->data; 226 m_rayCallback.process(proxy); 227 } 228 }; 229 228 230 BroadphaseRayTester callback(rayCallback); 229 231 … … 340 342 } 341 343 #endif 342 343 performDeferredRemoval(dispatcher);344 345 }346 347 void btDbvtBroadphase::performDeferredRemoval(btDispatcher* dispatcher)348 {349 350 if (m_paircache->hasDeferredRemoval())351 {352 353 btBroadphasePairArray& overlappingPairArray = m_paircache->getOverlappingPairArray();354 355 //perform a sort, to find duplicates and to sort 'invalid' pairs to the end356 overlappingPairArray.quickSort(btBroadphasePairSortPredicate());357 358 int invalidPair = 0;359 360 361 int i;362 363 btBroadphasePair previousPair;364 previousPair.m_pProxy0 = 0;365 previousPair.m_pProxy1 = 0;366 previousPair.m_algorithm = 0;367 368 369 for (i=0;i<overlappingPairArray.size();i++)370 {371 372 btBroadphasePair& pair = overlappingPairArray[i];373 374 bool isDuplicate = (pair == previousPair);375 376 previousPair = pair;377 378 bool needsRemoval = false;379 380 if (!isDuplicate)381 {382 //important to perform AABB check that is consistent with the broadphase383 btDbvtProxy* pa=(btDbvtProxy*)pair.m_pProxy0;384 btDbvtProxy* pb=(btDbvtProxy*)pair.m_pProxy1;385 bool hasOverlap = Intersect(pa->leaf->volume,pb->leaf->volume);386 387 if (hasOverlap)388 {389 needsRemoval = false;390 } else391 {392 needsRemoval = true;393 }394 } else395 {396 //remove duplicate397 needsRemoval = true;398 //should have no algorithm399 btAssert(!pair.m_algorithm);400 }401 402 if (needsRemoval)403 {404 m_paircache->cleanOverlappingPair(pair,dispatcher);405 406 pair.m_pProxy0 = 0;407 pair.m_pProxy1 = 0;408 invalidPair++;409 }410 411 }412 413 //perform a sort, to sort 'invalid' pairs to the end414 overlappingPairArray.quickSort(btBroadphasePairSortPredicate());415 overlappingPairArray.resize(overlappingPairArray.size() - invalidPair);416 }417 344 } 418 345 … … 420 347 void btDbvtBroadphase::collide(btDispatcher* dispatcher) 421 348 { 422 /*printf("---------------------------------------------------------\n");423 printf("m_sets[0].m_leaves=%d\n",m_sets[0].m_leaves);424 printf("m_sets[1].m_leaves=%d\n",m_sets[1].m_leaves);425 printf("numPairs = %d\n",getOverlappingPairCache()->getNumOverlappingPairs());426 {427 int i;428 for (i=0;i<getOverlappingPairCache()->getNumOverlappingPairs();i++)429 {430 printf("pair[%d]=(%d,%d),",i,getOverlappingPairCache()->getOverlappingPairArray()[i].m_pProxy0->getUid(),431 getOverlappingPairCache()->getOverlappingPairArray()[i].m_pProxy1->getUid());432 }433 printf("\n");434 }435 */436 437 438 439 349 SPC(m_profiling.m_total); 440 350 /* optimize */ … … 492 402 if(pairs.size()>0) 493 403 { 494 495 int ni=btMin( pairs.size(),btMax<int>(m_newpairs,(pairs.size()*m_cupdates)/100));404 const int ci=pairs.size(); 405 int ni=btMin(ci,btMax<int>(m_newpairs,(ci*m_cupdates)/100)); 496 406 for(int i=0;i<ni;++i) 497 407 { 498 btBroadphasePair& p=pairs[(m_cid+i)% pairs.size()];408 btBroadphasePair& p=pairs[(m_cid+i)%ci]; 499 409 btDbvtProxy* pa=(btDbvtProxy*)p.m_pProxy0; 500 410 btDbvtProxy* pb=(btDbvtProxy*)p.m_pProxy1; … … 502 412 { 503 413 #if DBVT_BP_SORTPAIRS 504 if(pa->m_uniqueId>pb->m_uniqueId) 505 btSwap(pa,pb); 414 if(pa>pb) btSwap(pa,pb); 506 415 #endif 507 416 m_paircache->removeOverlappingPair(pa,pb,dispatcher); … … 558 467 aabbMin=bounds.Mins(); 559 468 aabbMax=bounds.Maxs(); 560 }561 562 void btDbvtBroadphase::resetPool(btDispatcher* dispatcher)563 {564 565 int totalObjects = m_sets[0].m_leaves + m_sets[1].m_leaves;566 if (!totalObjects)567 {568 //reset internal dynamic tree data structures569 m_sets[0].clear();570 m_sets[1].clear();571 572 m_deferedcollide = false;573 m_needcleanup = true;574 m_prediction = 1/(btScalar)2;575 m_stageCurrent = 0;576 m_fixedleft = 0;577 m_fupdates = 1;578 m_dupdates = 0;579 m_cupdates = 10;580 m_newpairs = 1;581 m_updates_call = 0;582 m_updates_done = 0;583 m_updates_ratio = 0;584 585 m_gid = 0;586 m_pid = 0;587 m_cid = 0;588 for(int i=0;i<=STAGECOUNT;++i)589 {590 m_stageRoots[i]=0;591 }592 }593 469 } 594 470 … … 725 601 #undef SPC 726 602 #endif 727
Note: See TracChangeset
for help on using the changeset viewer.