assetManager_ScriptBinding.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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 "console/engineAPI.h"
  23. #include "assetBase.h"
  24. #include "assetManager.h"
  25. #include "module/moduleDefinition.h"
  26. #include "console/sim.h"
  27. DefineEngineMethod(AssetManager, compileReferencedAssets, bool, (const char* moduleDefinition), (""),
  28. "Compile the referenced assets determined by the specified module definition.\n"
  29. "@param moduleDefinition The module definition specifies the asset manifest.\n"
  30. "@return Whether the compilation was successful or not.\n")
  31. {
  32. // Fetch module definition.
  33. ModuleDefinition* pModuleDefinition;
  34. Sim::findObject(moduleDefinition, pModuleDefinition);
  35. // Did we find the module definition?
  36. if ( pModuleDefinition == NULL )
  37. {
  38. // No, so warn.
  39. Con::warnf("AssetManager::compileReferencedAssets() - Could not find the module definition '%s'.", moduleDefinition);
  40. return false;
  41. }
  42. // Compile referenced assets.
  43. return object->compileReferencedAssets( pModuleDefinition );
  44. }
  45. //-----------------------------------------------------------------------------
  46. DefineEngineMethod(AssetManager, addModuleDeclaredAssets, bool, (const char* moduleDefinition), (""),
  47. "Add any the declared assets specified by the module definition.\n"
  48. "@param moduleDefinition The module definition specifies the asset manifest.\n"
  49. "@return Whether adding declared assets was successful or not.\n")
  50. {
  51. // Fetch module definition.
  52. ModuleDefinition* pModuleDefinition;
  53. Sim::findObject(moduleDefinition, pModuleDefinition);
  54. // Did we find the module definition?
  55. if ( pModuleDefinition == NULL )
  56. {
  57. // No, so warn.
  58. Con::warnf("AssetManager::addDeclaredAssets() - Could not find the module definition '%s'.", moduleDefinition);
  59. return false;
  60. }
  61. // Add module declared assets.
  62. return object->addModuleDeclaredAssets( pModuleDefinition );
  63. }
  64. //-----------------------------------------------------------------------------
  65. DefineEngineMethod(AssetManager, addDeclaredAsset, bool, (const char* moduleDefinition, const char* assetFilePath), ("", ""),
  66. "Add the specified asset against the specified module definition.\n"
  67. "@param moduleDefinition The module definition that may contain declared assets.\n"
  68. "@return Whether adding declared assets was successful or not.\n")
  69. {
  70. // Fetch module definition.
  71. ModuleDefinition* pModuleDefinition;
  72. Sim::findObject(moduleDefinition, pModuleDefinition);
  73. // Did we find the module definition?
  74. if ( pModuleDefinition == NULL )
  75. {
  76. // No, so warn.
  77. Con::warnf("AssetManager::addDeclaredAsset() - Could not find the module definition '%s'.", moduleDefinition);
  78. return false;
  79. }
  80. // Fetch asset file-path.
  81. const char* pAssetFilePath = assetFilePath;
  82. // Add declared asset.
  83. return object->addDeclaredAsset( pModuleDefinition, pAssetFilePath );
  84. }
  85. //-----------------------------------------------------------------------------
  86. DefineEngineMethod(AssetManager, addPrivateAsset, String, (const char* assetObject), (""),
  87. "Adds a private asset object.\n"
  88. "@param assetObject The asset object to add as a private asset.\n"
  89. "@return The allocated private asset Id.\n")
  90. {
  91. // Fetch asset.
  92. AssetBase* pAssetBase;
  93. Sim::findObject(assetObject, pAssetBase);
  94. // Did we find the asset?
  95. if ( pAssetBase == NULL )
  96. {
  97. // No, so warn.
  98. Con::warnf("AssetManager::addPrivateAsset() - Could not find the asset '%s'.", assetObject);
  99. return StringTable->EmptyString();
  100. }
  101. // Add private asset.
  102. return object->addPrivateAsset( pAssetBase );
  103. }
  104. //-----------------------------------------------------------------------------
  105. DefineEngineMethod(AssetManager, removeDeclaredAssets, bool, (const char* moduleDefinition), (""),
  106. "Remove any the declared assets specified by the module definition.\n"
  107. "@param moduleDefinition The module definition that may contain declared assets.\n"
  108. "@return Whether removing declared assets was successful or not.\n")
  109. {
  110. // Fetch module definition.
  111. ModuleDefinition* pModuleDefinition;
  112. Sim::findObject(moduleDefinition, pModuleDefinition);
  113. // Did we find the module definition?
  114. if ( pModuleDefinition == NULL )
  115. {
  116. // No, so warn.
  117. Con::warnf("AssetManager::removeDeclaredAssets() - Could not find the module definition '%s'.", moduleDefinition);
  118. return false;
  119. }
  120. // Remove declared assets.
  121. return object->removeDeclaredAssets( pModuleDefinition );
  122. }
  123. //-----------------------------------------------------------------------------
  124. DefineEngineMethod(AssetManager, removeDeclaredAsset, bool, (const char* assetId), (""),
  125. "Remove the specified declared asset Id.\n"
  126. "@param assetId The selected asset Id.\n"
  127. "@return Whether removing the declared asset was successful or not.\n")
  128. {
  129. // Remove the declared asset Id.
  130. return object->removeDeclaredAsset(assetId);
  131. }
  132. //-----------------------------------------------------------------------------
  133. DefineEngineMethod(AssetManager, getAssetName, String, (const char* assetId), (""),
  134. "Gets the asset name from the specified asset Id.\n"
  135. "@param assetId The selected asset Id.\n"
  136. "@return The asset name from the specified asset Id.\n")
  137. {
  138. return object->getAssetName(assetId);
  139. }
  140. //-----------------------------------------------------------------------------
  141. DefineEngineMethod(AssetManager, getAssetDescription, String, (const char* assetId), (""),
  142. "Gets the asset description from the specified asset Id.\n"
  143. "@param assetId The selected asset Id.\n"
  144. "@return The asset description from the specified asset Id.\n")
  145. {
  146. return object->getAssetDescription(assetId);
  147. }
  148. //-----------------------------------------------------------------------------
  149. DefineEngineMethod(AssetManager, getAssetCategory, String, (const char* assetId), (""),
  150. "Gets the asset category from the specified asset Id.\n"
  151. "@param assetId The selected asset Id.\n"
  152. "@return The asset category from the specified asset Id.\n")
  153. {
  154. return object->getAssetCategory(assetId);
  155. }
  156. //-----------------------------------------------------------------------------
  157. DefineEngineMethod(AssetManager, getAssetType, String, (const char* assetId), (""),
  158. "Gets the asset type from the specified asset Id.\n"
  159. "@param assetId The selected asset Id.\n"
  160. "@return The asset type from the specified asset Id.\n")
  161. {
  162. return object->getAssetType(assetId);
  163. }
  164. //-----------------------------------------------------------------------------
  165. DefineEngineMethod(AssetManager, getAssetFilePath, String, (const char* assetId), (""),
  166. "Gets the asset file-path from the specified asset Id.\n"
  167. "@param assetId The selected asset Id.\n"
  168. "@return The asset file - path from the specified asset Id.\n")
  169. {
  170. return object->getAssetFilePath(assetId);
  171. }
  172. //-----------------------------------------------------------------------------
  173. DefineEngineMethod(AssetManager, getAssetPath, String, (const char* assetId), (""),
  174. "Gets the asset path (not including the asset file) from the specified asset Id.\n"
  175. "@param assetId The selected asset Id.\n"
  176. "@return The asset path(not including the asset file) from the specified asset Id.\n")
  177. {
  178. return object->getAssetPath(assetId);
  179. }
  180. //-----------------------------------------------------------------------------
  181. DefineEngineMethod(AssetManager, getAssetModule, String, (const char* assetId), (""),
  182. "Gets the module definition where the the specified asset Id is located.\n"
  183. "@param assetId The selected asset Id.\n"
  184. "@return The module definition where the the specified asset Id is located.\n")
  185. {
  186. // Fetch module definition.
  187. ModuleDefinition* pModuleDefinition = object->getAssetModuleDefinition(assetId);
  188. return pModuleDefinition == NULL ? StringTable->EmptyString() : pModuleDefinition->getIdString();
  189. }
  190. //-----------------------------------------------------------------------------
  191. DefineEngineMethod(AssetManager, isAssetInternal, bool, (const char* assetId), (""),
  192. "Check whether the specified asset Id is internal or not.\n"
  193. "@param assetId The selected asset Id.\n"
  194. "@return Whether the specified asset Id is internal or not.\n")
  195. {
  196. return object->isAssetInternal(assetId);
  197. }
  198. //-----------------------------------------------------------------------------
  199. DefineEngineMethod(AssetManager, isAssetPrivate, bool, (const char* assetId), (""),
  200. "Check whether the specified asset Id is private or not.\n"
  201. "@param assetId The selected asset Id.\n"
  202. "@return Whether the specified asset Id is private or not.\n")
  203. {
  204. return object->isAssetPrivate(assetId);
  205. }
  206. //-----------------------------------------------------------------------------
  207. DefineEngineMethod(AssetManager, isAssetAutoUnload, bool, (const char* assetId), (""),
  208. "Check whether the specified asset Id is auto - unload or not.\n"
  209. "@param assetId The selected asset Id.\n"
  210. "@return Whether the specified asset Id is auto-unload or not.\n")
  211. {
  212. return object->isAssetAutoUnload(assetId);
  213. }
  214. //-----------------------------------------------------------------------------
  215. DefineEngineMethod(AssetManager, isAssetLoaded, bool, (const char* assetId), (""),
  216. "Check whether the specified asset Id is loaded or not.\n"
  217. "@param assetId The selected asset Id.\n"
  218. "@return Whether the specified asset Id is loaded or not.\n")
  219. {
  220. return object->isAssetLoaded(assetId);
  221. }
  222. //-----------------------------------------------------------------------------
  223. DefineEngineMethod(AssetManager, isDeclaredAsset, bool, (const char* assetId), (""),
  224. "Check whether the specified asset Id is declared or not.\n"
  225. "@param assetId The selected asset Id.\n"
  226. "@return Whether the specified asset Id is declared or not.\n")
  227. {
  228. return object->isDeclaredAsset(assetId);
  229. }
  230. //-----------------------------------------------------------------------------
  231. DefineEngineMethod(AssetManager, isReferencedAsset, bool, (const char* assetId), (""),
  232. "Check whether the specified asset Id is referenced or not.\n"
  233. "@param assetId The selected asset Id.\n"
  234. "@return Whether the specified asset Id is referenced or not.\n")
  235. {
  236. return object->isReferencedAsset(assetId);
  237. }
  238. //-----------------------------------------------------------------------------
  239. DefineEngineMethod(AssetManager, renameDeclaredAsset, bool, (const char* assetIdFrom, const char* assetIdTo), ("", ""),
  240. "Rename declared asset Id.\n"
  241. "@param assetIdFrom The selected asset Id to rename from.\n"
  242. "@param assetIdFrom The selected asset Id to rename to.\n"
  243. "@return Whether the rename was successful or not.\n")
  244. {
  245. return object->renameDeclaredAsset(assetIdFrom, assetIdTo);
  246. }
  247. //-----------------------------------------------------------------------------
  248. DefineEngineMethod(AssetManager, renameReferencedAsset, bool, (const char* assetIdFrom, const char* assetIdTo), ("", ""),
  249. "Rename referenced asset Id. \n"
  250. "@param assetIdFrom The selected asset Id to rename from.\n"
  251. "@param assetIdFrom The selected asset Id to rename to.\n"
  252. "@return Whether the rename was successful or not.\n")
  253. {
  254. return object->renameReferencedAsset(assetIdFrom, assetIdTo);
  255. }
  256. //-----------------------------------------------------------------------------
  257. DefineEngineMethod(AssetManager, acquireAsset, String, (const char* assetId, bool asPrivate), ("", false),
  258. "Acquire the specified asset Id.\n"
  259. "You must release the asset once you're finish with it using 'releaseAsset'.\n"
  260. "@param assetId The selected asset Id.\n"
  261. "@param asPrivate Whether to acquire the asset Id as a private asset.\n"
  262. "@return The acquired asset or NULL if not acquired.\n")
  263. {
  264. // Fetch asset Id.
  265. const char* pAssetId = assetId;
  266. // Reset asset reference.
  267. AssetBase* pAssetBase = NULL;
  268. // Acquire private asset?
  269. if ( asPrivate )
  270. {
  271. // Acquire private asset.
  272. pAssetBase = object->acquireAsPrivateAsset<AssetBase>( pAssetId );
  273. }
  274. else
  275. {
  276. // Acquire public asset.
  277. pAssetBase = object->acquireAsset<AssetBase>( pAssetId );
  278. }
  279. return pAssetBase != NULL ? pAssetBase->getIdString() : StringTable->EmptyString();
  280. }
  281. //-----------------------------------------------------------------------------
  282. DefineEngineMethod(AssetManager, releaseAsset, bool, (const char* assetId), (""),
  283. "Release the specified asset Id.\n"
  284. "The asset should have been acquired using 'acquireAsset'.\n"
  285. "@param assetId The selected asset Id.\n"
  286. "@return Whether the asset was released or not.\n")
  287. {
  288. // Release asset.
  289. return object->releaseAsset(assetId);
  290. }
  291. //-----------------------------------------------------------------------------
  292. DefineEngineMethod(AssetManager, purgeAssets, void, (),,
  293. "Purge all assets that are not referenced even if they are set to not auto-unload.\n"
  294. "Assets can be in this state because they are either set to not auto-unload or the asset manager has/is disabling auto-unload.\n"
  295. "@return No return value.\n")
  296. {
  297. // Purge assets.
  298. object->purgeAssets();
  299. }
  300. //-----------------------------------------------------------------------------
  301. DefineEngineMethod(AssetManager, deleteAsset, bool, (const char* assetId, bool deleteLooseFiles, bool deleteDependencies), ("", false, false),
  302. "Deletes the specified asset Id and optionally its loose files and asset dependencies.\n"
  303. "@param assetId The selected asset Id.\n"
  304. "@param deleteLooseFiles Whether to delete an assets loose files or not.\n"
  305. "@param deleteDependencies Whether to delete assets that depend on this asset or not.\n"
  306. "@return Whether the asset deletion was successful or not. A failure only indicates that the specified asset was not deleted but dependent assets and their loose files may have being deleted.\n")
  307. {
  308. // Fetch asset Id.
  309. const char* pAssetId = assetId;
  310. // Delete asset.
  311. return object->deleteAsset( pAssetId, deleteLooseFiles, deleteDependencies );
  312. }
  313. //-----------------------------------------------------------------------------
  314. DefineEngineMethod(AssetManager, refreshAsset, void, (const char* assetId), (""),
  315. "Refresh the specified asset Id.\n"
  316. "@param assetId The selected asset Id.\n"
  317. "@return No return value.\n")
  318. {
  319. object->refreshAsset(assetId);
  320. }
  321. //-----------------------------------------------------------------------------
  322. DefineEngineMethod(AssetManager, refreshAllAssets, void, (bool includeUnloaded), (false),
  323. "Refresh all declared assets.\n"
  324. "@param Whether to include currently unloaded assets in the refresh or not. Optional: Defaults to false.\n"
  325. "Refreshing all assets can be an expensive (time-consuming) operation to perform.\n"
  326. "@return No return value.\n")
  327. {
  328. // Refresh assets
  329. object->refreshAllAssets(includeUnloaded);
  330. }
  331. //-----------------------------------------------------------------------------
  332. DefineEngineMethod(AssetManager, saveAssetTags, bool, (),,
  333. "Save the currently loaded asset tags manifest.\n"
  334. "@return Whether the save was successful or not.\n")
  335. {
  336. // Save asset tags.
  337. return object->saveAssetTags();
  338. }
  339. //-----------------------------------------------------------------------------
  340. DefineEngineMethod(AssetManager, restoreAssetTags, bool, (),,
  341. "Restore the currently loaded asset tags manifest from disk (replace anything in memory).\n"
  342. "@return Whether the restore was successful or not.\n")
  343. {
  344. // Restore asset tags.
  345. return object->restoreAssetTags();
  346. }
  347. //-----------------------------------------------------------------------------
  348. DefineEngineMethod(AssetManager, getAssetTags, S32, (), ,
  349. "Gets the currently loaded asset tags manifest.\n"
  350. "@return The currently loaded asset tags manifest or zero if not loaded.\n")
  351. {
  352. // Fetch the asset tags manifest.
  353. AssetTagsManifest* pAssetTagsManifest = object->getAssetTags();
  354. return pAssetTagsManifest == NULL ? 0 : pAssetTagsManifest->getId();
  355. }
  356. //-----------------------------------------------------------------------------
  357. DefineEngineMethod(AssetManager, findAllAssets, S32, (const char* assetQuery, bool ignoreInternal, bool ignorePrivate), ("", true, true),
  358. "Performs an asset query searching for all assets optionally ignoring internal assets.\n"
  359. "@param assetQuery The asset query object that will be populated with the results.\n"
  360. "@param ignoreInternal Whether to ignore internal assets or not. Optional: Defaults to true.\n"
  361. "@param ignorePrivate Whether to ignore private assets or not. Optional: Defaults to true.\n"
  362. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  363. {
  364. // Fetch asset query.
  365. AssetQuery* pAssetQuery;
  366. Sim::findObject(assetQuery, pAssetQuery);
  367. // Did we find the asset query?
  368. if ( pAssetQuery == NULL )
  369. {
  370. // No, so warn.
  371. Con::warnf("AssetManager::findAllAssets() - Could not find the asset query object '%s'.", assetQuery);
  372. return -1;
  373. }
  374. // Perform query.
  375. return object->findAllAssets( pAssetQuery, ignoreInternal, ignorePrivate );
  376. }
  377. //-----------------------------------------------------------------------------
  378. DefineEngineMethod(AssetManager, findAssetName, S32, (const char* assetQuery, const char* assetName, bool partialName), ("", "", false),
  379. "Performs an asset query searching for the specified asset name.\n"
  380. "@param assetQuery The asset query object that will be populated with the results.\n"
  381. "@param assetName The asset name to search for. This may be a partial name if 'partialName' is true.\n"
  382. "@param partialName Whether the asset name is to be used as a partial name or not. Optional: Defaults to false.\n"
  383. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  384. {
  385. // Fetch asset query.
  386. AssetQuery* pAssetQuery;
  387. Sim::findObject(assetQuery, pAssetQuery);
  388. // Did we find the asset query?
  389. if ( pAssetQuery == NULL )
  390. {
  391. // No, so warn.
  392. Con::warnf("AssetManager::findAssetName() - Could not find the asset query object '%s'.", assetQuery);
  393. return -1;
  394. }
  395. // Fetch asset name.
  396. const char* pAssetName = assetName;
  397. // Perform query.
  398. return object->findAssetName( pAssetQuery, pAssetName, partialName );
  399. }
  400. //-----------------------------------------------------------------------------
  401. DefineEngineMethod(AssetManager, findAssetCategory, S32, (const char* assetQuery, const char* assetCategory, bool assetQueryAsSource), ("", "", false),
  402. "Performs an asset query searching for the specified asset category.\n"
  403. "@param assetQuery The asset query object that will be populated with the results.\n"
  404. "@param assetCategory The asset category to search for.\n"
  405. "@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
  406. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  407. {
  408. // Fetch asset query.
  409. AssetQuery* pAssetQuery;
  410. Sim::findObject(assetQuery, pAssetQuery);
  411. // Did we find the asset query?
  412. if ( pAssetQuery == NULL )
  413. {
  414. // No, so warn.
  415. Con::warnf("AssetManager::findAssetCategory() - Could not find the asset query object '%s'.", assetQuery);
  416. return -1;
  417. }
  418. // Fetch asset category.
  419. const char* pAssetCategory = assetCategory;
  420. // Perform query.
  421. return object->findAssetCategory( pAssetQuery, pAssetCategory, assetQueryAsSource );
  422. }
  423. //-----------------------------------------------------------------------------
  424. DefineEngineMethod(AssetManager, findAssetAutoUnload, S32, (const char* assetQuery, bool assetAutoUnload, bool assetQueryAsSource), ("", false, false),
  425. "Performs an asset query searching for the specified asset auto-unload flag.\n"
  426. "@param assetQuery The asset query object that will be populated with the results.\n"
  427. "@param assetInternal The asset internal flag to search for.\n"
  428. "@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
  429. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  430. {
  431. // Fetch asset query.
  432. AssetQuery* pAssetQuery;
  433. Sim::findObject(assetQuery, pAssetQuery);
  434. // Did we find the asset query?
  435. if ( pAssetQuery == NULL )
  436. {
  437. // No, so warn.
  438. Con::warnf("AssetManager::findAssetAutoUnload() - Could not find the asset query object '%s'.", assetQuery);
  439. return -1;
  440. }
  441. // Perform query.
  442. return object->findAssetAutoUnload( pAssetQuery, assetAutoUnload, assetQueryAsSource );
  443. }
  444. //-----------------------------------------------------------------------------
  445. DefineEngineMethod(AssetManager, findAssetInternal, S32, (const char* assetQuery, bool assetInternal, bool assetQueryAsSource), ("", false, false),
  446. "Performs an asset query searching for the specified asset internal flag.\n"
  447. "@param assetQuery The asset query object that will be populated with the results.\n"
  448. "@param assetInternal The asset internal flag to search for.\n"
  449. "@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
  450. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  451. {
  452. // Fetch asset query.
  453. AssetQuery* pAssetQuery;
  454. Sim::findObject(assetQuery, pAssetQuery);
  455. // Did we find the asset query?
  456. if ( pAssetQuery == NULL )
  457. {
  458. // No, so warn.
  459. Con::warnf("AssetManager::findAssetInternal() - Could not find the asset query object '%s'.", assetQuery);
  460. return -1;
  461. }
  462. // Perform query.
  463. return object->findAssetInternal( pAssetQuery, assetInternal, assetQueryAsSource );
  464. }
  465. //-----------------------------------------------------------------------------
  466. DefineEngineMethod(AssetManager, findAssetPrivate, S32, (const char* assetQuery, bool assetPrivate, bool assetQueryAsSource), ("", false, false),
  467. "Performs an asset query searching for the specified asset private flag.\n"
  468. "@param assetQuery The asset query object that will be populated with the results.\n"
  469. "@param assetPrivate The asset private flag to search for.\n"
  470. "@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
  471. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  472. {
  473. // Fetch asset query.
  474. AssetQuery* pAssetQuery;
  475. Sim::findObject(assetQuery, pAssetQuery);
  476. // Did we find the asset query?
  477. if ( pAssetQuery == NULL )
  478. {
  479. // No, so warn.
  480. Con::warnf("AssetManager::findAssetPrivate() - Could not find the asset query object '%s'.", assetQuery);
  481. return -1;
  482. }
  483. // Perform query.
  484. return object->findAssetInternal( pAssetQuery, assetPrivate, assetQueryAsSource );
  485. }
  486. //-----------------------------------------------------------------------------
  487. DefineEngineMethod(AssetManager, findAssetType, S32, (const char* assetQuery, const char* assetType, bool assetQueryAsSource), ("", "", false),
  488. "Performs an asset query searching for the specified asset type.\n"
  489. "@param assetQuery The asset query object that will be populated with the results.\n"
  490. "@param assetType The asset type to search for.\n"
  491. "@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
  492. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  493. {
  494. // Fetch asset query.
  495. AssetQuery* pAssetQuery;
  496. Sim::findObject(assetQuery, pAssetQuery);
  497. // Did we find the asset query?
  498. if ( pAssetQuery == NULL )
  499. {
  500. // No, so warn.
  501. Con::warnf("AssetManager::findAssetType() - Could not find the asset query object '%s'.", assetQuery);
  502. return -1;
  503. }
  504. // Fetch asset type.
  505. const char* pAssetType = assetType;
  506. // Perform query.
  507. return object->findAssetType( pAssetQuery, pAssetType, assetQueryAsSource );
  508. }
  509. //-----------------------------------------------------------------------------
  510. DefineEngineMethod(AssetManager, findAssetDependsOn, S32, (const char* assetQuery, const char* assetId), ("", ""),
  511. "Performs an asset query searching for asset Ids that the specified asset Id depends on.\n"
  512. "@param assetQuery The asset query object that will be populated with the results.\n"
  513. "@param assetId The asset Id to query for any asset Ids that it depends on.\n"
  514. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  515. {
  516. // Fetch asset query.
  517. AssetQuery* pAssetQuery;
  518. Sim::findObject(assetQuery, pAssetQuery);
  519. // Did we find the asset query?
  520. if ( pAssetQuery == NULL )
  521. {
  522. // No, so warn.
  523. Con::warnf("AssetManager::findAssetDependsOn() - Could not find the asset query object '%s'.", assetQuery);
  524. return -1;
  525. }
  526. // Fetch asset Id.
  527. const char* pAssetId = assetId;
  528. // Perform query.
  529. return object->findAssetDependsOn( pAssetQuery, pAssetId );
  530. }
  531. //-----------------------------------------------------------------------------
  532. DefineEngineMethod(AssetManager, findAssetIsDependedOn, S32, (const char* assetQuery, const char* assetId), ("", ""),
  533. "Performs an asset query searching for asset Ids that depend on the specified asset Id.\n"
  534. "@param assetQuery The asset query object that will be populated with the results.\n"
  535. "@param assetId The asset Id to query for any asset Ids that may depend on it.\n"
  536. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  537. {
  538. // Fetch asset query.
  539. AssetQuery* pAssetQuery;
  540. Sim::findObject(assetQuery, pAssetQuery);
  541. // Did we find the asset query?
  542. if ( pAssetQuery == NULL )
  543. {
  544. // No, so warn.
  545. Con::warnf("AssetManager::findAssetIsDependedOn() - Could not find the asset query object '%s'.", assetQuery);
  546. return -1;
  547. }
  548. // Fetch asset Id.
  549. const char* pAssetId = assetId;
  550. // Perform query.
  551. return object->findAssetIsDependedOn( pAssetQuery, pAssetId );
  552. }
  553. //-----------------------------------------------------------------------------
  554. DefineEngineMethod(AssetManager, findInvalidAssetReferences, S32, (const char* assetQuery), (""),
  555. "Performs an asset query searching for invalid asset references.\n"
  556. "@param assetQuery The asset query object that will be populated with the results.\n"
  557. "@return The number of asset Ids found that are invalid or (-1) if an error occurred.\n")
  558. {
  559. // Fetch asset query.
  560. AssetQuery* pAssetQuery;
  561. Sim::findObject(assetQuery, pAssetQuery);
  562. // Did we find the asset query?
  563. if ( pAssetQuery == NULL )
  564. {
  565. // No, so warn.
  566. Con::warnf("AssetManager::findInvalidAssetReferences() - Could not find the asset query object '%s'.", assetQuery);
  567. return -1;
  568. }
  569. // Perform query.
  570. return object->findInvalidAssetReferences( pAssetQuery );
  571. }
  572. //-----------------------------------------------------------------------------
  573. DefineEngineMethod(AssetManager, findTaggedAssets, S32, (const char* assetQuery, const char* assetTagNames, bool assetQueryAsSource), ("", "", false),
  574. "Performs an asset query searching for the specified asset tag name(s).\n"
  575. "@param assetQuery The asset query object that will be populated with the results.\n"
  576. "@param assetTagNames The asset tag name or names to search for. Multiple names can be specified using comma, space, tab or newline separation. Tags use an OR operation i.e. only assets tagged with ANY of the specified tags will be returned.\n"
  577. "@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
  578. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  579. {
  580. // Fetch asset query.
  581. AssetQuery* pAssetQuery;
  582. Sim::findObject(assetQuery, pAssetQuery);
  583. // Did we find the asset query?
  584. if ( pAssetQuery == NULL )
  585. {
  586. // No, so warn.
  587. Con::warnf("AssetManager::findTaggedAssets() - Could not find the asset query object '%s'.", assetQuery);
  588. return -1;
  589. }
  590. // Fetch asset tag name(s).
  591. const char* pAssetTagNames = assetTagNames;
  592. // Perform query.
  593. return object->findTaggedAssets( pAssetQuery, pAssetTagNames, assetQueryAsSource );
  594. }
  595. //-----------------------------------------------------------------------------
  596. DefineEngineMethod(AssetManager, findAssetLooseFile, S32, (const char* assetQuery, const char* assetLooseFile, bool assetQueryAsSource), ("", "", false),
  597. "Performs an asset query searching for the specified loose file.\n"
  598. "@param assetQuery The asset query object that will be populated with the results.\n"
  599. "@param assetLooseFile The loose-file used by the asset to search for.\n"
  600. "@param assetQueryAsSource Whether to use the asset query as the data-source rather than the asset managers database or not. Doing this effectively filters the asset query. Optional: Defaults to false.\n"
  601. "@return The number of asset Ids found or (-1) if an error occurred.\n")
  602. {
  603. // Fetch asset query.
  604. AssetQuery* pAssetQuery;
  605. Sim::findObject(assetQuery, pAssetQuery);
  606. // Did we find the asset query?
  607. if ( pAssetQuery == NULL )
  608. {
  609. // No, so warn.
  610. Con::warnf("AssetManager::findAssetLooseFile() - Could not find the asset query object '%s'.", assetQuery);
  611. return -1;
  612. }
  613. // Fetch asset loose file.
  614. const char* pAssetLooseFile = assetLooseFile;
  615. // Perform query.
  616. return object->findAssetLooseFile( pAssetQuery, pAssetLooseFile, assetQueryAsSource );
  617. }
  618. //-----------------------------------------------------------------------------
  619. DefineEngineMethod(AssetManager, getDeclaredAssetCount, bool, (),,
  620. "Gets the number of declared assets.\n"
  621. "@return Returns the number of declared assets.\n")
  622. {
  623. return object->getDeclaredAssetCount();
  624. }
  625. //-----------------------------------------------------------------------------
  626. DefineEngineMethod(AssetManager, getReferencedAssetCount, bool, (), ,
  627. "Gets the number of asset referenced.\n"
  628. "@return Returns the number of asset references.\n")
  629. {
  630. return object->getReferencedAssetCount();
  631. }
  632. //-----------------------------------------------------------------------------
  633. DefineEngineMethod(AssetManager, getLoadedInternalAssetCount, bool, (), ,
  634. "Gets the number of loaded internal assets.\n"
  635. "@return Returns the number of loaded internal assets.\n")
  636. {
  637. return object->getLoadedInternalAssetCount();
  638. }
  639. //-----------------------------------------------------------------------------
  640. DefineEngineMethod(AssetManager, getMaxLoadedInternalAssetCount, bool, (), ,
  641. "Gets the maximum number of loaded internal assets.\n"
  642. "@return Returns the maximum number of loaded internal assets.\n")
  643. {
  644. return object->getMaxLoadedInternalAssetCount();
  645. }
  646. //-----------------------------------------------------------------------------
  647. DefineEngineMethod(AssetManager, getLoadedExternalAssetCount, bool, (), ,
  648. "Gets the number of loaded external assets.\n"
  649. "@return Returns the number of loaded external assets.\n")
  650. {
  651. return object->getLoadedExternalAssetCount();
  652. }
  653. //-----------------------------------------------------------------------------
  654. DefineEngineMethod(AssetManager, getMaxLoadedExternalAssetCount, bool, (), ,
  655. "Gets the maximum number of loaded external assets.\n"
  656. "@return Returns the maximum number of loaded external assets.\n")
  657. {
  658. return object->getMaxLoadedExternalAssetCount();
  659. }
  660. //-----------------------------------------------------------------------------
  661. DefineEngineMethod(AssetManager, dumpDeclaredAssets, void, (), ,
  662. "Dumps a breakdown of all declared assets.\n"
  663. "@return No return value.\n")
  664. {
  665. return object->dumpDeclaredAssets();
  666. }