assetManager.cc 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "assetManager.h"
  23. #ifndef _ASSET_PTR_H_
  24. #include "assetPtr.h"
  25. #endif
  26. #ifndef _REFERENCED_ASSETS_H_
  27. #include "assets/referencedAssets.h"
  28. #endif
  29. #ifndef _DECLARED_ASSETS_H_
  30. #include "assets/declaredAssets.h"
  31. #endif
  32. #ifndef _TAML_ASSET_REFERENCED_VISITOR_H_
  33. #include "tamlAssetReferencedVisitor.h"
  34. #endif
  35. #ifndef _TAML_ASSET_DECLARED_VISITOR_H_
  36. #include "tamlAssetDeclaredVisitor.h"
  37. #endif
  38. #ifndef _TAML_ASSET_DECLARED_UPDATE_VISITOR_H_
  39. #include "tamlAssetDeclaredUpdateVisitor.h"
  40. #endif
  41. #ifndef _TAML_ASSET_REFERENCED_UPDATE_VISITOR_H_
  42. #include "tamlAssetReferencedUpdateVisitor.h"
  43. #endif
  44. #ifndef _CONSOLETYPES_H_
  45. #include "console/consoleTypes.h"
  46. #endif
  47. // Script bindings.
  48. #include "assetManager_ScriptBinding.h"
  49. //-----------------------------------------------------------------------------
  50. IMPLEMENT_CONOBJECT( AssetManager );
  51. //-----------------------------------------------------------------------------
  52. AssetManager AssetDatabase;
  53. //-----------------------------------------------------------------------------
  54. AssetManager::AssetManager() :
  55. mLoadedInternalAssetsCount( 0 ),
  56. mLoadedExternalAssetsCount( 0 ),
  57. mLoadedPrivateAssetsCount( 0 ),
  58. mMaxLoadedInternalAssetsCount( 0 ),
  59. mMaxLoadedExternalAssetsCount( 0 ),
  60. mMaxLoadedPrivateAssetsCount( 0 ),
  61. mAcquiredReferenceCount( 0 ),
  62. mEchoInfo( false ),
  63. mIgnoreAutoUnload( false )
  64. {
  65. }
  66. //-----------------------------------------------------------------------------
  67. bool AssetManager::onAdd()
  68. {
  69. // Call parent.
  70. if ( !Parent::onAdd() )
  71. return false;
  72. return true;
  73. }
  74. //-----------------------------------------------------------------------------
  75. void AssetManager::onRemove()
  76. {
  77. // Do we have an asset tags manifest?
  78. if ( !mAssetTagsManifest.isNull() )
  79. {
  80. // Yes, so remove it.
  81. mAssetTagsManifest->deleteObject();
  82. }
  83. // Call parent.
  84. Parent::onRemove();
  85. }
  86. //-----------------------------------------------------------------------------
  87. void AssetManager::initPersistFields()
  88. {
  89. // Call parent.
  90. Parent::initPersistFields();
  91. addField( "EchoInfo", TypeBool, Offset(mEchoInfo, AssetManager), "Whether the asset manager echos extra information to the console or not." );
  92. addField( "IgnoreAutoUnload", TypeBool, Offset(mIgnoreAutoUnload, AssetManager), "Whether the asset manager should ignore unloading of auto-unload assets or not." );
  93. }
  94. //-----------------------------------------------------------------------------
  95. bool AssetManager::compileReferencedAssets( ModuleDefinition* pModuleDefinition )
  96. {
  97. // Debug Profiling.
  98. PROFILE_SCOPE(AssetManager_CompileReferencedAsset);
  99. // Sanity!
  100. AssertFatal( pModuleDefinition != NULL, "Cannot add declared assets using a NULL module definition" );
  101. // Clear referenced assets.
  102. mReferencedAssets.clear();
  103. // Iterate the module definition children.
  104. for( SimSet::iterator itr = pModuleDefinition->begin(); itr != pModuleDefinition->end(); ++itr )
  105. {
  106. // Fetch the referenced assets.
  107. ReferencedAssets* pReferencedAssets = dynamic_cast<ReferencedAssets*>( *itr );
  108. // Skip if it's not a referenced assets location.
  109. if ( pReferencedAssets == NULL )
  110. continue;
  111. // Expand asset manifest location.
  112. char filePathBuffer[1024];
  113. dSprintf( filePathBuffer, sizeof(filePathBuffer), "%s/%s", pModuleDefinition->getModulePath(), pReferencedAssets->getPath() );
  114. // Scan referenced assets at location.
  115. if ( !scanReferencedAssets( filePathBuffer, pReferencedAssets->getExtension(), pReferencedAssets->getRecurse() ) )
  116. {
  117. // Warn.
  118. Con::warnf( "AssetManager::compileReferencedAssets() - Could not scan for referenced assets at location '%s' with extension '%s'.", filePathBuffer, pReferencedAssets->getExtension() );
  119. }
  120. }
  121. return true;
  122. }
  123. //-----------------------------------------------------------------------------
  124. bool AssetManager::addModuleDeclaredAssets( ModuleDefinition* pModuleDefinition )
  125. {
  126. // Debug Profiling.
  127. PROFILE_SCOPE(AssetManager_AddDeclaredAssets);
  128. // Sanity!
  129. AssertFatal( pModuleDefinition != NULL, "Cannot add declared assets using a NULL module definition" );
  130. // Does the module have any assets associated with it?
  131. if ( pModuleDefinition->getModuleAssets().size() > 0 )
  132. {
  133. // Yes, so warn.
  134. Con::warnf( "Asset Manager: Cannot add declared assets to module '%s' as it already has existing assets.", pModuleDefinition->getSignature() );
  135. return false;
  136. }
  137. // Iterate the module definition children.
  138. for( SimSet::iterator itr = pModuleDefinition->begin(); itr != pModuleDefinition->end(); ++itr )
  139. {
  140. // Fetch the declared assets.
  141. DeclaredAssets* pDeclaredAssets = dynamic_cast<DeclaredAssets*>( *itr );
  142. // Skip if it's not a declared assets location.
  143. if ( pDeclaredAssets == NULL )
  144. continue;
  145. // Expand asset manifest location.
  146. char filePathBuffer[1024];
  147. dSprintf( filePathBuffer, sizeof(filePathBuffer), "%s/%s", pModuleDefinition->getModulePath(), pDeclaredAssets->getPath() );
  148. // Scan declared assets at location.
  149. if ( !scanDeclaredAssets( filePathBuffer, pDeclaredAssets->getExtension(), pDeclaredAssets->getRecurse(), pModuleDefinition ) )
  150. {
  151. // Warn.
  152. Con::warnf( "AssetManager::addModuleDeclaredAssets() - Could not scan for declared assets at location '%s' with extension '%s'.", filePathBuffer, pDeclaredAssets->getExtension() );
  153. }
  154. }
  155. return true;
  156. }
  157. //-----------------------------------------------------------------------------
  158. bool AssetManager::addDeclaredAsset( ModuleDefinition* pModuleDefinition, const char* pAssetFilePath )
  159. {
  160. // Debug Profiling.
  161. PROFILE_SCOPE(AssetManager_AddSingleDeclaredAsset);
  162. // Sanity!
  163. AssertFatal( pModuleDefinition != NULL, "Cannot add single declared asset using a NULL module definition" );
  164. AssertFatal( pAssetFilePath != NULL, "Cannot add single declared asset using a NULL asset file-path." );
  165. // Expand asset file-path.
  166. char assetFilePathBuffer[1024];
  167. Con::expandPath( assetFilePathBuffer, sizeof(assetFilePathBuffer), pAssetFilePath );
  168. // Find the final slash which should be just before the file.
  169. char* pFileStart = dStrrchr( assetFilePathBuffer, '/' );
  170. // Did we find the final slash?
  171. if ( pFileStart == NULL )
  172. {
  173. // No, so warn.
  174. Con::warnf( "AssetManager::addDeclaredAsset() - Could not add single declared asset file '%s' as file-path '%s' is not valid.",
  175. assetFilePathBuffer,
  176. pModuleDefinition->getModulePath() );
  177. return false;
  178. }
  179. // Terminate path at slash.
  180. *pFileStart = 0;
  181. // Move to next character which should be the file start.
  182. pFileStart++;
  183. // Scan declared assets at location.
  184. if ( !scanDeclaredAssets( assetFilePathBuffer, pFileStart, false, pModuleDefinition ) )
  185. {
  186. // Warn.
  187. Con::warnf( "AssetManager::addDeclaredAsset() - Could not scan declared assets at location '%s' with extension '%s'.", assetFilePathBuffer, pFileStart );
  188. return false;
  189. }
  190. return true;
  191. }
  192. //-----------------------------------------------------------------------------
  193. StringTableEntry AssetManager::addPrivateAsset( AssetBase* pAssetBase )
  194. {
  195. // Debug Profiling.
  196. PROFILE_SCOPE(AssetManager_AddPrivateAsset);
  197. // Sanity!
  198. AssertFatal( pAssetBase != NULL, "Cannot add a NULL private asset." );
  199. // Is the asset already added?
  200. if ( pAssetBase->mpAssetDefinition->mAssetId != StringTable->EmptyString )
  201. {
  202. // Yes, so warn.
  203. Con::warnf( "Cannot add private asset '%d' as it has already been assigned.", pAssetBase->mpAssetDefinition->mAssetId );
  204. return StringTable->EmptyString;
  205. }
  206. static U32 masterPrivateAssetId = 1;
  207. // Create asset definition.
  208. AssetDefinition* pAssetDefinition = new AssetDefinition();
  209. // Fetch source asset definition.
  210. AssetDefinition* pSourceAssetDefinition = pAssetBase->mpAssetDefinition;
  211. // Configure asset.
  212. pAssetDefinition->mpAssetBase = pAssetBase;
  213. pAssetDefinition->mAssetDescription = pSourceAssetDefinition->mAssetDescription;
  214. pAssetDefinition->mAssetCategory = pSourceAssetDefinition->mAssetCategory;
  215. pAssetDefinition->mAssetAutoUnload = true;
  216. pAssetDefinition->mAssetRefreshEnable = false;
  217. pAssetDefinition->mAssetType = StringTable->insert( pAssetBase->getClassName() );
  218. pAssetDefinition->mAssetLoadedCount = 0;
  219. pAssetDefinition->mAssetInternal = false;
  220. pAssetDefinition->mAssetPrivate = true;
  221. // Format asset name.
  222. char assetNameBuffer[256];
  223. dSprintf(assetNameBuffer, sizeof(assetNameBuffer), "%s_%d", pAssetDefinition->mAssetType, masterPrivateAssetId++ );
  224. // Set asset identity.
  225. pAssetDefinition->mAssetName = StringTable->insert( assetNameBuffer );
  226. pAssetDefinition->mAssetId = pAssetDefinition->mAssetName;
  227. // Ensure that the source asset is fully synchronized with the new asset definition.
  228. pSourceAssetDefinition->mAssetName = pAssetDefinition->mAssetName;
  229. pSourceAssetDefinition->mAssetAutoUnload = pAssetDefinition->mAssetAutoUnload;
  230. pSourceAssetDefinition->mAssetInternal = pAssetDefinition->mAssetInternal;
  231. // Set ownership by asset manager.
  232. pAssetDefinition->mpAssetBase->setOwned( this, pAssetDefinition );
  233. // Store in declared assets.
  234. mDeclaredAssets.insert( pAssetDefinition->mAssetId, pAssetDefinition );
  235. // Increase the private loaded asset count.
  236. if ( ++mLoadedPrivateAssetsCount > mMaxLoadedPrivateAssetsCount )
  237. mMaxLoadedPrivateAssetsCount = mLoadedPrivateAssetsCount;
  238. return pAssetDefinition->mAssetId;
  239. }
  240. //-----------------------------------------------------------------------------
  241. bool AssetManager::removeDeclaredAssets( ModuleDefinition* pModuleDefinition )
  242. {
  243. // Debug Profiling.
  244. PROFILE_SCOPE(AssetManager_RemoveDeclaredAssets);
  245. // Sanity!
  246. AssertFatal( pModuleDefinition != NULL, "Cannot remove declared assets using a NULL module definition" );
  247. // Fetch module assets.
  248. ModuleDefinition::typeModuleAssetsVector& moduleAssets = pModuleDefinition->getModuleAssets();
  249. // Remove all module assets.
  250. while ( moduleAssets.size() > 0 )
  251. {
  252. // Fetch asset definition.
  253. AssetDefinition* pAssetDefinition = *moduleAssets.begin();
  254. // Remove this asset.
  255. removeDeclaredAsset( pAssetDefinition->mAssetId );
  256. }
  257. // Info.
  258. if ( mEchoInfo )
  259. Con::printSeparator();
  260. return true;
  261. }
  262. //-----------------------------------------------------------------------------
  263. bool AssetManager::removeDeclaredAsset( const char* pAssetId )
  264. {
  265. // Debug Profiling.
  266. PROFILE_SCOPE(AssetManager_RemoveSingleDeclaredAsset);
  267. // Sanity!
  268. AssertFatal( pAssetId != NULL, "Cannot remove single declared asset using NULL asset Id." );
  269. // Fetch asset Id.
  270. StringTableEntry assetId = StringTable->insert( pAssetId );
  271. // Find declared asset.
  272. typeDeclaredAssetsHash::iterator declaredAssetItr = mDeclaredAssets.find( assetId );
  273. // Did we find the declared asset?
  274. if ( declaredAssetItr == mDeclaredAssets.end() )
  275. {
  276. // No, so warn.
  277. Con::warnf( "Asset Manager: Cannot remove single asset Id '%s' it could not be found.", assetId );
  278. return false;
  279. }
  280. // Fetch asset definition.
  281. AssetDefinition* pAssetDefinition = declaredAssetItr->value;
  282. // Is the asset private?
  283. if ( !pAssetDefinition->mAssetPrivate )
  284. {
  285. // No, so fetch module assets.
  286. ModuleDefinition::typeModuleAssetsVector& moduleAssets = pAssetDefinition->mpModuleDefinition->getModuleAssets();
  287. // Remove module asset.
  288. for ( ModuleDefinition::typeModuleAssetsVector::iterator moduleAssetItr = moduleAssets.begin(); moduleAssetItr != moduleAssets.end(); ++moduleAssetItr )
  289. {
  290. if ( *moduleAssetItr == pAssetDefinition )
  291. {
  292. moduleAssets.erase( moduleAssetItr );
  293. break;
  294. }
  295. }
  296. // Remove asset dependencies.
  297. removeAssetDependencies( pAssetId );
  298. }
  299. // Do we have an asset loaded?
  300. if ( pAssetDefinition->mpAssetBase.notNull() )
  301. {
  302. // Yes, so delete it.
  303. // NOTE: If anything is using this then this'll cause a crash. Objects should always use safe reference methods however.
  304. pAssetDefinition->mpAssetBase->deleteObject();
  305. }
  306. // Remove from declared assets.
  307. mDeclaredAssets.erase( declaredAssetItr );
  308. // Info.
  309. if ( mEchoInfo )
  310. {
  311. Con::printf( "Asset Manager: Removing Asset Id '%s' of type '%s' in asset file '%s'.",
  312. pAssetDefinition->mAssetId,
  313. pAssetDefinition->mAssetType,
  314. pAssetDefinition->mAssetBaseFilePath );
  315. }
  316. // Destroy asset definition.
  317. delete pAssetDefinition;
  318. return true;
  319. }
  320. //-----------------------------------------------------------------------------
  321. StringTableEntry AssetManager::getAssetName( const char* pAssetId )
  322. {
  323. // Find asset definition.
  324. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  325. // Did we find the asset?
  326. if ( pAssetDefinition == NULL )
  327. {
  328. // No, so warn.
  329. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  330. return NULL;
  331. }
  332. return pAssetDefinition->mAssetName;
  333. }
  334. //-----------------------------------------------------------------------------
  335. StringTableEntry AssetManager::getAssetDescription( const char* pAssetId )
  336. {
  337. // Find asset definition.
  338. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  339. // Did we find the asset?
  340. if ( pAssetDefinition == NULL )
  341. {
  342. // No, so warn.
  343. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  344. return NULL;
  345. }
  346. return pAssetDefinition->mAssetDescription;
  347. }
  348. //-----------------------------------------------------------------------------
  349. StringTableEntry AssetManager::getAssetCategory( const char* pAssetId )
  350. {
  351. // Find asset definition.
  352. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  353. // Did we find the asset?
  354. if ( pAssetDefinition == NULL )
  355. {
  356. // No, so warn.
  357. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  358. return NULL;
  359. }
  360. return pAssetDefinition->mAssetCategory;
  361. }
  362. //-----------------------------------------------------------------------------
  363. StringTableEntry AssetManager::getAssetType( const char* pAssetId )
  364. {
  365. // Find asset definition.
  366. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  367. // Did we find the asset?
  368. if ( pAssetDefinition == NULL )
  369. {
  370. // No, so warn.
  371. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  372. return NULL;
  373. }
  374. return pAssetDefinition->mAssetType;
  375. }
  376. //-----------------------------------------------------------------------------
  377. StringTableEntry AssetManager::getAssetFilePath( const char* pAssetId )
  378. {
  379. // Find asset definition.
  380. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  381. // Did we find the asset?
  382. if ( pAssetDefinition == NULL )
  383. {
  384. // No, so warn.
  385. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  386. return StringTable->EmptyString;
  387. }
  388. return pAssetDefinition->mAssetBaseFilePath;
  389. }
  390. //-----------------------------------------------------------------------------
  391. StringTableEntry AssetManager::getAssetPath( const char* pAssetId )
  392. {
  393. // Debug Profiling.
  394. PROFILE_SCOPE(AssetManager_GetAssetPath);
  395. // Fetch asset file-path.
  396. StringTableEntry assetFilePath = getAssetFilePath( pAssetId );
  397. // Finish if no file-path.
  398. if ( assetFilePath == StringTable->EmptyString )
  399. return assetFilePath;
  400. // Find the final slash which should be just before the file.
  401. const char* pFinalSlash = dStrrchr( assetFilePath, '/' );
  402. // Sanity!
  403. AssertFatal( pFinalSlash != NULL, "Should always be able to find final slash in the asset file-path." );
  404. // Fetch asset path.
  405. return StringTable->insertn( assetFilePath, (U32)(pFinalSlash - assetFilePath) );
  406. }
  407. //-----------------------------------------------------------------------------
  408. ModuleDefinition* AssetManager::getAssetModuleDefinition( const char* pAssetId )
  409. {
  410. // Find asset definition.
  411. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  412. // Did we find the asset?
  413. if ( pAssetDefinition == NULL )
  414. {
  415. // No, so warn.
  416. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  417. return NULL;
  418. }
  419. return pAssetDefinition->mpModuleDefinition;
  420. }
  421. //-----------------------------------------------------------------------------
  422. bool AssetManager::isAssetInternal( const char* pAssetId )
  423. {
  424. // Find asset definition.
  425. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  426. // Did we find the asset?
  427. if ( pAssetDefinition == NULL )
  428. {
  429. // No, so warn.
  430. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  431. return false;
  432. }
  433. return pAssetDefinition->mAssetInternal;
  434. }
  435. //-----------------------------------------------------------------------------
  436. bool AssetManager::isAssetPrivate( const char* pAssetId )
  437. {
  438. // Find asset definition.
  439. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  440. // Did we find the asset?
  441. if ( pAssetDefinition == NULL )
  442. {
  443. // No, so warn.
  444. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  445. return false;
  446. }
  447. return pAssetDefinition->mAssetPrivate;
  448. }
  449. //-----------------------------------------------------------------------------
  450. bool AssetManager::isAssetAutoUnload( const char* pAssetId )
  451. {
  452. // Find asset definition.
  453. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  454. // Did we find the asset?
  455. if ( pAssetDefinition == NULL )
  456. {
  457. // No, so warn.
  458. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  459. return false;
  460. }
  461. return pAssetDefinition->mAssetAutoUnload;
  462. }
  463. //-----------------------------------------------------------------------------
  464. bool AssetManager::isAssetLoaded( const char* pAssetId )
  465. {
  466. // Find asset definition.
  467. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  468. // Did we find the asset?
  469. if ( pAssetDefinition == NULL )
  470. {
  471. // No, so warn.
  472. Con::warnf( "Asset Manager: Cannot find asset Id '%s'.", pAssetId );
  473. return false;
  474. }
  475. return pAssetDefinition->mpAssetBase != NULL;
  476. }
  477. //-----------------------------------------------------------------------------
  478. bool AssetManager::isDeclaredAsset( const char* pAssetId )
  479. {
  480. return findAsset( pAssetId ) != NULL;
  481. }
  482. //-----------------------------------------------------------------------------
  483. bool AssetManager::doesAssetDependOn( const char* pAssetId, const char* pDependsOnAssetId )
  484. {
  485. // Debug Profiling.
  486. PROFILE_SCOPE(AssetManager_DoesAssetDependOn);
  487. // Sanity!
  488. AssertFatal( pAssetId != NULL, "Cannot use NULL asset Id." );
  489. AssertFatal( pDependsOnAssetId != NULL, "Cannot use NULL depends-on asset Id." );
  490. // Fetch asset Id.
  491. StringTableEntry assetId = StringTable->insert( pAssetId );
  492. // Fetch depends-on asset Id.
  493. StringTableEntry dependsOnAssetId = StringTable->insert( pDependsOnAssetId );
  494. // Find depends-on entry.
  495. typeAssetDependsOnHash::iterator dependsOnItr = mAssetDependsOn.find( assetId );
  496. // Iterate all dependencies.
  497. while( dependsOnItr != mAssetDependsOn.end() && dependsOnItr->key == assetId )
  498. {
  499. // Finish if a depends on.
  500. if ( dependsOnItr->value == dependsOnAssetId )
  501. return true;
  502. // Next dependency.
  503. dependsOnItr++;
  504. }
  505. return false;
  506. }
  507. //-----------------------------------------------------------------------------
  508. bool AssetManager::isAssetDependedOn( const char* pAssetId, const char* pDependedOnByAssetId )
  509. {
  510. // Debug Profiling.
  511. PROFILE_SCOPE(AssetManager_IsAssetDependedOn);
  512. // Sanity!
  513. AssertFatal( pAssetId != NULL, "Cannot use NULL asset Id." );
  514. AssertFatal( pDependedOnByAssetId != NULL, "Cannot use NULL depended-on-by asset Id." );
  515. // Fetch asset Id.
  516. StringTableEntry assetId = StringTable->insert( pAssetId );
  517. // Fetch depended-on-by asset Id.
  518. StringTableEntry dependedOnByAssetId = StringTable->insert( pDependedOnByAssetId );
  519. // Find depended-on-by entry.
  520. typeAssetDependsOnHash::iterator dependedOnItr = mAssetIsDependedOn.find( assetId );
  521. // Iterate all dependencies.
  522. while( dependedOnItr != mAssetIsDependedOn.end() && dependedOnItr->key == assetId )
  523. {
  524. // Finish if depended-on.
  525. if ( dependedOnItr->value == dependedOnByAssetId )
  526. return true;
  527. // Next dependency.
  528. dependedOnItr++;
  529. }
  530. return false;
  531. }
  532. //-----------------------------------------------------------------------------
  533. bool AssetManager::isReferencedAsset( const char* pAssetId )
  534. {
  535. // Debug Profiling.
  536. PROFILE_SCOPE(AssetManager_IsReferencedAsset);
  537. // Sanity!
  538. AssertFatal( pAssetId != NULL, "Cannot check if NULL asset Id is referenced." );
  539. // Fetch asset Id.
  540. StringTableEntry assetId = StringTable->insert( pAssetId );
  541. // Is asset Id the correct format?
  542. if ( StringUnit::getUnitCount( assetId, ASSET_SCOPE_TOKEN ) != 2 )
  543. {
  544. // No, so warn.
  545. Con::warnf( "Asset Manager: Cannot check if asset Id '%s' is referenced as it is not the correct format.", assetId );
  546. return false;
  547. }
  548. return mReferencedAssets.count( assetId ) > 0;
  549. }
  550. //-----------------------------------------------------------------------------
  551. bool AssetManager::renameDeclaredAsset( const char* pAssetIdFrom, const char* pAssetIdTo )
  552. {
  553. // Debug Profiling.
  554. PROFILE_SCOPE(AssetManager_RenameDeclaredAsset);
  555. // Sanity!
  556. AssertFatal( pAssetIdFrom != NULL, "Cannot rename from NULL asset Id." );
  557. AssertFatal( pAssetIdTo != NULL, "Cannot rename to NULL asset Id." );
  558. // Fetch asset Ids.
  559. StringTableEntry assetIdFrom = StringTable->insert( pAssetIdFrom );
  560. StringTableEntry assetIdTo = StringTable->insert( pAssetIdTo );
  561. // Is asset Id from the correct format?
  562. if ( StringUnit::getUnitCount( assetIdFrom, ASSET_SCOPE_TOKEN ) != 2 )
  563. {
  564. // No, so warn.
  565. Con::warnf("Asset Manager: Cannot rename declared asset Id '%s' to asset Id '%s' as source asset Id is not the correct format.", assetIdFrom, assetIdTo );
  566. return false;
  567. }
  568. // Is asset Id to the correct format?
  569. if ( StringUnit::getUnitCount( assetIdTo, ASSET_SCOPE_TOKEN ) != 2 )
  570. {
  571. // No, so warn.
  572. Con::warnf("Asset Manager: Cannot rename declared asset Id '%s' to asset Id '%s' as target asset Id is not the correct format.", assetIdFrom, assetIdTo );
  573. return false;
  574. }
  575. // Does the asset Id from exist?
  576. if ( !mDeclaredAssets.contains( assetIdFrom ) )
  577. {
  578. // No, so warn.
  579. Con::warnf("Asset Manager: Cannot rename declared asset Id '%s' to asset Id '%s' as source asset Id is not declared.", assetIdFrom, assetIdTo );
  580. return false;
  581. }
  582. // Does the asset Id to exist?
  583. if ( mDeclaredAssets.contains( assetIdTo ) )
  584. {
  585. // No, so warn.
  586. Con::warnf("Asset Manager: Cannot rename declared asset Id '%s' to asset Id '%s' as target asset Id is already declared.", assetIdFrom, assetIdTo );
  587. return false;
  588. }
  589. // Split module Ids from asset Ids.
  590. StringTableEntry moduleIdFrom = StringTable->insert( StringUnit::getUnit( assetIdFrom, 0, ASSET_SCOPE_TOKEN ) );
  591. StringTableEntry moduleIdTo = StringTable->insert( StringUnit::getUnit( assetIdTo, 0, ASSET_SCOPE_TOKEN ) );
  592. // Are the module Ids the same?
  593. if ( moduleIdFrom != moduleIdTo )
  594. {
  595. // No, so warn.
  596. Con::warnf("Asset Manager: Cannot rename declared asset Id '%s' to asset Id '%s' as the module Id cannot be changed.", assetIdFrom, assetIdTo );
  597. return false;
  598. }
  599. // Find asset definition.
  600. typeDeclaredAssetsHash::iterator assetDefinitionItr = mDeclaredAssets.find( assetIdFrom );
  601. // Sanity!
  602. AssertFatal( assetDefinitionItr != mDeclaredAssets.end(), "Asset Manager: Failed to find asset." );
  603. // Fetch asset definition.
  604. AssetDefinition* pAssetDefinition = assetDefinitionItr->value;
  605. // Is this a private asset?
  606. if ( pAssetDefinition->mAssetPrivate )
  607. {
  608. // Yes, so warn.
  609. Con::warnf("Asset Manager: Cannot rename declared asset Id '%s' to asset Id '%s' as the source asset is private.", assetIdFrom, assetIdTo );
  610. return false;
  611. }
  612. // Setup declared update visitor.
  613. TamlAssetDeclaredUpdateVisitor assetDeclaredUpdateVisitor;
  614. assetDeclaredUpdateVisitor.setAssetIdFrom( assetIdFrom );
  615. assetDeclaredUpdateVisitor.setAssetIdTo( assetIdTo );
  616. // Update asset file declaration.
  617. if ( !mTaml.parse( pAssetDefinition->mAssetBaseFilePath, assetDeclaredUpdateVisitor ) )
  618. {
  619. // No, so warn.
  620. Con::warnf("Asset Manager: Cannot rename declared asset Id '%s' to asset Id '%s' as the declared asset file could not be parsed: %s",
  621. assetIdFrom, assetIdTo, pAssetDefinition->mAssetBaseFilePath );
  622. return false;
  623. }
  624. // Update asset definition.
  625. pAssetDefinition->mAssetId = assetIdTo;
  626. pAssetDefinition->mAssetName = StringTable->insert( StringUnit::getUnit( assetIdTo, 1, ASSET_SCOPE_TOKEN ) );
  627. // Reinsert declared asset.
  628. mDeclaredAssets.erase( assetIdFrom );
  629. mDeclaredAssets.insert( assetIdTo, pAssetDefinition );
  630. // Info.
  631. if ( mEchoInfo )
  632. {
  633. Con::printf( "Asset Manager: Renaming declared Asset Id '%s' to Asset Id '%s'.", assetIdFrom, assetIdTo );
  634. Con::printSeparator();
  635. }
  636. // Rename asset dependencies.
  637. renameAssetDependencies( assetIdFrom, assetIdTo );
  638. // Do we have an asset tags manifest?
  639. if ( !mAssetTagsManifest.isNull() )
  640. {
  641. // Yes, so rename any assets.
  642. mAssetTagsManifest->renameAssetId( pAssetIdFrom, pAssetIdTo );
  643. // Save the asset tags.
  644. saveAssetTags();
  645. }
  646. return true;
  647. }
  648. //-----------------------------------------------------------------------------
  649. bool AssetManager::renameReferencedAsset( const char* pAssetIdFrom, const char* pAssetIdTo )
  650. {
  651. // Debug Profiling.
  652. PROFILE_SCOPE(AssetManager_RenameReferencedAsset);
  653. // Sanity!
  654. AssertFatal( pAssetIdFrom != NULL, "Cannot rename from NULL asset Id." );
  655. AssertFatal( pAssetIdTo != NULL, "Cannot rename to NULL asset Id." );
  656. // Fetch asset Ids.
  657. StringTableEntry assetIdFrom = StringTable->insert( pAssetIdFrom );
  658. StringTableEntry assetIdTo = StringTable->insert( pAssetIdTo );
  659. // Is asset Id from the correct format?
  660. if ( StringUnit::getUnitCount( assetIdFrom, ASSET_SCOPE_TOKEN ) != 2 )
  661. {
  662. // No, so warn.
  663. Con::warnf("Asset Manager: Cannot rename referenced asset Id '%s' to asset Id '%s' as source asset Id is not the correct format.", assetIdFrom, assetIdTo );
  664. return false;
  665. }
  666. // Is asset Id to the correct format?
  667. if ( StringUnit::getUnitCount( assetIdTo, ASSET_SCOPE_TOKEN ) != 2 )
  668. {
  669. // No, so warn.
  670. Con::warnf("Asset Manager: Cannot rename referenced asset Id '%s' to asset Id '%s' as target asset Id is not the correct format.", assetIdFrom, assetIdTo );
  671. return false;
  672. }
  673. // Does the asset Id to exist?
  674. if ( !mDeclaredAssets.contains( assetIdTo ) )
  675. {
  676. // No, so warn.
  677. Con::warnf("Asset Manager: Cannot rename referenced asset Id '%s' to asset Id '%s' as target asset Id is not declared.", assetIdFrom, assetIdTo );
  678. return false;
  679. }
  680. // Rename asset references.
  681. renameAssetReferences( assetIdFrom, assetIdTo );
  682. // Info.
  683. if ( mEchoInfo )
  684. Con::printSeparator();
  685. return true;
  686. }
  687. //-----------------------------------------------------------------------------
  688. bool AssetManager::releaseAsset( const char* pAssetId )
  689. {
  690. // Debug Profiling.
  691. PROFILE_SCOPE(AssetManager_ReleaseAsset);
  692. // Sanity!
  693. AssertFatal( pAssetId != NULL, "Cannot release NULL asset Id." );
  694. // Find asset.
  695. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  696. // Did we find the asset?
  697. if ( pAssetDefinition == NULL )
  698. {
  699. // No, so warn.
  700. Con::warnf( "Asset Manager: Failed to release asset Id '%s' as it does not exist.", pAssetId );
  701. return false;
  702. }
  703. // Is the asset loaded?
  704. if ( pAssetDefinition->mpAssetBase == NULL )
  705. {
  706. // No, so warn.
  707. Con::warnf( "Asset Manager: Failed to release asset Id '%s' as it is not acquired.", pAssetId );
  708. return false;
  709. }
  710. // Info.
  711. if ( mEchoInfo )
  712. {
  713. Con::printSeparator();
  714. Con::printf( "Asset Manager: Started releasing Asset Id '%s'...", pAssetId );
  715. }
  716. // Release asset reference.
  717. if ( pAssetDefinition->mpAssetBase->releaseAssetReference() )
  718. {
  719. // Are we ignoring auto-unloaded assets?
  720. if ( mIgnoreAutoUnload )
  721. {
  722. // Yes, so info.
  723. if ( mEchoInfo )
  724. {
  725. Con::printf( "Asset Manager: > Releasing to idle state." );
  726. }
  727. }
  728. else
  729. {
  730. // No, so info.
  731. if ( mEchoInfo )
  732. {
  733. Con::printf( "Asset Manager: > Unload the asset from memory." );
  734. }
  735. // Unload the asset.
  736. unloadAsset( pAssetDefinition );
  737. }
  738. }
  739. // Info.
  740. else if ( mEchoInfo )
  741. {
  742. Con::printf( "Asset Manager: > Reference count now '%d'.", pAssetDefinition->mpAssetBase->getAcquiredReferenceCount() );
  743. }
  744. // Info.
  745. if ( mEchoInfo )
  746. {
  747. Con::printf( "Asset Manager: > Finished releasing Asset Id '%s'.", pAssetId );
  748. Con::printSeparator();
  749. }
  750. return true;
  751. }
  752. //-----------------------------------------------------------------------------
  753. void AssetManager::purgeAssets( void )
  754. {
  755. // Debug Profiling.
  756. PROFILE_SCOPE(AssetManager_PurgeAssets);
  757. // Info.
  758. if ( mEchoInfo )
  759. {
  760. Con::printf( "Asset Manager: Started purging assets..." );
  761. }
  762. // Iterate asset definitions.
  763. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  764. {
  765. // Fetch asset definition.
  766. AssetDefinition* pAssetDefinition = assetItr->value;
  767. // Skip asset if private, not loaded or referenced.
  768. if ( pAssetDefinition->mAssetPrivate ||
  769. pAssetDefinition->mpAssetBase == NULL ||
  770. pAssetDefinition->mpAssetBase->getAcquiredReferenceCount() > 0 )
  771. continue;
  772. // Info.
  773. if ( mEchoInfo )
  774. {
  775. Con::printf( "Asset Manager: Purging asset Id '%s'...", pAssetDefinition->mAssetId );
  776. }
  777. // Unload the asset.
  778. unloadAsset( pAssetDefinition );
  779. }
  780. // Info.
  781. if ( mEchoInfo )
  782. {
  783. Con::printf( "Asset Manager: ... Finished purging assets." );
  784. }
  785. }
  786. //-----------------------------------------------------------------------------
  787. bool AssetManager::deleteAsset( const char* pAssetId, const bool deleteLooseFiles, const bool deleteDependencies )
  788. {
  789. // Debug Profiling.
  790. PROFILE_SCOPE(AssetManager_DeleteAsset);
  791. // Sanity!
  792. AssertFatal( pAssetId != NULL, "Cannot delete NULL asset Id." );
  793. // Find asset.
  794. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  795. // Did we find the asset?
  796. if ( pAssetDefinition == NULL )
  797. {
  798. // No, so warn.
  799. Con::warnf( "Asset Manager: Failed to delete asset Id '%s' as it does not exist.", pAssetId );
  800. return false;
  801. }
  802. // Info.
  803. if ( mEchoInfo )
  804. {
  805. Con::printSeparator();
  806. Con::printf( "Asset Manager: Started deleting Asset Id '%s'...", pAssetId );
  807. }
  808. // Fetch asset Id.
  809. StringTableEntry assetId = StringTable->insert( pAssetId );
  810. // Are we deleting dependencies?
  811. if ( deleteDependencies )
  812. {
  813. Vector<typeAssetId> dependantAssets;
  814. // Yes, so find depended-on-by entry.
  815. typeAssetDependsOnHash::iterator dependedOnItr = mAssetIsDependedOn.find( assetId );
  816. // Iterate all dependencies.
  817. while( dependedOnItr != mAssetIsDependedOn.end() && dependedOnItr->key == assetId )
  818. {
  819. // Store asset Id.
  820. dependantAssets.push_back( dependedOnItr->value );
  821. // Next dependency.
  822. dependedOnItr++;
  823. }
  824. // Do we have any dependants?
  825. if ( dependantAssets.size() > 0 )
  826. {
  827. // Yes, so iterate dependants.
  828. for( Vector<typeAssetId>::const_iterator assetItr = dependantAssets.begin(); assetItr != dependantAssets.end(); ++assetItr )
  829. {
  830. StringTableEntry dependentAssetId = *assetItr;
  831. // Info.
  832. if ( mEchoInfo )
  833. {
  834. Con::printSeparator();
  835. Con::printf( "Asset Manager: Deleting Asset Id '%s' dependant of '%s.'", pAssetId, dependentAssetId );
  836. }
  837. // Delete dependant.
  838. deleteAsset( dependentAssetId, deleteLooseFiles, deleteDependencies );
  839. }
  840. }
  841. }
  842. // Remove asset references.
  843. removeAssetReferences( assetId );
  844. // Are we deleting loose files?
  845. if ( deleteLooseFiles )
  846. {
  847. // Yes, so remove loose files.
  848. Vector<StringTableEntry>& assetLooseFiles = pAssetDefinition->mAssetLooseFiles;
  849. for( Vector<StringTableEntry>::iterator looseFileItr = assetLooseFiles.begin(); looseFileItr != assetLooseFiles.end(); ++looseFileItr )
  850. {
  851. // Fetch loose file.
  852. StringTableEntry looseFile = *looseFileItr;
  853. // Delete the loose file.
  854. if ( !Platform::fileDelete( looseFile ) )
  855. {
  856. // Failed so warn.
  857. Con::warnf( "Asset Manager: Failed to delete the loose file '%s' while deleting asset Id '%s'.", looseFile, pAssetId );
  858. }
  859. }
  860. }
  861. // Fetch asset definition file.
  862. StringTableEntry assetDefinitionFile = pAssetDefinition->mAssetBaseFilePath;
  863. // Remove reference here as we're about to remove the declared asset.
  864. pAssetDefinition = NULL;
  865. // Remove asset.
  866. removeDeclaredAsset( pAssetId );
  867. // Delete the asset definition file.
  868. if ( !Platform::fileDelete( assetDefinitionFile ) )
  869. {
  870. // Failed so warn.
  871. Con::warnf( "Asset Manager: Failed to delete the asset definition file '%s' while deleting asset Id '%s'.", assetDefinitionFile, pAssetId );
  872. }
  873. // Info.
  874. if ( mEchoInfo )
  875. {
  876. Con::printSeparator();
  877. Con::printf( "Asset Manager: Finished deleting Asset Id '%s'.", pAssetId );
  878. }
  879. return true;
  880. }
  881. //-----------------------------------------------------------------------------
  882. bool AssetManager::refreshAsset( const char* pAssetId )
  883. {
  884. // Debug Profiling.
  885. PROFILE_SCOPE(AssetManager_RefreshAsset);
  886. // Sanity!
  887. AssertFatal( pAssetId != NULL, "Cannot refresh NULL asset Id." );
  888. // Find asset.
  889. AssetDefinition* pAssetDefinition = findAsset( pAssetId );
  890. // Did we find the asset?
  891. if ( pAssetDefinition == NULL )
  892. {
  893. // No, so warn.
  894. Con::warnf( "Asset Manager: Failed to refresh asset Id '%s' as it does not exist.", pAssetId );
  895. return false;
  896. }
  897. // Info.
  898. if ( mEchoInfo )
  899. {
  900. Con::printSeparator();
  901. Con::printf( "Asset Manager: Started refreshing Asset Id '%s'...", pAssetId );
  902. }
  903. // Fetch asset Id.
  904. StringTableEntry assetId = StringTable->insert( pAssetId );
  905. // Is the asset private?
  906. if ( pAssetDefinition->mAssetPrivate )
  907. {
  908. // Yes, so notify asset of asset refresh only.
  909. pAssetDefinition->mpAssetBase->onAssetRefresh();
  910. // Asset refresh notifications.
  911. for( typeAssetPtrRefreshHash::iterator refreshNotifyItr = mAssetPtrRefreshNotifications.begin(); refreshNotifyItr != mAssetPtrRefreshNotifications.end(); ++refreshNotifyItr )
  912. {
  913. // Fetch pointed asset.
  914. StringTableEntry pointedAsset = refreshNotifyItr->key->getAssetId();
  915. // Ignore if the pointed asset is not the asset or a dependency.
  916. if ( pointedAsset == StringTable->EmptyString || ( pointedAsset != assetId && !doesAssetDependOn( pointedAsset, assetId ) ) )
  917. continue;
  918. // Perform refresh notification callback.
  919. refreshNotifyItr->value->onAssetRefreshed( refreshNotifyItr->key );
  920. }
  921. }
  922. // Is the asset definition allowed to refresh?
  923. else if ( pAssetDefinition->mAssetRefreshEnable )
  924. {
  925. // Yes, so fetch the asset.
  926. AssetBase* pAssetBase = pAssetDefinition->mpAssetBase;
  927. // Is the asset loaded?
  928. if ( pAssetBase != NULL )
  929. {
  930. // Yes, so notify asset of asset refresh.
  931. pAssetBase->onAssetRefresh();
  932. // Save asset.
  933. mTaml.write( pAssetBase, pAssetDefinition->mAssetBaseFilePath );
  934. // Remove asset dependencies.
  935. removeAssetDependencies( pAssetId );
  936. // Find any new dependencies.
  937. TamlAssetDeclaredVisitor assetDeclaredVisitor;
  938. // Parse the filename.
  939. if ( !mTaml.parse( pAssetDefinition->mAssetBaseFilePath, assetDeclaredVisitor ) )
  940. {
  941. // Warn.
  942. Con::warnf( "Asset Manager: Failed to parse file containing asset declaration: '%s'.\nDependencies are now incorrect!", pAssetDefinition->mAssetBaseFilePath );
  943. return false;
  944. }
  945. // Fetch asset dependencies.
  946. TamlAssetDeclaredVisitor::typeAssetIdVector& assetDependencies = assetDeclaredVisitor.getAssetDependencies();
  947. // Are there any asset dependences?
  948. if ( assetDependencies.size() > 0 )
  949. {
  950. // Yes, so iterate dependencies.
  951. for( TamlAssetDeclaredVisitor::typeAssetIdVector::iterator assetDependencyItr = assetDependencies.begin(); assetDependencyItr != assetDependencies.end(); ++assetDependencyItr )
  952. {
  953. // Fetch dependency asset Id.
  954. StringTableEntry dependencyAssetId = *assetDependencyItr;
  955. // Insert depends-on.
  956. mAssetDependsOn.insertEqual( assetId, dependencyAssetId );
  957. // Insert is-depended-on.
  958. mAssetIsDependedOn.insertEqual( dependencyAssetId, assetId );
  959. }
  960. }
  961. // Fetch asset loose files.
  962. TamlAssetDeclaredVisitor::typeLooseFileVector& assetLooseFiles = assetDeclaredVisitor.getAssetLooseFiles();
  963. // Clear any existing loose files.
  964. pAssetDefinition->mAssetLooseFiles.clear();
  965. // Are there any loose files?
  966. if ( assetLooseFiles.size() > 0 )
  967. {
  968. // Yes, so iterate loose files.
  969. for( TamlAssetDeclaredVisitor::typeLooseFileVector::iterator assetLooseFileItr = assetLooseFiles.begin(); assetLooseFileItr != assetLooseFiles.end(); ++assetLooseFileItr )
  970. {
  971. // Store loose file.
  972. pAssetDefinition->mAssetLooseFiles.push_back( *assetLooseFileItr );
  973. }
  974. }
  975. // Asset refresh notifications.
  976. for( typeAssetPtrRefreshHash::iterator refreshNotifyItr = mAssetPtrRefreshNotifications.begin(); refreshNotifyItr != mAssetPtrRefreshNotifications.end(); ++refreshNotifyItr )
  977. {
  978. // Fetch pointed asset.
  979. StringTableEntry pointedAsset = refreshNotifyItr->key->getAssetId();
  980. // Ignore if the pointed asset is not the asset or a dependency.
  981. if ( pointedAsset == StringTable->EmptyString || ( pointedAsset != assetId && !doesAssetDependOn( pointedAsset, assetId ) ) )
  982. continue;
  983. // Perform refresh notification callback.
  984. refreshNotifyItr->value->onAssetRefreshed( refreshNotifyItr->key );
  985. }
  986. // Find is-depends-on entry.
  987. typeAssetIsDependedOnHash::iterator isDependedOnItr = mAssetIsDependedOn.find( assetId );
  988. // Is asset depended on?
  989. if ( isDependedOnItr != mAssetIsDependedOn.end() )
  990. {
  991. // Yes, so compiled them.
  992. Vector<typeAssetId> dependedOn;
  993. // Iterate all dependencies.
  994. while( isDependedOnItr != mAssetIsDependedOn.end() && isDependedOnItr->key == assetId )
  995. {
  996. dependedOn.push_back( isDependedOnItr->value );
  997. // Next dependency.
  998. isDependedOnItr++;
  999. }
  1000. // Refresh depended-on assets.
  1001. for ( Vector<typeAssetId>::iterator isDependedOnItr = dependedOn.begin(); isDependedOnItr != dependedOn.end(); ++isDependedOnItr )
  1002. {
  1003. // Refresh dependency asset.
  1004. refreshAsset( *isDependedOnItr );
  1005. }
  1006. }
  1007. }
  1008. }
  1009. // Info.
  1010. if ( mEchoInfo )
  1011. {
  1012. Con::printSeparator();
  1013. Con::printf( "Asset Manager: Finished refreshing Asset Id '%s'.", pAssetId );
  1014. }
  1015. return true;
  1016. }
  1017. //-----------------------------------------------------------------------------
  1018. void AssetManager::refreshAllAssets( const bool includeUnloaded )
  1019. {
  1020. // Debug Profiling.
  1021. PROFILE_SCOPE(AssetManager_RefreshAllAssets);
  1022. // Info.
  1023. if ( mEchoInfo )
  1024. {
  1025. Con::printSeparator();
  1026. Con::printf( "Asset Manager: Started refreshing ALL assets." );
  1027. }
  1028. Vector<typeAssetId> assetsToRelease;
  1029. // Are we including unloaded assets?
  1030. if ( includeUnloaded )
  1031. {
  1032. // Yes, so prepare a list of assets to release and load them.
  1033. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1034. {
  1035. // Fetch asset Id.
  1036. typeAssetId assetId = assetItr->key;
  1037. // Skip if asset is loaded.
  1038. if ( assetItr->value->mpAssetBase != NULL )
  1039. continue;
  1040. // Note asset as needing a release.
  1041. assetsToRelease.push_back( assetId );
  1042. // Acquire the asset.
  1043. acquireAsset<AssetBase>( assetId );
  1044. }
  1045. }
  1046. // Refresh the current loaded assets.
  1047. // NOTE: This will result in some assets being refreshed more than once due to asset dependencies.
  1048. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1049. {
  1050. // Skip private assets.
  1051. if ( assetItr->value->mAssetPrivate )
  1052. continue;
  1053. // Refresh asset if it's loaded.
  1054. refreshAsset( assetItr->key );
  1055. }
  1056. // Are we including unloaded assets?
  1057. if ( includeUnloaded )
  1058. {
  1059. // Yes, so release the assets we loaded.
  1060. for( Vector<typeAssetId>::iterator assetItr = assetsToRelease.begin(); assetItr != assetsToRelease.end(); ++assetItr )
  1061. {
  1062. releaseAsset( *assetItr );
  1063. }
  1064. }
  1065. // Info.
  1066. if ( mEchoInfo )
  1067. {
  1068. Con::printSeparator();
  1069. Con::printf( "Asset Manager: Finished refreshing ALL assets." );
  1070. }
  1071. }
  1072. //-----------------------------------------------------------------------------
  1073. void AssetManager::registerAssetPtrRefreshNotify( AssetPtrBase* pAssetPtrBase, AssetPtrCallback* pCallback )
  1074. {
  1075. // Find an existing notification iterator.
  1076. typeAssetPtrRefreshHash::iterator notificationItr = mAssetPtrRefreshNotifications.find( pAssetPtrBase );
  1077. // Do we have one?
  1078. if ( notificationItr != mAssetPtrRefreshNotifications.end() )
  1079. {
  1080. // Yes, so update the callback.
  1081. notificationItr->value = pCallback;
  1082. return;
  1083. }
  1084. // No, so add one.
  1085. mAssetPtrRefreshNotifications.insert( pAssetPtrBase, pCallback );
  1086. }
  1087. //-----------------------------------------------------------------------------
  1088. void AssetManager::unregisterAssetPtrRefreshNotify( AssetPtrBase* pAssetPtrBase )
  1089. {
  1090. mAssetPtrRefreshNotifications.erase( pAssetPtrBase );
  1091. }
  1092. //-----------------------------------------------------------------------------
  1093. bool AssetManager::loadAssetTags( ModuleDefinition* pModuleDefinition )
  1094. {
  1095. // Sanity!
  1096. AssertFatal( pModuleDefinition != NULL, "Cannot load asset tags manifest using a NULL module definition" );
  1097. // Expand manifest location.
  1098. char assetTagsManifestFilePathBuffer[1024];
  1099. Con::expandPath( assetTagsManifestFilePathBuffer, sizeof(assetTagsManifestFilePathBuffer), pModuleDefinition->getAssetTagsManifest() );
  1100. // Do we already have a manifest?
  1101. if ( !mAssetTagsManifest.isNull() )
  1102. {
  1103. // Yes, so warn.
  1104. Con::warnf( "Asset Manager: Cannot load asset tags manifest from module '%s' as one is already loaded.", pModuleDefinition->getSignature() );
  1105. return false;
  1106. }
  1107. // Is the specified file valid?
  1108. if ( Platform::isFile( assetTagsManifestFilePathBuffer ) )
  1109. {
  1110. // Yes, so read asset tags manifest.
  1111. mAssetTagsManifest = mTaml.read<AssetTagsManifest>( assetTagsManifestFilePathBuffer );
  1112. // Did we read the manifest?
  1113. if ( mAssetTagsManifest.isNull() )
  1114. {
  1115. // No, so warn.
  1116. Con::warnf( "Asset Manager: Failed to load asset tags manifest '%s' from module '%s'.", assetTagsManifestFilePathBuffer, pModuleDefinition->getSignature() );
  1117. return false;
  1118. }
  1119. // Set asset tags module definition.
  1120. mAssetTagsModuleDefinition = pModuleDefinition;
  1121. }
  1122. else
  1123. {
  1124. // No, so generate a new asset tags manifest.
  1125. mAssetTagsManifest = new AssetTagsManifest();
  1126. mAssetTagsManifest->registerObject();
  1127. // Set asset tags module definition.
  1128. mAssetTagsModuleDefinition = pModuleDefinition;
  1129. // Save the asset tags.
  1130. saveAssetTags();
  1131. }
  1132. return true;
  1133. }
  1134. //-----------------------------------------------------------------------------
  1135. bool AssetManager::saveAssetTags( void )
  1136. {
  1137. // Do we have an asset tags manifest?
  1138. if ( mAssetTagsManifest.isNull() || mAssetTagsModuleDefinition.isNull() )
  1139. {
  1140. // No, so warn.
  1141. Con::warnf( "Asset Manager: Failed to save asset tags manifest as one is not loaded." );
  1142. return false;
  1143. }
  1144. // Expand manifest location.
  1145. char assetTagsManifestFilePathBuffer[1024];
  1146. Con::expandPath( assetTagsManifestFilePathBuffer, sizeof(assetTagsManifestFilePathBuffer), mAssetTagsModuleDefinition->getAssetTagsManifest() );
  1147. // Save asset tags manifest.
  1148. if ( !mTaml.write( mAssetTagsManifest, assetTagsManifestFilePathBuffer ) )
  1149. {
  1150. // Failed so warn.
  1151. Con::warnf( "Asset Manager: Failed to save asset tags manifest '%s' from module '%s'.", assetTagsManifestFilePathBuffer, mAssetTagsModuleDefinition->getSignature() );
  1152. return false;
  1153. }
  1154. return true;
  1155. }
  1156. //-----------------------------------------------------------------------------
  1157. bool AssetManager::restoreAssetTags( void )
  1158. {
  1159. // Do we already have a manifest?
  1160. if ( mAssetTagsManifest.isNull() )
  1161. {
  1162. // No, so warn.
  1163. Con::warnf( "Asset Manager: Cannot restore asset tags manifest as one is not already loaded." );
  1164. return false;
  1165. }
  1166. // Sanity!
  1167. AssertFatal( mAssetTagsModuleDefinition != NULL, "Cannot restore asset tags manifest as module definition is NULL." );
  1168. // Delete existing asset tags manifest.
  1169. mAssetTagsManifest->deleteObject();
  1170. // Reload asset tags manifest.
  1171. return loadAssetTags( mAssetTagsModuleDefinition );
  1172. }
  1173. //-----------------------------------------------------------------------------
  1174. S32 QSORT_CALLBACK descendingAssetDefinitionLoadCount(const void* a, const void* b)
  1175. {
  1176. // Debug Profiling.
  1177. PROFILE_SCOPE(AssetManager_DescendingAssetDefinitionLoadCount);
  1178. // Fetch asset definitions.
  1179. const AssetDefinition* pAssetDefinitionA = *(AssetDefinition**)a;
  1180. const AssetDefinition* pAssetDefinitionB = *(AssetDefinition**)b;
  1181. // Sort.
  1182. return pAssetDefinitionB->mAssetLoadedCount - pAssetDefinitionA->mAssetLoadedCount;
  1183. }
  1184. //-----------------------------------------------------------------------------
  1185. void AssetManager::dumpDeclaredAssets( void ) const
  1186. {
  1187. Vector<const AssetDefinition*> assetDefinitions;
  1188. // Iterate asset definitions.
  1189. for( typeDeclaredAssetsHash::const_iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1190. {
  1191. assetDefinitions.push_back( assetItr->value );
  1192. }
  1193. // Sort asset definitions.
  1194. dQsort( assetDefinitions.address(), assetDefinitions.size(), sizeof(const AssetDefinition*), descendingAssetDefinitionLoadCount );
  1195. // Info.
  1196. Con::printSeparator();
  1197. Con::printf( "Asset Manager: %d declared asset(s) dump as follows:", mDeclaredAssets.size() );
  1198. Con::printBlankLine();
  1199. // Iterate sorted asset definitions.
  1200. for ( Vector<const AssetDefinition*>::iterator assetItr = assetDefinitions.begin(); assetItr != assetDefinitions.end(); ++assetItr )
  1201. {
  1202. // Fetch asset definition.
  1203. const AssetDefinition* pAssetDefinition = *assetItr;
  1204. // Info.
  1205. Con::printf( "AssetId:'%s', RefCount:%d, LoadCount:%d, UnloadCount:%d, AutoUnload:%d, Loaded:%d, Internal:%d, Private: %d, Type:'%s', Module/Version:'%s'/'%d', File:'%s'",
  1206. pAssetDefinition->mAssetId,
  1207. pAssetDefinition->mpAssetBase == NULL ? 0 : pAssetDefinition->mpAssetBase->getAcquiredReferenceCount(),
  1208. pAssetDefinition->mAssetLoadedCount,
  1209. pAssetDefinition->mAssetUnloadedCount,
  1210. pAssetDefinition->mAssetAutoUnload,
  1211. pAssetDefinition->mpAssetBase != NULL,
  1212. pAssetDefinition->mAssetInternal,
  1213. pAssetDefinition->mAssetPrivate,
  1214. pAssetDefinition->mAssetType,
  1215. pAssetDefinition->mpModuleDefinition->getModuleId(),
  1216. pAssetDefinition->mpModuleDefinition->getVersionId(),
  1217. pAssetDefinition->mAssetBaseFilePath );
  1218. }
  1219. // Info.
  1220. Con::printSeparator();
  1221. Con::printBlankLine();
  1222. }
  1223. //-----------------------------------------------------------------------------
  1224. S32 AssetManager::findAllAssets( AssetQuery* pAssetQuery, const bool ignoreInternal, const bool ignorePrivate )
  1225. {
  1226. // Debug Profiling.
  1227. PROFILE_SCOPE(AssetManager_FindAllAssets);
  1228. // Sanity!
  1229. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1230. // Reset result count.
  1231. S32 resultCount = 0;
  1232. // Iterate declared assets.
  1233. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1234. {
  1235. // Fetch asset definition.
  1236. AssetDefinition* pAssetDefinition = assetItr->value;
  1237. // Skip if internal and we're ignoring them.
  1238. if ( ignoreInternal && pAssetDefinition->mAssetInternal )
  1239. continue;
  1240. // Skip if private and we're ignoring them.
  1241. if ( ignorePrivate && pAssetDefinition->mAssetPrivate )
  1242. continue;
  1243. // Store as result.
  1244. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1245. // Increase result count.
  1246. resultCount++;
  1247. }
  1248. return resultCount;
  1249. }
  1250. //-----------------------------------------------------------------------------
  1251. S32 AssetManager::findAssetName( AssetQuery* pAssetQuery, const char* pAssetName, const bool partialName )
  1252. {
  1253. // Debug Profiling.
  1254. PROFILE_SCOPE(AssetManager_FindAssetName);
  1255. // Sanity!
  1256. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1257. AssertFatal( pAssetName != NULL, "Cannot use NULL asset name." );
  1258. // Reset asset name.
  1259. StringTableEntry assetName = NULL;
  1260. S32 partialAssetNameLength = 0;
  1261. // Are we doing partial name search?
  1262. if ( partialName )
  1263. {
  1264. // Yes, so fetch length of partial name.
  1265. partialAssetNameLength = dStrlen( pAssetName );
  1266. }
  1267. else
  1268. {
  1269. // No, so fetch asset name.
  1270. assetName = StringTable->insert( pAssetName );
  1271. }
  1272. // Reset result count.
  1273. S32 resultCount = 0;
  1274. // Iterate declared assets.
  1275. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1276. {
  1277. // Fetch asset definition.
  1278. AssetDefinition* pAssetDefinition = assetItr->value;
  1279. // Are we doing partial name search?
  1280. if ( partialName )
  1281. {
  1282. // Yes, so fetch the length of this asset name.
  1283. const S32 currentAssetNameLength = dStrlen( pAssetDefinition->mAssetName );
  1284. // Skip if the query asset name is longer than the current asset name.
  1285. if ( partialAssetNameLength > currentAssetNameLength )
  1286. continue;
  1287. // Skip if this is not the asset we want.
  1288. if ( dStrnicmp( pAssetDefinition->mAssetName, pAssetName, partialAssetNameLength ) != 0 )
  1289. continue;
  1290. }
  1291. else
  1292. {
  1293. // No, so skip if this is not the asset we want.
  1294. if ( assetName != pAssetDefinition->mAssetName )
  1295. continue;
  1296. }
  1297. // Store as result.
  1298. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1299. // Increase result count.
  1300. resultCount++;
  1301. }
  1302. return resultCount;
  1303. }
  1304. //-----------------------------------------------------------------------------
  1305. S32 AssetManager::findAssetCategory( AssetQuery* pAssetQuery, const char* pAssetCategory, const bool assetQueryAsSource )
  1306. {
  1307. // Debug Profiling.
  1308. PROFILE_SCOPE(AssetManager_FindAssetCategory);
  1309. // Sanity!
  1310. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1311. AssertFatal( pAssetCategory != NULL, "Cannot use NULL asset category." );
  1312. // Fetch asset category.
  1313. StringTableEntry assetCategory = StringTable->insert( pAssetCategory );
  1314. // Reset result count.
  1315. S32 resultCount = 0;
  1316. // Use asset-query as the source?
  1317. if ( assetQueryAsSource )
  1318. {
  1319. AssetQuery filteredAssets;
  1320. // Yes, so iterate asset query.
  1321. for( Vector<StringTableEntry>::iterator assetItr = pAssetQuery->begin(); assetItr != pAssetQuery->end(); ++assetItr )
  1322. {
  1323. // Fetch asset definition.
  1324. AssetDefinition* pAssetDefinition = findAsset( *assetItr );
  1325. // Skip if this is not the asset we want.
  1326. if ( pAssetDefinition == NULL ||
  1327. pAssetDefinition->mAssetCategory != assetCategory )
  1328. continue;
  1329. // Store as result.
  1330. filteredAssets.push_back( pAssetDefinition->mAssetId );
  1331. // Increase result count.
  1332. resultCount++;
  1333. }
  1334. // Set asset query.
  1335. pAssetQuery->set( filteredAssets );
  1336. }
  1337. else
  1338. {
  1339. // No, so iterate declared assets.
  1340. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1341. {
  1342. // Fetch asset definition.
  1343. AssetDefinition* pAssetDefinition = assetItr->value;
  1344. // Skip if this is not the asset we want.
  1345. if ( assetCategory != pAssetDefinition->mAssetCategory )
  1346. continue;
  1347. // Store as result.
  1348. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1349. // Increase result count.
  1350. resultCount++;
  1351. }
  1352. }
  1353. return resultCount;
  1354. }
  1355. S32 AssetManager::findAssetAutoUnload( AssetQuery* pAssetQuery, const bool assetAutoUnload, const bool assetQueryAsSource )
  1356. {
  1357. // Debug Profiling.
  1358. PROFILE_SCOPE(AssetManager_FindAssetAutoUnload);
  1359. // Sanity!
  1360. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1361. // Reset result count.
  1362. S32 resultCount = 0;
  1363. // Use asset-query as the source?
  1364. if ( assetQueryAsSource )
  1365. {
  1366. AssetQuery filteredAssets;
  1367. // Yes, so iterate asset query.
  1368. for( Vector<StringTableEntry>::iterator assetItr = pAssetQuery->begin(); assetItr != pAssetQuery->end(); ++assetItr )
  1369. {
  1370. // Fetch asset definition.
  1371. AssetDefinition* pAssetDefinition = findAsset( *assetItr );
  1372. // Skip if this is not the asset we want.
  1373. if ( pAssetDefinition == NULL ||
  1374. pAssetDefinition->mAssetAutoUnload != assetAutoUnload )
  1375. continue;
  1376. // Store as result.
  1377. filteredAssets.push_back( pAssetDefinition->mAssetId );
  1378. // Increase result count.
  1379. resultCount++;
  1380. }
  1381. // Set asset query.
  1382. pAssetQuery->set( filteredAssets );
  1383. }
  1384. else
  1385. {
  1386. // No, so iterate declared assets.
  1387. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1388. {
  1389. // Fetch asset definition.
  1390. AssetDefinition* pAssetDefinition = assetItr->value;
  1391. // Skip if this is not the asset we want.
  1392. if ( assetAutoUnload != pAssetDefinition->mAssetAutoUnload )
  1393. continue;
  1394. // Store as result.
  1395. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1396. // Increase result count.
  1397. resultCount++;
  1398. }
  1399. }
  1400. return resultCount;
  1401. }
  1402. //-----------------------------------------------------------------------------
  1403. S32 AssetManager::findAssetInternal( AssetQuery* pAssetQuery, const bool assetInternal, const bool assetQueryAsSource )
  1404. {
  1405. // Debug Profiling.
  1406. PROFILE_SCOPE(AssetManager_FindAssetInternal);
  1407. // Sanity!
  1408. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1409. // Reset result count.
  1410. S32 resultCount = 0;
  1411. // Use asset-query as the source?
  1412. if ( assetQueryAsSource )
  1413. {
  1414. AssetQuery filteredAssets;
  1415. // Yes, so iterate asset query.
  1416. for( Vector<StringTableEntry>::iterator assetItr = pAssetQuery->begin(); assetItr != pAssetQuery->end(); ++assetItr )
  1417. {
  1418. // Fetch asset definition.
  1419. AssetDefinition* pAssetDefinition = findAsset( *assetItr );
  1420. // Skip if this is not the asset we want.
  1421. if ( pAssetDefinition == NULL ||
  1422. pAssetDefinition->mAssetInternal != assetInternal )
  1423. continue;
  1424. // Store as result.
  1425. filteredAssets.push_back( pAssetDefinition->mAssetId );
  1426. // Increase result count.
  1427. resultCount++;
  1428. }
  1429. // Set asset query.
  1430. pAssetQuery->set( filteredAssets );
  1431. }
  1432. else
  1433. {
  1434. // No, so iterate declared assets.
  1435. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1436. {
  1437. // Fetch asset definition.
  1438. AssetDefinition* pAssetDefinition = assetItr->value;
  1439. // Skip if this is not the asset we want.
  1440. if ( assetInternal != pAssetDefinition->mAssetInternal )
  1441. continue;
  1442. // Store as result.
  1443. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1444. // Increase result count.
  1445. resultCount++;
  1446. }
  1447. }
  1448. return resultCount;
  1449. }
  1450. //-----------------------------------------------------------------------------
  1451. S32 AssetManager::findAssetPrivate( AssetQuery* pAssetQuery, const bool assetPrivate, const bool assetQueryAsSource )
  1452. {
  1453. // Debug Profiling.
  1454. PROFILE_SCOPE(AssetManager_FindAssetPrivate);
  1455. // Sanity!
  1456. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1457. // Reset result count.
  1458. S32 resultCount = 0;
  1459. // Use asset-query as the source?
  1460. if ( assetQueryAsSource )
  1461. {
  1462. AssetQuery filteredAssets;
  1463. // Yes, so iterate asset query.
  1464. for( Vector<StringTableEntry>::iterator assetItr = pAssetQuery->begin(); assetItr != pAssetQuery->end(); ++assetItr )
  1465. {
  1466. // Fetch asset definition.
  1467. AssetDefinition* pAssetDefinition = findAsset( *assetItr );
  1468. // Skip if this is not the asset we want.
  1469. if ( pAssetDefinition == NULL ||
  1470. pAssetDefinition->mAssetPrivate != assetPrivate )
  1471. continue;
  1472. // Store as result.
  1473. filteredAssets.push_back( pAssetDefinition->mAssetId );
  1474. // Increase result count.
  1475. resultCount++;
  1476. }
  1477. // Set asset query.
  1478. pAssetQuery->set( filteredAssets );
  1479. }
  1480. else
  1481. {
  1482. // No, so iterate declared assets.
  1483. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1484. {
  1485. // Fetch asset definition.
  1486. AssetDefinition* pAssetDefinition = assetItr->value;
  1487. // Skip if this is not the asset we want.
  1488. if ( assetPrivate != pAssetDefinition->mAssetPrivate )
  1489. continue;
  1490. // Store as result.
  1491. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1492. // Increase result count.
  1493. resultCount++;
  1494. }
  1495. }
  1496. return resultCount;
  1497. }
  1498. //-----------------------------------------------------------------------------
  1499. S32 AssetManager::findAssetType( AssetQuery* pAssetQuery, const char* pAssetType, const bool assetQueryAsSource )
  1500. {
  1501. // Debug Profiling.
  1502. PROFILE_SCOPE(AssetManager_FindAssetType);
  1503. // Sanity!
  1504. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1505. AssertFatal( pAssetType != NULL, "Cannot use NULL asset type." );
  1506. // Fetch asset type.
  1507. StringTableEntry assetType = StringTable->insert( pAssetType );
  1508. // Reset result count.
  1509. S32 resultCount = 0;
  1510. // Use asset-query as the source?
  1511. if ( assetQueryAsSource )
  1512. {
  1513. AssetQuery filteredAssets;
  1514. // Yes, so iterate asset query.
  1515. for( Vector<StringTableEntry>::iterator assetItr = pAssetQuery->begin(); assetItr != pAssetQuery->end(); ++assetItr )
  1516. {
  1517. // Fetch asset definition.
  1518. AssetDefinition* pAssetDefinition = findAsset( *assetItr );
  1519. // Skip if this is not the asset we want.
  1520. if ( pAssetDefinition == NULL ||
  1521. pAssetDefinition->mAssetType != assetType )
  1522. continue;
  1523. // Store as result.
  1524. filteredAssets.push_back( pAssetDefinition->mAssetId );
  1525. // Increase result count.
  1526. resultCount++;
  1527. }
  1528. // Set asset query.
  1529. pAssetQuery->set( filteredAssets );
  1530. }
  1531. else
  1532. {
  1533. // No, so iterate declared assets.
  1534. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1535. {
  1536. // Fetch asset definition.
  1537. AssetDefinition* pAssetDefinition = assetItr->value;
  1538. // Skip if this is not the asset we want.
  1539. if ( assetType != pAssetDefinition->mAssetType )
  1540. continue;
  1541. // Store as result.
  1542. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1543. // Increase result count.
  1544. resultCount++;
  1545. }
  1546. }
  1547. return resultCount;
  1548. }
  1549. //-----------------------------------------------------------------------------
  1550. S32 AssetManager::findAssetDependsOn( AssetQuery* pAssetQuery, const char* pAssetId )
  1551. {
  1552. // Debug Profiling.
  1553. PROFILE_SCOPE(AssetManager_FindAssetDependsOn);
  1554. // Sanity!
  1555. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1556. AssertFatal( pAssetId != NULL, "Cannot use NULL asset Id." );
  1557. // Fetch asset Id.
  1558. StringTableEntry assetId = StringTable->insert( pAssetId );
  1559. // Reset result count.
  1560. S32 resultCount = 0;
  1561. // Find depends-on entry.
  1562. typeAssetDependsOnHash::iterator dependsOnItr = mAssetDependsOn.find( assetId );
  1563. // Iterate all dependencies.
  1564. while( dependsOnItr != mAssetDependsOn.end() && dependsOnItr->key == assetId )
  1565. {
  1566. // Store as result.
  1567. pAssetQuery->push_back( dependsOnItr->value );
  1568. // Next dependency.
  1569. dependsOnItr++;
  1570. // Increase result count.
  1571. resultCount++;
  1572. }
  1573. return resultCount;
  1574. }
  1575. //-----------------------------------------------------------------------------
  1576. S32 AssetManager::findAssetIsDependedOn( AssetQuery* pAssetQuery, const char* pAssetId )
  1577. {
  1578. // Debug Profiling.
  1579. PROFILE_SCOPE(AssetManager_FindAssetIsDependedOn);
  1580. // Sanity!
  1581. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1582. AssertFatal( pAssetId != NULL, "Cannot use NULL asset Id." );
  1583. // Fetch asset Id.
  1584. StringTableEntry assetId = StringTable->insert( pAssetId );
  1585. // Reset result count.
  1586. S32 resultCount = 0;
  1587. // Find depended-on entry.
  1588. typeAssetIsDependedOnHash::iterator dependedOnItr = mAssetIsDependedOn.find( assetId );
  1589. // Iterate all dependencies.
  1590. while( dependedOnItr != mAssetIsDependedOn.end() && dependedOnItr->key == assetId )
  1591. {
  1592. // Store as result.
  1593. pAssetQuery->push_back( dependedOnItr->value );
  1594. // Next dependency.
  1595. dependedOnItr++;
  1596. // Increase result count.
  1597. resultCount++;
  1598. }
  1599. return resultCount;
  1600. }
  1601. //-----------------------------------------------------------------------------
  1602. S32 AssetManager::findInvalidAssetReferences( AssetQuery* pAssetQuery )
  1603. {
  1604. // Debug Profiling.
  1605. PROFILE_SCOPE(AssetManager_FindInvalidAssetReferences);
  1606. // Sanity!
  1607. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1608. // Reset result count.
  1609. S32 resultCount = 0;
  1610. // Iterate referenced assets.
  1611. for( typeReferencedAssetsHash::iterator assetItr = mReferencedAssets.begin(); assetItr != mReferencedAssets.end(); ++assetItr )
  1612. {
  1613. // Find asset definition.
  1614. AssetDefinition* pAssetDefinition = findAsset( assetItr->key );
  1615. // Skip if the asset definition was found.
  1616. if ( pAssetDefinition != NULL )
  1617. continue;
  1618. // Store as result.
  1619. pAssetQuery->push_back( assetItr->key );
  1620. // Increase result count.
  1621. resultCount++;
  1622. }
  1623. return resultCount;
  1624. }
  1625. //-----------------------------------------------------------------------------
  1626. S32 AssetManager::findTaggedAssets( AssetQuery* pAssetQuery, const char* pAssetTagNames, const bool assetQueryAsSource )
  1627. {
  1628. // Debug Profiling.
  1629. PROFILE_SCOPE(AssetManager_FindTaggedAssets);
  1630. // Sanity!
  1631. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1632. AssertFatal( pAssetTagNames != NULL, "Cannot use NULL asset tag name(s)." );
  1633. // Do we have an asset tag manifest?
  1634. if ( mAssetTagsManifest.isNull() )
  1635. {
  1636. // No, so warn.
  1637. Con::warnf( "Asset Manager: Cannot find tagged assets as no asset tag manifest is present." );
  1638. return 0;
  1639. }
  1640. // Reset result count.
  1641. S32 resultCount = 0;
  1642. const char* pTagSeparators = " ,\t\n";
  1643. // Fetch tag count.
  1644. U32 assetTagCount = StringUnit::getUnitCount( pAssetTagNames, pTagSeparators );
  1645. // Fetch asset tags.
  1646. Vector<AssetTagsManifest::AssetTag*> assetTags;
  1647. for( U32 tagIndex = 0; tagIndex < assetTagCount; ++tagIndex )
  1648. {
  1649. // Fetch asset tag name.
  1650. const char* pTagName = StringUnit::getUnit( pAssetTagNames, tagIndex, pTagSeparators );
  1651. // Fetch asset tag.
  1652. AssetTagsManifest::AssetTag* pAssetTag = mAssetTagsManifest->findAssetTag( pTagName );
  1653. // Did we find the asset tag?
  1654. if ( pAssetTag == NULL )
  1655. {
  1656. // No, so warn.
  1657. Con::warnf( "AssetTagsManifest: Asset Manager: Cannot find tagged assets of '%s' as it does not exist. Ignoring tag.", pTagName );
  1658. continue;
  1659. }
  1660. assetTags.push_back( pAssetTag );
  1661. }
  1662. // Fetch found asset tag count.
  1663. assetTagCount = assetTags.size();
  1664. // Did we find any tags?
  1665. if ( assetTagCount == 0 )
  1666. {
  1667. // No, so warn.
  1668. Con::warnf( "AssetTagsManifest: Asset Manager: No specified tagged assets found in '%s'.", pAssetTagNames );
  1669. return 0;
  1670. }
  1671. // Use asset-query as the source?
  1672. if ( assetQueryAsSource )
  1673. {
  1674. AssetQuery filteredAssets;
  1675. // Yes, so iterate asset query.
  1676. for( Vector<StringTableEntry>::iterator assetItr = pAssetQuery->begin(); assetItr != pAssetQuery->end(); ++assetItr )
  1677. {
  1678. // Fetch asset Id.
  1679. StringTableEntry assetId = *assetItr;
  1680. // Skip if asset is not valid.
  1681. if ( !isDeclaredAsset( assetId ) )
  1682. continue;
  1683. // Reset matched flag.
  1684. bool assetTagMatched = false;
  1685. // Iterate asset tags.
  1686. for ( Vector<AssetTagsManifest::AssetTag*>::iterator assetTagItr = assetTags.begin(); assetTagItr != assetTags.end(); ++assetTagItr )
  1687. {
  1688. // Fetch asset tag.
  1689. AssetTagsManifest::AssetTag* pAssetTag = *assetTagItr;
  1690. // Skip if asset is not tagged.
  1691. if ( !pAssetTag->containsAsset( assetId ) )
  1692. continue;
  1693. // Flag as matched.
  1694. assetTagMatched = true;
  1695. break;
  1696. }
  1697. // Did we find a match?
  1698. if ( assetTagMatched )
  1699. {
  1700. // Yes, so is asset already present?
  1701. if ( !filteredAssets.containsAsset( assetId ) )
  1702. {
  1703. // No, so store as result.
  1704. filteredAssets.push_back( assetId );
  1705. // Increase result count.
  1706. resultCount++;
  1707. }
  1708. }
  1709. }
  1710. // Set asset query.
  1711. pAssetQuery->set( filteredAssets );
  1712. }
  1713. else
  1714. {
  1715. // Iterate asset tags.
  1716. for ( Vector<AssetTagsManifest::AssetTag*>::iterator assetTagItr = assetTags.begin(); assetTagItr != assetTags.end(); ++assetTagItr )
  1717. {
  1718. // Fetch asset tag.
  1719. AssetTagsManifest::AssetTag* pAssetTag = *assetTagItr;
  1720. // Iterate tagged assets.
  1721. for ( Vector<typeAssetId>::iterator assetItr = pAssetTag->mAssets.begin(); assetItr != pAssetTag->mAssets.end(); ++assetItr )
  1722. {
  1723. // Fetch asset Id.
  1724. StringTableEntry assetId = *assetItr;
  1725. // Skip if asset Id is already present.
  1726. if ( pAssetQuery->containsAsset( assetId ) )
  1727. continue;
  1728. // Store as result.
  1729. pAssetQuery->push_back( assetId );
  1730. // Increase result count.
  1731. resultCount++;
  1732. }
  1733. }
  1734. }
  1735. return resultCount;
  1736. }
  1737. //-----------------------------------------------------------------------------
  1738. S32 AssetManager::findAssetLooseFile( AssetQuery* pAssetQuery, const char* pLooseFile, const bool assetQueryAsSource )
  1739. {
  1740. // Debug Profiling.
  1741. PROFILE_SCOPE(AssetManager_FindAssetLooseFile);
  1742. // Sanity!
  1743. AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
  1744. AssertFatal( pLooseFile != NULL, "Cannot use NULL loose file." );
  1745. // Expand loose file.
  1746. char looseFileBuffer[1024];
  1747. Con::expandPath(looseFileBuffer, sizeof(looseFileBuffer), pLooseFile, NULL, false );
  1748. // Fetch asset loose file.
  1749. StringTableEntry looseFile = StringTable->insert( looseFileBuffer );
  1750. // Reset result count.
  1751. S32 resultCount = 0;
  1752. // Use asset-query as the source?
  1753. if ( assetQueryAsSource )
  1754. {
  1755. AssetQuery filteredAssets;
  1756. // Yes, so iterate asset query.
  1757. for( Vector<StringTableEntry>::iterator assetItr = pAssetQuery->begin(); assetItr != pAssetQuery->end(); ++assetItr )
  1758. {
  1759. // Fetch asset definition.
  1760. AssetDefinition* pAssetDefinition = findAsset( *assetItr );
  1761. // Fetch loose files.
  1762. Vector<StringTableEntry>& assetLooseFiles = pAssetDefinition->mAssetLooseFiles;
  1763. // Skip if this asset has no loose files.
  1764. if ( assetLooseFiles.size() == 0 )
  1765. continue;
  1766. // Search the assets loose files.
  1767. for( Vector<StringTableEntry>::iterator looseFileItr = assetLooseFiles.begin(); looseFileItr != assetLooseFiles.end(); ++looseFileItr )
  1768. {
  1769. // Is this the loose file we are searching for?
  1770. if ( *looseFileItr != looseFile )
  1771. continue;
  1772. // Store as result.
  1773. filteredAssets.push_back( pAssetDefinition->mAssetId );
  1774. // Increase result count.
  1775. resultCount++;
  1776. break;
  1777. }
  1778. }
  1779. // Set asset query.
  1780. pAssetQuery->set( filteredAssets );
  1781. }
  1782. else
  1783. {
  1784. // No, so iterate declared assets.
  1785. for( typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr )
  1786. {
  1787. // Fetch asset definition.
  1788. AssetDefinition* pAssetDefinition = assetItr->value;
  1789. // Fetch loose files.
  1790. Vector<StringTableEntry>& assetLooseFiles = pAssetDefinition->mAssetLooseFiles;
  1791. // Skip if this asset has no loose files.
  1792. if ( assetLooseFiles.size() == 0 )
  1793. continue;
  1794. // Search the assets loose files.
  1795. for( Vector<StringTableEntry>::iterator looseFileItr = assetLooseFiles.begin(); looseFileItr != assetLooseFiles.end(); ++looseFileItr )
  1796. {
  1797. // Is this the loose file we are searching for?
  1798. if ( *looseFileItr != looseFile )
  1799. continue;
  1800. // Store as result.
  1801. pAssetQuery->push_back( pAssetDefinition->mAssetId );
  1802. // Increase result count.
  1803. resultCount++;
  1804. break;
  1805. }
  1806. }
  1807. }
  1808. return resultCount;
  1809. }
  1810. //-----------------------------------------------------------------------------
  1811. bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension, const bool recurse, ModuleDefinition* pModuleDefinition )
  1812. {
  1813. // Debug Profiling.
  1814. PROFILE_SCOPE(AssetManager_ScanDeclaredAssets);
  1815. // Sanity!
  1816. AssertFatal( pPath != NULL, "Cannot scan declared assets with NULL path." );
  1817. AssertFatal( pExtension != NULL, "Cannot scan declared assets with NULL extension." );
  1818. // Expand path location.
  1819. char pathBuffer[1024];
  1820. Con::expandPath( pathBuffer, sizeof(pathBuffer), pPath );
  1821. // Find files.
  1822. Vector<Platform::FileInfo> files;
  1823. if ( !Platform::dumpPath( pathBuffer, files, recurse ? -1 : 0 ) )
  1824. {
  1825. // Failed so warn.
  1826. Con::warnf( "Asset Manager: Failed to scan declared assets in directory '%s'.", pathBuffer );
  1827. return false;
  1828. }
  1829. // Is the asset file-path located within the specified module?
  1830. if ( !Con::isBasePath( pathBuffer, pModuleDefinition->getModulePath() ) )
  1831. {
  1832. // No, so warn.
  1833. Con::warnf( "Asset Manager: Could not add declared asset file '%s' as file does not exist with module path '%s'",
  1834. pathBuffer,
  1835. pModuleDefinition->getModulePath() );
  1836. return false;
  1837. }
  1838. // Info.
  1839. if ( mEchoInfo )
  1840. {
  1841. Con::printSeparator();
  1842. Con::printf( "Asset Manager: Scanning for declared assets in path '%s' for files with extension '%s'...", pathBuffer, pExtension );
  1843. }
  1844. // Fetch extension length.
  1845. const U32 extensionLength = dStrlen( pExtension );
  1846. // Fetch module assets.
  1847. ModuleDefinition::typeModuleAssetsVector& moduleAssets = pModuleDefinition->getModuleAssets();
  1848. TamlAssetDeclaredVisitor assetDeclaredVisitor;
  1849. // Iterate files.
  1850. for ( Vector<Platform::FileInfo>::iterator fileItr = files.begin(); fileItr != files.end(); ++fileItr )
  1851. {
  1852. // Fetch file info.
  1853. Platform::FileInfo& fileInfo = *fileItr;
  1854. // Fetch filename.
  1855. const char* pFilename = fileInfo.pFileName;
  1856. // Find filename length.
  1857. const U32 filenameLength = dStrlen( pFilename );
  1858. // Skip if extension is longer than filename.
  1859. if ( extensionLength > filenameLength )
  1860. continue;
  1861. // Skip if extension not found.
  1862. if ( dStricmp( pFilename + filenameLength - extensionLength, pExtension ) != 0 )
  1863. continue;
  1864. // Clear declared assets.
  1865. assetDeclaredVisitor.clear();
  1866. // Format full file-path.
  1867. char assetFileBuffer[1024];
  1868. dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", fileInfo.pFullPath, fileInfo.pFileName );
  1869. // Parse the filename.
  1870. if ( !mTaml.parse( assetFileBuffer, assetDeclaredVisitor ) )
  1871. {
  1872. // Warn.
  1873. Con::warnf( "Asset Manager: Failed to parse file containing asset declaration: '%s'.", assetFileBuffer );
  1874. continue;
  1875. }
  1876. // Fetch asset definition.
  1877. AssetDefinition& foundAssetDefinition = assetDeclaredVisitor.getAssetDefinition();
  1878. // Did we get an asset name?
  1879. if ( foundAssetDefinition.mAssetName == StringTable->EmptyString )
  1880. {
  1881. // No, so warn.
  1882. Con::warnf( "Asset Manager: Parsed file '%s' but did not encounter an asset.", assetFileBuffer );
  1883. continue;
  1884. }
  1885. // Set module definition.
  1886. foundAssetDefinition.mpModuleDefinition = pModuleDefinition;
  1887. // Format asset Id.
  1888. char assetIdBuffer[1024];
  1889. dSprintf(assetIdBuffer, sizeof(assetIdBuffer), "%s%s%s",
  1890. pModuleDefinition->getModuleId(),
  1891. ASSET_SCOPE_TOKEN,
  1892. foundAssetDefinition.mAssetName );
  1893. // Set asset Id.
  1894. foundAssetDefinition.mAssetId = StringTable->insert( assetIdBuffer );
  1895. // Does this asset already exist?
  1896. if ( mDeclaredAssets.contains( foundAssetDefinition.mAssetId ) )
  1897. {
  1898. // Yes, so warn.
  1899. Con::warnf( "Asset Manager: Encountered asset Id '%s' in asset file '%s' but it conflicts with existing asset Id in asset file '%s'.",
  1900. foundAssetDefinition.mAssetId,
  1901. foundAssetDefinition.mAssetBaseFilePath,
  1902. mDeclaredAssets.find( foundAssetDefinition.mAssetId )->value->mAssetBaseFilePath );
  1903. continue;
  1904. }
  1905. // Create new asset definition.
  1906. AssetDefinition* pAssetDefinition = new AssetDefinition( foundAssetDefinition );
  1907. // Store in declared assets.
  1908. mDeclaredAssets.insert( pAssetDefinition->mAssetId, pAssetDefinition );
  1909. // Store in module assets.
  1910. moduleAssets.push_back( pAssetDefinition );
  1911. // Info.
  1912. if ( mEchoInfo )
  1913. {
  1914. Con::printSeparator();
  1915. Con::printf( "Asset Manager: Adding Asset Id '%s' of type '%s' in asset file '%s'.",
  1916. pAssetDefinition->mAssetId,
  1917. pAssetDefinition->mAssetType,
  1918. pAssetDefinition->mAssetBaseFilePath );
  1919. }
  1920. // Fetch asset Id.
  1921. StringTableEntry assetId = pAssetDefinition->mAssetId;
  1922. // Fetch asset dependencies.
  1923. TamlAssetDeclaredVisitor::typeAssetIdVector& assetDependencies = assetDeclaredVisitor.getAssetDependencies();
  1924. // Are there any asset dependencies?
  1925. if ( assetDependencies.size() > 0 )
  1926. {
  1927. // Yes, so iterate dependencies.
  1928. for( TamlAssetDeclaredVisitor::typeAssetIdVector::iterator assetDependencyItr = assetDependencies.begin(); assetDependencyItr != assetDependencies.end(); ++assetDependencyItr )
  1929. {
  1930. // Fetch asset Ids.
  1931. StringTableEntry dependencyAssetId = *assetDependencyItr;
  1932. // Insert depends-on.
  1933. mAssetDependsOn.insertEqual( assetId, dependencyAssetId );
  1934. // Insert is-depended-on.
  1935. mAssetIsDependedOn.insertEqual( dependencyAssetId, assetId );
  1936. // Info.
  1937. if ( mEchoInfo )
  1938. {
  1939. Con::printf( "Asset Manager: Asset Id '%s' has dependency of Asset Id '%s'", assetId, dependencyAssetId );
  1940. }
  1941. }
  1942. }
  1943. // Fetch asset loose files.
  1944. TamlAssetDeclaredVisitor::typeLooseFileVector& assetLooseFiles = assetDeclaredVisitor.getAssetLooseFiles();
  1945. // Are there any loose files?
  1946. if ( assetLooseFiles.size() > 0 )
  1947. {
  1948. // Yes, so iterate loose files.
  1949. for( TamlAssetDeclaredVisitor::typeLooseFileVector::iterator assetLooseFileItr = assetLooseFiles.begin(); assetLooseFileItr != assetLooseFiles.end(); ++assetLooseFileItr )
  1950. {
  1951. // Fetch loose file.
  1952. StringTableEntry looseFile = *assetLooseFileItr;
  1953. // Info.
  1954. if ( mEchoInfo )
  1955. {
  1956. Con::printf( "Asset Manager: Asset Id '%s' has loose file '%s'.", assetId, looseFile );
  1957. }
  1958. // Store loose file.
  1959. pAssetDefinition->mAssetLooseFiles.push_back( looseFile );
  1960. }
  1961. }
  1962. }
  1963. // Info.
  1964. if ( mEchoInfo )
  1965. {
  1966. Con::printSeparator();
  1967. Con::printf( "Asset Manager: ... Finished scanning for declared assets in path '%s' for files with extension '%s'.", pathBuffer, pExtension );
  1968. Con::printSeparator();
  1969. Con::printBlankLine();
  1970. }
  1971. return true;
  1972. }
  1973. //-----------------------------------------------------------------------------
  1974. bool AssetManager::scanReferencedAssets( const char* pPath, const char* pExtension, const bool recurse )
  1975. {
  1976. // Debug Profiling.
  1977. PROFILE_SCOPE(AssetManager_ScanReferencedAssets);
  1978. // Sanity!
  1979. AssertFatal( pPath != NULL, "Cannot scan referenced assets with NULL path." );
  1980. AssertFatal( pExtension != NULL, "Cannot scan referenced assets with NULL extension." );
  1981. // Expand path location.
  1982. char pathBuffer[1024];
  1983. Con::expandPath( pathBuffer, sizeof(pathBuffer), pPath );
  1984. // Find files.
  1985. Vector<Platform::FileInfo> files;
  1986. if ( !Platform::dumpPath( pathBuffer, files, recurse ? -1 : 0 ) )
  1987. {
  1988. // Failed so warn.
  1989. Con::warnf( "Asset Manager: Failed to scan referenced assets in directory '%s'.", pathBuffer );
  1990. return false;
  1991. }
  1992. // Info.
  1993. if ( mEchoInfo )
  1994. {
  1995. Con::printSeparator();
  1996. Con::printf( "Asset Manager: Scanning for referenced assets in path '%s' for files with extension '%s'...", pathBuffer, pExtension );
  1997. }
  1998. // Fetch extension length.
  1999. const U32 extensionLength = dStrlen( pExtension );
  2000. TamlAssetReferencedVisitor assetReferencedVisitor;
  2001. // Iterate files.
  2002. for ( Vector<Platform::FileInfo>::iterator fileItr = files.begin(); fileItr != files.end(); ++fileItr )
  2003. {
  2004. // Fetch file info.
  2005. Platform::FileInfo& fileInfo = *fileItr;
  2006. // Fetch filename.
  2007. const char* pFilename = fileInfo.pFileName;
  2008. // Find filename length.
  2009. const U32 filenameLength = dStrlen( pFilename );
  2010. // Skip if extension is longer than filename.
  2011. if ( extensionLength > filenameLength )
  2012. continue;
  2013. // Skip if extension not found.
  2014. if ( dStricmp( pFilename + filenameLength - extensionLength, pExtension ) != 0 )
  2015. continue;
  2016. // Clear referenced assets.
  2017. assetReferencedVisitor.clear();
  2018. // Format full file-path.
  2019. char assetFileBuffer[1024];
  2020. dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", fileInfo.pFullPath, fileInfo.pFileName );
  2021. // Format reference file-path.
  2022. typeReferenceFilePath referenceFilePath = StringTable->insert( assetFileBuffer );
  2023. // Parse the filename.
  2024. if ( !mTaml.parse( referenceFilePath, assetReferencedVisitor ) )
  2025. {
  2026. // Warn.
  2027. Con::warnf( "Asset Manager: Failed to parse file containing asset references: '%s'.", referenceFilePath );
  2028. continue;
  2029. }
  2030. // Fetch usage map.
  2031. const TamlAssetReferencedVisitor::typeAssetReferencedHash& assetReferencedMap = assetReferencedVisitor.getAssetReferencedMap();
  2032. // Do we have any asset references?
  2033. if ( assetReferencedMap.size() > 0 )
  2034. {
  2035. // Info.
  2036. if ( mEchoInfo )
  2037. {
  2038. Con::printSeparator();
  2039. }
  2040. // Iterate usage.
  2041. for( TamlAssetReferencedVisitor::typeAssetReferencedHash::const_iterator usageItr = assetReferencedMap.begin(); usageItr != assetReferencedMap.end(); ++usageItr )
  2042. {
  2043. // Fetch asset name.
  2044. typeAssetId assetId = usageItr->key;
  2045. // Info.
  2046. if ( mEchoInfo )
  2047. {
  2048. Con::printf( "Asset Manager: Found referenced Asset Id '%s' in file '%s'.", assetId, referenceFilePath );
  2049. }
  2050. // Add referenced asset.
  2051. addReferencedAsset( assetId, referenceFilePath );
  2052. }
  2053. }
  2054. }
  2055. // Info.
  2056. if ( mEchoInfo )
  2057. {
  2058. Con::printf( "Asset Manager: ... Finished scanning for referenced assets in path '%s' for files with extension '%s'.", pathBuffer, pExtension );
  2059. Con::printSeparator();
  2060. Con::printBlankLine();
  2061. }
  2062. return true;
  2063. }
  2064. //-----------------------------------------------------------------------------
  2065. AssetDefinition* AssetManager::findAsset( const char* pAssetId )
  2066. {
  2067. // Debug Profiling.
  2068. PROFILE_SCOPE(AssetManager_FindAsset);
  2069. // Sanity!
  2070. AssertFatal( pAssetId != NULL, "Cannot find NULL asset Id." );
  2071. // Fetch asset Id.
  2072. StringTableEntry assetId = StringTable->insert( pAssetId );
  2073. // Find declared asset.
  2074. typeDeclaredAssetsHash::iterator declaredAssetItr = mDeclaredAssets.find( assetId );
  2075. // Find if we didn't find a declared asset Id.
  2076. if ( declaredAssetItr == mDeclaredAssets.end() )
  2077. return NULL;
  2078. return declaredAssetItr->value;
  2079. }
  2080. //-----------------------------------------------------------------------------
  2081. void AssetManager::addReferencedAsset( StringTableEntry assetId, StringTableEntry referenceFilePath )
  2082. {
  2083. // Debug Profiling.
  2084. PROFILE_SCOPE(AssetManager_AddReferencedAsset);
  2085. // Sanity!
  2086. AssertFatal( assetId != NULL, "Cannot add referenced asset with NULL asset Id." );
  2087. AssertFatal( referenceFilePath != NULL, "Cannot add referenced asset with NULL reference file-path." );
  2088. // Find referenced asset.
  2089. typeReferencedAssetsHash::iterator referencedAssetItr = mReferencedAssets.find( assetId );
  2090. // Did we find the asset?
  2091. if ( referencedAssetItr == mReferencedAssets.end() )
  2092. {
  2093. // No, so add asset Id.
  2094. mReferencedAssets.insertEqual( assetId, referenceFilePath );
  2095. }
  2096. else
  2097. {
  2098. // Yes, so add asset Id with a unique file.
  2099. while( true )
  2100. {
  2101. // Finish if this file is already present.
  2102. if ( referencedAssetItr->value == referenceFilePath )
  2103. return;
  2104. // Move to next asset Id.
  2105. referencedAssetItr++;
  2106. // Is this the end of referenced assets or a different asset Id?
  2107. if ( referencedAssetItr == mReferencedAssets.end() ||
  2108. referencedAssetItr->key != assetId )
  2109. {
  2110. // Yes, so add asset reference.
  2111. mReferencedAssets.insertEqual( assetId, referenceFilePath );
  2112. return;
  2113. }
  2114. };
  2115. }
  2116. }
  2117. //-----------------------------------------------------------------------------
  2118. void AssetManager::renameAssetReferences( StringTableEntry assetIdFrom, StringTableEntry assetIdTo )
  2119. {
  2120. // Debug Profiling.
  2121. PROFILE_SCOPE(AssetManager_RenameAssetReferences);
  2122. // Sanity!
  2123. AssertFatal( assetIdFrom != NULL, "Cannot rename asset references using NULL asset Id from." );
  2124. AssertFatal( assetIdTo != NULL, "Cannot rename asset references using NULL asset Id to." );
  2125. // Finish if the asset is not referenced.
  2126. if ( !mReferencedAssets.count( assetIdFrom ) )
  2127. return;
  2128. // Setup referenced update visitor.
  2129. TamlAssetReferencedUpdateVisitor assetReferencedUpdateVisitor;
  2130. assetReferencedUpdateVisitor.setAssetIdFrom( assetIdFrom );
  2131. assetReferencedUpdateVisitor.setAssetIdTo( assetIdTo );
  2132. // Find first referenced asset Id.
  2133. typeReferencedAssetsHash::iterator referencedAssetItr = mReferencedAssets.find( assetIdFrom );
  2134. // Iterate references.
  2135. while( true )
  2136. {
  2137. // Finish if end of references.
  2138. if ( referencedAssetItr == mReferencedAssets.end() || referencedAssetItr->key != assetIdFrom )
  2139. return;
  2140. // Info.
  2141. if ( mEchoInfo )
  2142. {
  2143. Con::printf( "Asset Manager: Renaming declared Asset Id '%s' to Asset Id '%s'. Updating referenced file '%s'",
  2144. assetIdFrom,
  2145. assetIdTo,
  2146. referencedAssetItr->value );
  2147. }
  2148. // Update asset file declaration.
  2149. if ( !mTaml.parse( referencedAssetItr->value, assetReferencedUpdateVisitor ) )
  2150. {
  2151. // No, so warn.
  2152. Con::warnf("Asset Manager: Cannot rename referenced asset Id '%s' to asset Id '%s' as the referenced asset file could not be parsed: %s",
  2153. assetIdFrom, assetIdTo, referencedAssetItr->value );
  2154. }
  2155. // Move to next reference.
  2156. referencedAssetItr++;
  2157. }
  2158. }
  2159. //-----------------------------------------------------------------------------
  2160. void AssetManager::removeAssetReferences( StringTableEntry assetId )
  2161. {
  2162. // Debug Profiling.
  2163. PROFILE_SCOPE(AssetManager_RemoveAssetReferences);
  2164. // Sanity!
  2165. AssertFatal( assetId != NULL, "Cannot rename asset references using NULL asset Id." );
  2166. // Finish if the asset is not referenced.
  2167. if ( !mReferencedAssets.count( assetId ) )
  2168. return;
  2169. // Setup referenced update visitor.
  2170. TamlAssetReferencedUpdateVisitor assetReferencedUpdateVisitor;
  2171. assetReferencedUpdateVisitor.setAssetIdFrom( assetId );
  2172. assetReferencedUpdateVisitor.setAssetIdTo( StringTable->EmptyString );
  2173. // Find first referenced asset Id.
  2174. typeReferencedAssetsHash::iterator referencedAssetItr = mReferencedAssets.find( assetId );
  2175. // Iterate references.
  2176. while( true )
  2177. {
  2178. // Finish if end of references.
  2179. if ( referencedAssetItr == mReferencedAssets.end() || referencedAssetItr->key != assetId )
  2180. break;
  2181. // Info.
  2182. if ( mEchoInfo )
  2183. {
  2184. Con::printf( "Asset Manager: Removing Asset Id '%s' references from file '%s'",
  2185. assetId,
  2186. referencedAssetItr->value );
  2187. }
  2188. // Update asset file declaration.
  2189. if ( !mTaml.parse( referencedAssetItr->value, assetReferencedUpdateVisitor ) )
  2190. {
  2191. // No, so warn.
  2192. Con::warnf("Asset Manager: Cannot remove referenced asset Id '%s' as the referenced asset file could not be parsed: %s",
  2193. assetId,
  2194. referencedAssetItr->value );
  2195. }
  2196. // Move to next reference.
  2197. referencedAssetItr++;
  2198. }
  2199. // Remove asset references.
  2200. mReferencedAssets.erase( assetId );
  2201. }
  2202. //-----------------------------------------------------------------------------
  2203. void AssetManager::renameAssetDependencies( StringTableEntry assetIdFrom, StringTableEntry assetIdTo )
  2204. {
  2205. // Debug Profiling.
  2206. PROFILE_SCOPE(AssetManager_RenameAssetDependencies);
  2207. // Sanity!
  2208. AssertFatal( assetIdFrom != NULL, "Cannot rename asset dependencies using NULL asset Id from." );
  2209. AssertFatal( assetIdTo != NULL, "Cannot rename asset dependencies using NULL asset Id to." );
  2210. // Rename via depends-on...
  2211. while( mAssetDependsOn.count( assetIdFrom ) > 0 )
  2212. {
  2213. // Find depends-on.
  2214. typeAssetDependsOnHash::iterator dependsOnItr = mAssetDependsOn.find( assetIdFrom );
  2215. // Fetch dependency asset Id.
  2216. StringTableEntry dependencyAssetId = dependsOnItr->value;
  2217. // Find is-depends-on entry.
  2218. typeAssetIsDependedOnHash::iterator isDependedOnItr = mAssetIsDependedOn.find( dependencyAssetId );
  2219. // Sanity!
  2220. AssertFatal( isDependedOnItr != mAssetIsDependedOn.end(), "Asset dependencies are corrupt!" );
  2221. while( isDependedOnItr != mAssetIsDependedOn.end() && isDependedOnItr->key == dependencyAssetId && isDependedOnItr->value != assetIdFrom )
  2222. {
  2223. isDependedOnItr++;
  2224. }
  2225. // Sanity!
  2226. AssertFatal( isDependedOnItr->key == dependencyAssetId && isDependedOnItr->value == assetIdFrom, "Asset dependencies are corrupt!" );
  2227. // Remove is-depended-on.
  2228. mAssetIsDependedOn.erase( isDependedOnItr );
  2229. // Remove depends-on.
  2230. mAssetDependsOn.erase( dependsOnItr );
  2231. // Insert depends-on.
  2232. mAssetDependsOn.insertEqual( assetIdTo, dependencyAssetId );
  2233. // Insert is-depended-on.
  2234. mAssetIsDependedOn.insertEqual( dependencyAssetId, assetIdTo );
  2235. }
  2236. // Rename via is-depended-on...
  2237. while( mAssetIsDependedOn.count( assetIdFrom ) > 0 )
  2238. {
  2239. // Find is-depended-on.
  2240. typeAssetIsDependedOnHash::iterator isdependedOnItr = mAssetIsDependedOn.find( assetIdFrom );
  2241. // Fetch dependency asset Id.
  2242. StringTableEntry dependencyAssetId = isdependedOnItr->value;
  2243. // Find depends-on entry.
  2244. typeAssetDependsOnHash::iterator dependsOnItr = mAssetDependsOn.find( dependencyAssetId );
  2245. // Sanity!
  2246. AssertFatal( dependsOnItr != mAssetDependsOn.end(), "Asset dependencies are corrupt!" );
  2247. while( dependsOnItr != mAssetDependsOn.end() && dependsOnItr->key == dependencyAssetId && dependsOnItr->value != assetIdFrom )
  2248. {
  2249. dependsOnItr++;
  2250. }
  2251. // Sanity!
  2252. AssertFatal( dependsOnItr->key == dependencyAssetId && dependsOnItr->value == assetIdFrom, "Asset dependencies are corrupt!" );
  2253. // Remove is-depended-on.
  2254. mAssetIsDependedOn.erase( isdependedOnItr );
  2255. // Remove depends-on.
  2256. mAssetDependsOn.erase( dependsOnItr );
  2257. // Insert depends-on.
  2258. mAssetDependsOn.insertEqual( dependencyAssetId, assetIdTo );
  2259. // Insert is-depended-on.
  2260. mAssetIsDependedOn.insertEqual( assetIdTo, dependencyAssetId );
  2261. }
  2262. }
  2263. //-----------------------------------------------------------------------------
  2264. void AssetManager::removeAssetDependencies( const char* pAssetId )
  2265. {
  2266. // Debug Profiling.
  2267. PROFILE_SCOPE(AssetManager_RemvoeAsetDependencies);
  2268. // Sanity!
  2269. AssertFatal( pAssetId != NULL, "Cannot remove asset dependencies using NULL asset Id." );
  2270. // Fetch asset Id.
  2271. StringTableEntry assetId = StringTable->insert( pAssetId );
  2272. // Remove from depends-on assets.
  2273. while( mAssetDependsOn.count( assetId ) > 0 )
  2274. {
  2275. // Find depends-on.
  2276. typeAssetDependsOnHash::iterator dependsOnItr = mAssetDependsOn.find( assetId );
  2277. // Fetch dependency asset Id.
  2278. StringTableEntry dependencyAssetId = dependsOnItr->value;
  2279. // Find is-depends-on entry.
  2280. typeAssetIsDependedOnHash::iterator isDependedOnItr = mAssetIsDependedOn.find( dependencyAssetId );
  2281. // Sanity!
  2282. AssertFatal( isDependedOnItr != mAssetIsDependedOn.end(), "Asset dependencies are corrupt!" );
  2283. while( isDependedOnItr != mAssetIsDependedOn.end() && isDependedOnItr->key == dependencyAssetId && isDependedOnItr->value != assetId )
  2284. {
  2285. isDependedOnItr++;
  2286. }
  2287. // Sanity!
  2288. AssertFatal( isDependedOnItr->key == dependencyAssetId && isDependedOnItr->value == assetId, "Asset dependencies are corrupt!" );
  2289. // Remove is-depended-on.
  2290. mAssetIsDependedOn.erase( isDependedOnItr );
  2291. // Remove depends-on.
  2292. mAssetDependsOn.erase( dependsOnItr );
  2293. }
  2294. }
  2295. //-----------------------------------------------------------------------------
  2296. void AssetManager::unloadAsset( AssetDefinition* pAssetDefinition )
  2297. {
  2298. // Debug Profiling.
  2299. PROFILE_SCOPE(AssetManager_UnloadAsset);
  2300. // Destroy the asset.
  2301. pAssetDefinition->mpAssetBase->deleteObject();
  2302. // Increase unloaded count.
  2303. pAssetDefinition->mAssetUnloadedCount++;
  2304. // Is the asset internal?
  2305. if ( pAssetDefinition->mAssetInternal )
  2306. {
  2307. // Yes, so decrease internal loaded asset count.
  2308. mLoadedInternalAssetsCount--;
  2309. }
  2310. else
  2311. {
  2312. // No, so decrease external loaded assets count.
  2313. mLoadedExternalAssetsCount--;
  2314. }
  2315. // Is the asset private?
  2316. if ( pAssetDefinition->mAssetPrivate )
  2317. {
  2318. // Yes, so decrease private loaded asset count.
  2319. mLoadedPrivateAssetsCount--;
  2320. // Remove it completely.
  2321. removeDeclaredAsset( pAssetDefinition->mAssetId );
  2322. }
  2323. }
  2324. //-----------------------------------------------------------------------------
  2325. void AssetManager::onModulePreLoad( ModuleDefinition* pModuleDefinition )
  2326. {
  2327. // Debug Profiling.
  2328. PROFILE_SCOPE(AssetManager_OnModulePreLoad);
  2329. // Add module declared assets.
  2330. addModuleDeclaredAssets( pModuleDefinition );
  2331. // Is an asset tags manifest specified?
  2332. if ( pModuleDefinition->getAssetTagsManifest() != StringTable->EmptyString )
  2333. {
  2334. // Yes, so load the asset tags manifest.
  2335. loadAssetTags( pModuleDefinition );
  2336. }
  2337. }
  2338. //-----------------------------------------------------------------------------
  2339. void AssetManager::onModulePreUnload( ModuleDefinition* pModuleDefinition )
  2340. {
  2341. // Debug Profiling.
  2342. PROFILE_SCOPE(AssetManager_OnModulePreUnload);
  2343. // Is an asset tags manifest specified?
  2344. if ( pModuleDefinition->getAssetTagsManifest() != StringTable->EmptyString )
  2345. {
  2346. // Yes, so save the asset tags manifest.
  2347. saveAssetTags();
  2348. // Do we have an asset tags manifest?
  2349. if ( !mAssetTagsManifest.isNull() )
  2350. {
  2351. // Yes, so remove it.
  2352. mAssetTagsManifest->deleteObject();
  2353. mAssetTagsModuleDefinition = NULL;
  2354. }
  2355. }
  2356. }
  2357. //-----------------------------------------------------------------------------
  2358. void AssetManager::onModulePostUnload( ModuleDefinition* pModuleDefinition )
  2359. {
  2360. // Debug Profiling.
  2361. PROFILE_SCOPE(AssetManager_OnModulePostUnload);
  2362. // Remove declared assets.
  2363. removeDeclaredAssets( pModuleDefinition );
  2364. }