| 418 | //----------------------------------------------------------------------------- |
| 419 | |
| 420 | bool AssetManager::removeDeclaredAsset( const char* pAssetId ) |
| 421 | { |
| 422 | // Debug Profiling. |
| 423 | PROFILE_SCOPE(AssetManager_RemoveSingleDeclaredAsset); |
| 424 | |
| 425 | // Sanity! |
| 426 | AssertFatal( pAssetId != NULL, "Cannot remove single declared asset using NULL asset Id." ); |
| 427 | |
| 428 | // Fetch asset Id. |
| 429 | StringTableEntry assetId = StringTable->insert( pAssetId ); |
| 430 | |
| 431 | // Find declared asset. |
| 432 | typeDeclaredAssetsHash::iterator declaredAssetItr = mDeclaredAssets.find( assetId ); |
| 433 | |
| 434 | // Did we find the declared asset? |
| 435 | if ( declaredAssetItr == mDeclaredAssets.end() ) |
| 436 | { |
| 437 | // No, so warn. |
| 438 | Con::warnf( "Asset Manager: Cannot remove single asset Id '%s' it could not be found.", assetId ); |
| 439 | return false; |
| 440 | } |
| 441 | |
| 442 | // Fetch asset definition. |
| 443 | AssetDefinition* pAssetDefinition = declaredAssetItr->value; |
| 444 | |
| 445 | // Is the asset private? |
| 446 | if ( !pAssetDefinition->mAssetPrivate ) |
| 447 | { |
| 448 | // No, so fetch module assets. |
| 449 | ModuleDefinition::typeModuleAssetsVector& moduleAssets = pAssetDefinition->mpModuleDefinition->getModuleAssets(); |
| 450 | |
| 451 | // Remove module asset. |
| 452 | for ( ModuleDefinition::typeModuleAssetsVector::iterator moduleAssetItr = moduleAssets.begin(); moduleAssetItr != moduleAssets.end(); ++moduleAssetItr ) |
| 453 | { |
| 454 | if ( *moduleAssetItr == pAssetDefinition ) |
| 455 | { |
| 456 | moduleAssets.erase( moduleAssetItr ); |
| 457 | break; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // Remove asset dependencies. |
| 462 | removeAssetDependencies( pAssetId ); |
| 463 | } |
| 464 | |
| 465 | // Do we have an asset loaded? |
| 466 | if ( pAssetDefinition->mpAssetBase != NULL ) |
| 467 | { |
| 468 | // Yes, so delete it. |
| 469 | // NOTE: If anything is using this then this'll cause a crash. Objects should always use safe reference methods however. |
| 470 | pAssetDefinition->mpAssetBase->deleteObject(); |
| 471 | } |
| 472 | |
| 473 | // Remove from declared assets. |
| 474 | mDeclaredAssets.erase( declaredAssetItr ); |
| 475 | |
| 476 | // Info. |
| 477 | if ( mEchoInfo ) |
no test coverage detected