Implements support of autoloaded assets.

This commit is contained in:
Areloch 2017-10-14 22:10:42 -05:00
parent efbd5fb451
commit 4e03f07e8e
5 changed files with 184 additions and 0 deletions

View file

@ -54,6 +54,14 @@
#include "console/consoleTypes.h"
#endif
#ifndef _AUTOLOAD_ASSETS_H_
#include "assets/autoloadAssets.h"
#endif
#ifndef COMPONENTASSET_H
#include "T3D/assets/ComponentAsset.h"
#endif
// Script bindings.
#include "assetManager_ScriptBinding.h"
@ -202,6 +210,57 @@ bool AssetManager::addModuleDeclaredAssets( ModuleDefinition* pModuleDefinition
return true;
}
bool AssetManager::loadModuleAutoLoadAssets(ModuleDefinition* pModuleDefinition)
{
// Debug Profiling.
PROFILE_SCOPE(AssetManager_loadModuleAutoLoadAssets);
// Sanity!
AssertFatal(pModuleDefinition != NULL, "Cannot auto load assets using a NULL module definition");
// Does the module have any assets associated with it?
if (pModuleDefinition->getModuleAssets().empty())
{
// Yes, so warn.
Con::warnf("Asset Manager: Cannot auto load assets to module '%s' as it has no existing assets.", pModuleDefinition->getSignature());
return false;
}
U32 assetCount = pModuleDefinition->getModuleAssets().size();
// Iterate the module definition children.
for (SimSet::iterator itr = pModuleDefinition->begin(); itr != pModuleDefinition->end(); ++itr)
{
// Fetch the declared assets.
AutoloadAssets* pAutoloadAssets = dynamic_cast<AutoloadAssets*>(*itr);
// Skip if it's not a declared assets location.
if (pAutoloadAssets == NULL)
continue;
for (U32 i = 0; i < assetCount; ++i)
{
AssetDefinition* assetDef = pModuleDefinition->getModuleAssets()[i];
if (assetDef->mAssetType == pAutoloadAssets->getAssetType())
{
//TODO: this is stupid and ugly, need to properly automagically parse the class for registration
AssetBase* assetBase = nullptr;
if (assetDef->mAssetType == StringTable->insert("ComponentAsset"))
{
assetBase = mTaml.read<ComponentAsset>(assetDef->mAssetBaseFilePath);
}
//load the asset now if valid
if (assetBase)
addPrivateAsset(assetBase);
}
}
}
return true;
}
//-----------------------------------------------------------------------------
bool AssetManager::addDeclaredAsset( ModuleDefinition* pModuleDefinition, const char* pAssetFilePath )
@ -2974,6 +3033,9 @@ void AssetManager::onModulePreLoad( ModuleDefinition* pModuleDefinition )
// Add module declared assets.
addModuleDeclaredAssets( pModuleDefinition );
// Load any auto-loaded asset types
loadModuleAutoLoadAssets(pModuleDefinition);
// Is an asset tags manifest specified?
if ( pModuleDefinition->getAssetTagsManifest() != StringTable->EmptyString() )
{