| 1424 | } |
| 1425 | |
| 1426 | void GroundCover::_updateCoverGrid( const Frustum &culler ) |
| 1427 | { |
| 1428 | PROFILE_SCOPE( GroundCover_UpdateCoverGrid ); |
| 1429 | |
| 1430 | mGridSize = getMax( mGridSize, (U32)2 ); |
| 1431 | |
| 1432 | // How many cells in the grid? |
| 1433 | const U32 cells = mGridSize * mGridSize; |
| 1434 | |
| 1435 | // Whats the max placement count for each cell considering |
| 1436 | // the grid size and quality scale LOD value. |
| 1437 | const S32 placementCount = getMax( ( (F32)mMaxPlacement * smDensityScale ) / F32( mGridSize * mGridSize ), 0.0f ); |
| 1438 | |
| 1439 | // If the cell grid isn't sized or the placement count |
| 1440 | // changed (most likely because of quality lod) then we |
| 1441 | // need to initialize the system again. |
| 1442 | if ( mCellGrid.empty() || placementCount != mLastPlacementCount ) |
| 1443 | { |
| 1444 | _initialize( cells, placementCount ); |
| 1445 | mLastPlacementCount = placementCount; |
| 1446 | } |
| 1447 | |
| 1448 | // Without a count... we don't function at all. |
| 1449 | if ( placementCount == 0 ) |
| 1450 | return; |
| 1451 | |
| 1452 | // Clear the scratch grid. |
| 1453 | dMemset( mScratchGrid.address(), 0, mScratchGrid.memSize() ); |
| 1454 | |
| 1455 | // Calculate the normal cell size here. |
| 1456 | const F32 cellSize = ( mRadius * 2.0f ) / (F32)(mGridSize - 1); |
| 1457 | |
| 1458 | // Figure out the root index of the new grid based on the camera position. |
| 1459 | Point2I index( (S32)mFloor( ( culler.getPosition().x - mRadius ) / cellSize ), |
| 1460 | (S32)mFloor( ( culler.getPosition().y - mRadius ) / cellSize ) ); |
| 1461 | |
| 1462 | // Figure out the cell shift between the old and new grid positions. |
| 1463 | Point2I shift = mGridIndex - index; |
| 1464 | |
| 1465 | // If we've shifted more than one in either axis then we've warped. |
| 1466 | bool didWarp = shift.x > 1 || shift.x < -1 || |
| 1467 | shift.y > 1 || shift.y < -1 ? true : false; |
| 1468 | |
| 1469 | // Go thru the grid shifting each cell we find and |
| 1470 | // placing them in the scratch grid. |
| 1471 | for ( S32 i = 0; i < mCellGrid.size(); i++ ) |
| 1472 | { |
| 1473 | GroundCoverCell* cell = mCellGrid[ i ]; |
| 1474 | if ( !cell ) |
| 1475 | continue; |
| 1476 | |
| 1477 | // Whats our new index? |
| 1478 | Point2I newIndex = cell->shiftIndex( shift ); |
| 1479 | |
| 1480 | // Is this cell outside of the new grid? |
| 1481 | if ( newIndex.x < 0 || newIndex.x >= mGridSize || |
| 1482 | newIndex.y < 0 || newIndex.y >= mGridSize ) |
| 1483 | { |
nothing calls this directly
no test coverage detected