mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Update assetManager.cpp
load compiled binary if it exists and is newer than the asset file
This commit is contained in:
parent
48680700ab
commit
e1bcced905
1 changed files with 118 additions and 103 deletions
|
|
@ -2692,133 +2692,148 @@ bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension
|
||||||
|
|
||||||
TamlAssetDeclaredVisitor assetDeclaredVisitor;
|
TamlAssetDeclaredVisitor assetDeclaredVisitor;
|
||||||
|
|
||||||
// Iterate files.
|
// Iterate files.
|
||||||
for (S32 i = 0; i < numAssets; ++i)
|
for (S32 i = 0; i < numAssets; ++i)
|
||||||
{
|
{
|
||||||
Torque::Path assetPath = files[i];
|
Torque::Path assetPath = files[i];
|
||||||
|
|
||||||
|
Torque::Path compiledPath = assetPath;
|
||||||
|
compiledPath.setExtension(mTaml.getAutoFormatBinaryExtension());
|
||||||
|
|
||||||
// Clear declared assets.
|
if (Torque::FS::IsFile(compiledPath))
|
||||||
assetDeclaredVisitor.clear();
|
{
|
||||||
|
Torque::FS::FileNodeRef assetFile = Torque::FS::GetFileNode(assetPath);
|
||||||
|
Torque::FS::FileNodeRef compiledFile = Torque::FS::GetFileNode(compiledPath);
|
||||||
|
|
||||||
// Format full file-path.
|
if (assetFile != NULL && compiledFile != NULL)
|
||||||
char assetFileBuffer[1024];
|
{
|
||||||
dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", assetPath.getPath().c_str(), assetPath.getFullFileName().c_str());
|
if (compiledFile->getModifiedTime() >= assetFile->getModifiedTime())
|
||||||
|
assetPath = compiledPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the filename.
|
// Clear declared assets.
|
||||||
if ( !mTaml.parse( assetFileBuffer, assetDeclaredVisitor ) )
|
assetDeclaredVisitor.clear();
|
||||||
{
|
|
||||||
// Warn.
|
|
||||||
Con::warnf( "Asset Manager: Failed to parse file containing asset declaration: '%s'.", assetFileBuffer );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch asset definition.
|
// Format full file-path.
|
||||||
AssetDefinition& foundAssetDefinition = assetDeclaredVisitor.getAssetDefinition();
|
char assetFileBuffer[1024];
|
||||||
|
dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", assetPath.getPath().c_str(), assetPath.getFullFileName().c_str());
|
||||||
|
|
||||||
// Did we get an asset name?
|
// Parse the filename.
|
||||||
if ( foundAssetDefinition.mAssetName == StringTable->EmptyString() )
|
if ( !mTaml.parse( assetFileBuffer, assetDeclaredVisitor ) )
|
||||||
{
|
{
|
||||||
// No, so warn.
|
// Warn.
|
||||||
Con::warnf( "Asset Manager: Parsed file '%s' but did not encounter an asset.", assetFileBuffer );
|
Con::warnf( "Asset Manager: Failed to parse file containing asset declaration: '%s'.", assetFileBuffer );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set module definition.
|
// Fetch asset definition.
|
||||||
foundAssetDefinition.mpModuleDefinition = pModuleDefinition;
|
AssetDefinition& foundAssetDefinition = assetDeclaredVisitor.getAssetDefinition();
|
||||||
|
|
||||||
// Format asset Id.
|
// Did we get an asset name?
|
||||||
char assetIdBuffer[1024];
|
if ( foundAssetDefinition.mAssetName == StringTable->EmptyString() )
|
||||||
dSprintf(assetIdBuffer, sizeof(assetIdBuffer), "%s%s%s",
|
{
|
||||||
pModuleDefinition->getModuleId(),
|
// No, so warn.
|
||||||
ASSET_SCOPE_TOKEN,
|
Con::warnf( "Asset Manager: Parsed file '%s' but did not encounter an asset.", assetFileBuffer );
|
||||||
foundAssetDefinition.mAssetName );
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Set asset Id.
|
// Set module definition.
|
||||||
foundAssetDefinition.mAssetId = StringTable->insert( assetIdBuffer );
|
foundAssetDefinition.mpModuleDefinition = pModuleDefinition;
|
||||||
|
|
||||||
// Does this asset already exist?
|
// Format asset Id.
|
||||||
if ( mDeclaredAssets.contains( foundAssetDefinition.mAssetId ) )
|
char assetIdBuffer[1024];
|
||||||
{
|
dSprintf(assetIdBuffer, sizeof(assetIdBuffer), "%s%s%s",
|
||||||
// Yes, so warn.
|
pModuleDefinition->getModuleId(),
|
||||||
Con::warnf( "Asset Manager: Encountered asset Id '%s' in asset file '%s' but it conflicts with existing asset Id in asset file '%s'.",
|
ASSET_SCOPE_TOKEN,
|
||||||
foundAssetDefinition.mAssetId,
|
foundAssetDefinition.mAssetName );
|
||||||
foundAssetDefinition.mAssetBaseFilePath,
|
|
||||||
mDeclaredAssets.find( foundAssetDefinition.mAssetId )->value->mAssetBaseFilePath );
|
|
||||||
|
|
||||||
continue;
|
// Set asset Id.
|
||||||
}
|
foundAssetDefinition.mAssetId = StringTable->insert( assetIdBuffer );
|
||||||
|
|
||||||
// Create new asset definition.
|
// Does this asset already exist?
|
||||||
AssetDefinition* pAssetDefinition = new AssetDefinition( foundAssetDefinition );
|
if ( mDeclaredAssets.contains( foundAssetDefinition.mAssetId ) )
|
||||||
|
{
|
||||||
|
// Yes, so warn.
|
||||||
|
Con::warnf( "Asset Manager: Encountered asset Id '%s' in asset file '%s' but it conflicts with existing asset Id in asset file '%s'.",
|
||||||
|
foundAssetDefinition.mAssetId,
|
||||||
|
foundAssetDefinition.mAssetBaseFilePath,
|
||||||
|
mDeclaredAssets.find( foundAssetDefinition.mAssetId )->value->mAssetBaseFilePath );
|
||||||
|
|
||||||
// Store in declared assets.
|
continue;
|
||||||
mDeclaredAssets.insert( pAssetDefinition->mAssetId, pAssetDefinition );
|
}
|
||||||
|
|
||||||
// Store in module assets.
|
// Create new asset definition.
|
||||||
moduleAssets.push_back( pAssetDefinition );
|
AssetDefinition* pAssetDefinition = new AssetDefinition( foundAssetDefinition );
|
||||||
|
|
||||||
|
// Store in declared assets.
|
||||||
|
mDeclaredAssets.insert( pAssetDefinition->mAssetId, pAssetDefinition );
|
||||||
|
|
||||||
|
// Store in module assets.
|
||||||
|
moduleAssets.push_back( pAssetDefinition );
|
||||||
|
|
||||||
// Info.
|
// Info.
|
||||||
if ( mEchoInfo )
|
if ( mEchoInfo )
|
||||||
{
|
{
|
||||||
Con::printSeparator();
|
Con::printSeparator();
|
||||||
Con::printf( "Asset Manager: Adding Asset Id '%s' of type '%s' in asset file '%s'.",
|
Con::printf( "Asset Manager: Adding Asset Id '%s' of type '%s' in asset file '%s'.",
|
||||||
pAssetDefinition->mAssetId,
|
pAssetDefinition->mAssetId,
|
||||||
pAssetDefinition->mAssetType,
|
pAssetDefinition->mAssetType,
|
||||||
pAssetDefinition->mAssetBaseFilePath );
|
pAssetDefinition->mAssetBaseFilePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch asset Id.
|
// Fetch asset Id.
|
||||||
StringTableEntry assetId = pAssetDefinition->mAssetId;
|
StringTableEntry assetId = pAssetDefinition->mAssetId;
|
||||||
|
|
||||||
// Fetch asset dependencies.
|
// Fetch asset dependencies.
|
||||||
TamlAssetDeclaredVisitor::typeAssetIdVector& assetDependencies = assetDeclaredVisitor.getAssetDependencies();
|
TamlAssetDeclaredVisitor::typeAssetIdVector& assetDependencies = assetDeclaredVisitor.getAssetDependencies();
|
||||||
|
|
||||||
// Are there any asset dependencies?
|
// Are there any asset dependencies?
|
||||||
if ( assetDependencies.size() > 0 )
|
if ( assetDependencies.size() > 0 )
|
||||||
{
|
{
|
||||||
// Yes, so iterate dependencies.
|
// Yes, so iterate dependencies.
|
||||||
for( TamlAssetDeclaredVisitor::typeAssetIdVector::iterator assetDependencyItr = assetDependencies.begin(); assetDependencyItr != assetDependencies.end(); ++assetDependencyItr )
|
for( TamlAssetDeclaredVisitor::typeAssetIdVector::iterator assetDependencyItr = assetDependencies.begin(); assetDependencyItr != assetDependencies.end(); ++assetDependencyItr )
|
||||||
{
|
{
|
||||||
// Fetch asset Ids.
|
// Fetch asset Ids.
|
||||||
StringTableEntry dependencyAssetId = *assetDependencyItr;
|
StringTableEntry dependencyAssetId = *assetDependencyItr;
|
||||||
|
|
||||||
// Insert depends-on.
|
// Insert depends-on.
|
||||||
mAssetDependsOn.insertEqual( assetId, dependencyAssetId );
|
mAssetDependsOn.insertEqual( assetId, dependencyAssetId );
|
||||||
|
|
||||||
// Insert is-depended-on.
|
// Insert is-depended-on.
|
||||||
mAssetIsDependedOn.insertEqual( dependencyAssetId, assetId );
|
mAssetIsDependedOn.insertEqual( dependencyAssetId, assetId );
|
||||||
|
|
||||||
// Info.
|
// Info.
|
||||||
if ( mEchoInfo )
|
if ( mEchoInfo )
|
||||||
{
|
{
|
||||||
Con::printf( "Asset Manager: Asset Id '%s' has dependency of Asset Id '%s'", assetId, dependencyAssetId );
|
Con::printf( "Asset Manager: Asset Id '%s' has dependency of Asset Id '%s'", assetId, dependencyAssetId );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch asset loose files.
|
// Fetch asset loose files.
|
||||||
TamlAssetDeclaredVisitor::typeLooseFileVector& assetLooseFiles = assetDeclaredVisitor.getAssetLooseFiles();
|
TamlAssetDeclaredVisitor::typeLooseFileVector& assetLooseFiles = assetDeclaredVisitor.getAssetLooseFiles();
|
||||||
|
|
||||||
// Are there any loose files?
|
// Are there any loose files?
|
||||||
if ( assetLooseFiles.size() > 0 )
|
if ( assetLooseFiles.size() > 0 )
|
||||||
{
|
{
|
||||||
// Yes, so iterate loose files.
|
// Yes, so iterate loose files.
|
||||||
for( TamlAssetDeclaredVisitor::typeLooseFileVector::iterator assetLooseFileItr = assetLooseFiles.begin(); assetLooseFileItr != assetLooseFiles.end(); ++assetLooseFileItr )
|
for( TamlAssetDeclaredVisitor::typeLooseFileVector::iterator assetLooseFileItr = assetLooseFiles.begin(); assetLooseFileItr != assetLooseFiles.end(); ++assetLooseFileItr )
|
||||||
{
|
{
|
||||||
// Fetch loose file.
|
// Fetch loose file.
|
||||||
StringTableEntry looseFile = *assetLooseFileItr;
|
StringTableEntry looseFile = *assetLooseFileItr;
|
||||||
|
|
||||||
// Info.
|
// Info.
|
||||||
if ( mEchoInfo )
|
if ( mEchoInfo )
|
||||||
{
|
{
|
||||||
Con::printf( "Asset Manager: Asset Id '%s' has loose file '%s'.", assetId, looseFile );
|
Con::printf( "Asset Manager: Asset Id '%s' has loose file '%s'.", assetId, looseFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store loose file.
|
// Store loose file.
|
||||||
pAssetDefinition->mAssetLooseFiles.push_back( looseFile );
|
pAssetDefinition->mAssetLooseFiles.push_back( looseFile );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info.
|
// Info.
|
||||||
if ( mEchoInfo )
|
if ( mEchoInfo )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue