assetManager.cpp 99 KB

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