Commit either performs a refit if background rebuild is not yet finished or swaps the current tree for the second tree rebuilt in the background
| 381 | // Commit either performs a refit if background rebuild is not yet finished |
| 382 | // or swaps the current tree for the second tree rebuilt in the background |
| 383 | void AABBPruner::commit() |
| 384 | { |
| 385 | PX_PROFILE_ZONE("SceneQuery.prunerCommit", mContextID); |
| 386 | |
| 387 | if(!mUncommittedChanges && (mProgress != BUILD_FINISHED)) |
| 388 | // Q: seems like this is both for refit and finalization so is this is correct? |
| 389 | // i.e. in a situation when we started rebuilding a tree and didn't add anything since |
| 390 | // who is going to set mUncommittedChanges to true? |
| 391 | // A: it's set in buildStep at final stage, so that finalization is forced. |
| 392 | // Seems a bit difficult to follow and verify correctness. |
| 393 | return; |
| 394 | |
| 395 | mUncommittedChanges = false; |
| 396 | |
| 397 | if(!mAABBTree || !mIncrementalRebuild) |
| 398 | { |
| 399 | #if PX_CHECKED |
| 400 | if(!mIncrementalRebuild && mAABBTree) |
| 401 | Ps::getFoundation().error(PxErrorCode::ePERF_WARNING, __FILE__, __LINE__, "SceneQuery static AABB Tree rebuilt, because a shape attached to a static actor was added, removed or moved, and PxSceneDesc::staticStructure is set to eSTATIC_AABB_TREE."); |
| 402 | #endif |
| 403 | fullRebuildAABBTree(); |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | // Note: it is not safe to call AABBPruner::build() here |
| 408 | // because the first thread will perform one step of the incremental update, |
| 409 | // continue raycasting, while the second thread performs the next step in |
| 410 | // the incremental update |
| 411 | |
| 412 | // Calling Refit() below is safe. It will call |
| 413 | // StaticPruner::build() when necessary. Both will early |
| 414 | // exit if the tree is already up to date, if it is not already, then we |
| 415 | // must be the first thread performing raycasts on a dirty tree and other |
| 416 | // scene query threads will be locked out by the write lock in |
| 417 | // SceneQueryManager::flushUpdates() |
| 418 | |
| 419 | |
| 420 | if (mProgress != BUILD_FINISHED) |
| 421 | { |
| 422 | // Calling refit because the second tree is not ready to be swapped in (mProgress != BUILD_FINISHED) |
| 423 | // Generally speaking as long as things keep moving the second build will never catch up with true state |
| 424 | refitUpdatedAndRemoved(); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | PX_PROFILE_ZONE("SceneQuery.prunerNewTreeFinalize", mContextID); |
| 429 | |
| 430 | { |
| 431 | PX_PROFILE_ZONE("SceneQuery.prunerNewTreeSwitch", mContextID); |
| 432 | |
| 433 | PX_DELETE(mAABBTree); // delete the old tree |
| 434 | PX_FREE_AND_RESET(mCachedBoxes); |
| 435 | mProgress = BUILD_NOT_STARTED; // reset the build state to initial |
| 436 | |
| 437 | // Adjust adaptive term to get closer to specified rebuild rate. |
| 438 | // perform an even division correction to make sure the rebuild rate adds up |
| 439 | if (mNbCalls > mRebuildRateHint) |
| 440 | mAdaptiveRebuildTerm++; |
no test coverage detected