mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
add compile options to asset manager
CompileAll - allows us to compile all assets to binary CompileModuleAssets - allows us to just compile assets for a specific module CompileAsset - compile a single asset
This commit is contained in:
parent
7d497383da
commit
f1658d2e1e
3 changed files with 206 additions and 4 deletions
|
|
@ -964,6 +964,148 @@ bool AssetManager::renameReferencedAsset( const char* pAssetIdFrom, const char*
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AssetManager::compileAllAssets(const bool compressed, const bool includeUnloaded)
|
||||||
|
{
|
||||||
|
// Debug Profiling.
|
||||||
|
PROFILE_SCOPE(AssetManager_CompileAllAssets);
|
||||||
|
|
||||||
|
// Info.
|
||||||
|
if (mEchoInfo)
|
||||||
|
{
|
||||||
|
Con::printSeparator();
|
||||||
|
Con::printf("Asset Manager: Started compiling ALL assets.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<typeAssetId> assetsToRelease;
|
||||||
|
|
||||||
|
// Are we including unloaded assets?
|
||||||
|
if (includeUnloaded)
|
||||||
|
{
|
||||||
|
// Yes, so prepare a list of assets to release and load them.
|
||||||
|
for (typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr)
|
||||||
|
{
|
||||||
|
// Fetch asset Id.
|
||||||
|
typeAssetId assetId = assetItr->key;
|
||||||
|
|
||||||
|
// Skip if asset is loaded.
|
||||||
|
if (assetItr->value->mpAssetBase != NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Note asset as needing a release.
|
||||||
|
assetsToRelease.push_back(assetId);
|
||||||
|
|
||||||
|
// Acquire the asset.
|
||||||
|
acquireAsset<AssetBase>(assetId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool oldCompressed = mTaml.getBinaryCompression();
|
||||||
|
mTaml.setBinaryCompression(compressed);
|
||||||
|
bool success = false;
|
||||||
|
// Refresh the current loaded assets.
|
||||||
|
// NOTE: This will result in some assets being refreshed more than once due to asset dependencies.
|
||||||
|
for (typeDeclaredAssetsHash::iterator assetItr = mDeclaredAssets.begin(); assetItr != mDeclaredAssets.end(); ++assetItr)
|
||||||
|
{
|
||||||
|
// Skip private assets.
|
||||||
|
if (assetItr->value->mAssetPrivate)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Refresh asset if it's loaded.
|
||||||
|
success = compileAsset(assetItr->key);
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mTaml.setBinaryCompression(oldCompressed);
|
||||||
|
|
||||||
|
// Are we including unloaded assets?
|
||||||
|
if (includeUnloaded)
|
||||||
|
{
|
||||||
|
// Yes, so release the assets we loaded.
|
||||||
|
for (Vector<typeAssetId>::iterator assetItr = assetsToRelease.begin(); assetItr != assetsToRelease.end(); ++assetItr)
|
||||||
|
{
|
||||||
|
releaseAsset(*assetItr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info.
|
||||||
|
if (mEchoInfo)
|
||||||
|
{
|
||||||
|
Con::printSeparator();
|
||||||
|
Con::printf("Asset Manager: Finished compiling ALL assets.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManager::compileModuleAssets(ModuleDefinition* pModuleDefinition)
|
||||||
|
{
|
||||||
|
// Sanity!
|
||||||
|
AssertFatal(pModuleDefinition != NULL, "Cannot remove declared assets using a NULL module definition");
|
||||||
|
|
||||||
|
// Fetch module assets.
|
||||||
|
ModuleDefinition::typeModuleAssetsVector& moduleAssets = pModuleDefinition->getModuleAssets();
|
||||||
|
|
||||||
|
// Remove all module assets.
|
||||||
|
while (moduleAssets.size() > 0)
|
||||||
|
{
|
||||||
|
// Fetch asset definition.
|
||||||
|
AssetDefinition* pAssetDefinition = *moduleAssets.begin();
|
||||||
|
bool success = compileAsset(pAssetDefinition->mAssetId);
|
||||||
|
if (!success)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManager::compileAsset(const char* pAssetId)
|
||||||
|
{
|
||||||
|
// Sanity!
|
||||||
|
AssertFatal(pAssetId != NULL, "Cannot compile NULL asset");
|
||||||
|
|
||||||
|
AssetDefinition* pAssetDefinition = findAsset(pAssetId);
|
||||||
|
|
||||||
|
// Does the asset exist?
|
||||||
|
if (pAssetDefinition == NULL)
|
||||||
|
{
|
||||||
|
Con::warnf("Asset Manager::compileAsset Failed to compile asset Id '%s' as it does not exist", pAssetId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info.
|
||||||
|
if (mEchoInfo)
|
||||||
|
{
|
||||||
|
Con::printSeparator();
|
||||||
|
Con::printf("Asset Manager::compileAsset Started compiling Asset Id '%s'...", pAssetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetBase* pAssetBase = pAssetDefinition->mpAssetBase;
|
||||||
|
if (pAssetBase != NULL)
|
||||||
|
{
|
||||||
|
Torque::Path binaryPath = pAssetDefinition->mAssetBaseFilePath;
|
||||||
|
binaryPath.setExtension(mTaml.getAutoFormatBinaryExtension());
|
||||||
|
// Save asset.
|
||||||
|
mTaml.write(pAssetBase, binaryPath.getFullPath().c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Con::warnf("Asset Manager::compileAsset Failed to compile asset Id '%s' as it does not have an assetBase", pAssetId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info.
|
||||||
|
if (mEchoInfo)
|
||||||
|
{
|
||||||
|
Con::printSeparator();
|
||||||
|
Con::printf("Asset Manager: Finished refreshing Asset Id '%s'.", pAssetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool AssetManager::releaseAsset( const char* pAssetId )
|
bool AssetManager::releaseAsset( const char* pAssetId )
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,28 @@ public:
|
||||||
bool isReferencedAsset( const char* pAssetId );
|
bool isReferencedAsset( const char* pAssetId );
|
||||||
bool renameReferencedAsset( const char* pAssetIdFrom, const char* pAssetIdTo );
|
bool renameReferencedAsset( const char* pAssetIdFrom, const char* pAssetIdTo );
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compile all assets.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="compressed">Do we want binary compression?</param>
|
||||||
|
/// <param name="includeUnloaded">Do we want to include unloaded assets?</param>
|
||||||
|
/// <returns>True if successful, otherwise false.</returns>
|
||||||
|
bool compileAllAssets(const bool compressed = false, const bool includeUnloaded = false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compile all assets for a module.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pModuleDefinition">The module definition to compile.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool compileModuleAssets(ModuleDefinition* pModuleDefinition);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compile a single asset to binary.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pAssetId">The asset id to be compiled.</param>
|
||||||
|
/// <returns>True if successful, otherwise false.</returns>
|
||||||
|
bool compileAsset(const char* pAssetId);
|
||||||
|
|
||||||
/// Public asset acquisition.
|
/// Public asset acquisition.
|
||||||
template<typename T> T* acquireAsset( const char* pAssetId )
|
template<typename T> T* acquireAsset( const char* pAssetId )
|
||||||
{
|
{
|
||||||
|
|
@ -404,4 +426,4 @@ private:
|
||||||
|
|
||||||
extern AssetManager AssetDatabase;
|
extern AssetManager AssetDatabase;
|
||||||
|
|
||||||
#endif // _ASSET_MANAGER_H_
|
#endif // _ASSET_MANAGER_H_
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Copyright (c) 2013 GarageGames, LLC
|
// Copyright (c) 2013 GarageGames, LLC
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
|
@ -20,11 +20,12 @@
|
||||||
// IN THE SOFTWARE.
|
// IN THE SOFTWARE.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
#include "assetBase.h"
|
#include "assets/assetBase.h"
|
||||||
#include "assetManager.h"
|
#include "assets/assetManager.h"
|
||||||
#include "module/moduleDefinition.h"
|
#include "module/moduleDefinition.h"
|
||||||
#include "console/sim.h"
|
#include "console/sim.h"
|
||||||
|
|
||||||
|
|
||||||
DefineEngineMethod(AssetManager, compileReferencedAssets, bool, (const char* moduleDefinition), (""),
|
DefineEngineMethod(AssetManager, compileReferencedAssets, bool, (const char* moduleDefinition), (""),
|
||||||
"Compile the referenced assets determined by the specified module definition.\n"
|
"Compile the referenced assets determined by the specified module definition.\n"
|
||||||
"@param moduleDefinition The module definition specifies the asset manifest.\n"
|
"@param moduleDefinition The module definition specifies the asset manifest.\n"
|
||||||
|
|
@ -853,3 +854,40 @@ DefineEngineMethod(AssetManager, dumpDeclaredAssets, void, (), ,
|
||||||
{
|
{
|
||||||
return object->dumpDeclaredAssets();
|
return object->dumpDeclaredAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DefineEngineMethod(AssetManager, compileAllAssets, bool, (bool compressed, bool includeUnloaded),(false, true),
|
||||||
|
"Compile all assets.\n"
|
||||||
|
"@return true on success.\n")
|
||||||
|
{
|
||||||
|
return object->compileAllAssets(compressed, includeUnloaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod(AssetManager, compileModuleAssets, bool, (const char* moduleDefinition), (""),
|
||||||
|
"Compile all assets for a module.\n"
|
||||||
|
"@return true on success.\n")
|
||||||
|
{
|
||||||
|
// Fetch module definition.
|
||||||
|
ModuleDefinition* pModuleDefinition;
|
||||||
|
Sim::findObject(moduleDefinition, pModuleDefinition);
|
||||||
|
|
||||||
|
// Did we find the module definition?
|
||||||
|
if (pModuleDefinition == NULL)
|
||||||
|
{
|
||||||
|
// No, so warn.
|
||||||
|
Con::warnf("AssetManager::removeDeclaredAssets() - Could not find the module definition '%s'.", moduleDefinition);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove declared assets.
|
||||||
|
return object->compileModuleAssets(pModuleDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod(AssetManager, compileAsset, bool, (const char* assetId), (""),
|
||||||
|
"Compile a single asset.\n"
|
||||||
|
"@return true on success.\n")
|
||||||
|
{
|
||||||
|
return object->compileAsset(assetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue