ModuleManager and AssetManager updated for T3D mount system.

Platform file calls replaced with Torque::FS calls when scanning for or loading files.
This commit is contained in:
OTHGMars 2021-01-11 05:03:00 -05:00
parent fd85491ed7
commit 8148bdfcdd
3 changed files with 56 additions and 147 deletions

View file

@ -668,11 +668,8 @@ AssetImportObject* AssetImporter::findImportingAssetByName(String assetName, Ass
ModuleDefinition* AssetImporter::getModuleFromPath(Torque::Path filePath) ModuleDefinition* AssetImporter::getModuleFromPath(Torque::Path filePath)
{ {
//We want to ensure it's a full filepath, because the module system internally uses full paths for the module dirs // Use a relative path so modules on mounted file systems will be found.
char fullPath[2048]; ModuleDefinition* moduleDef = ModuleDatabase.findModuleByFilePath(Platform::makeRelativePathName(filePath.getFullPath().c_str(), NULL));
Platform::makeFullPathName(filePath.getFullPath().c_str(), fullPath, sizeof(fullPath));
ModuleDefinition* moduleDef = ModuleDatabase.findModuleByFilePath(StringTable->insert(fullPath));
return moduleDef; return moduleDef;
} }

View file

@ -201,18 +201,18 @@ bool AssetManager::addModuleDeclaredAssets( ModuleDefinition* pModuleDefinition
continue; continue;
// Expand asset manifest location. // Expand asset manifest location.
char filePathBuffer[1024]; char filePathBuffer[1024], extensionBuffer[256];
String mdldfpth = pModuleDefinition->getModulePath(); String mdldfpth = pModuleDefinition->getModulePath();
String astfpth = pDeclaredAssets->getPath(); String astfpth = pDeclaredAssets->getPath();
//dSprintf( filePathBuffer, sizeof(filePathBuffer), "%s/%s", pModuleDefinition->getModulePath(), pDeclaredAssets->getPath() );
dSprintf(filePathBuffer, sizeof(filePathBuffer), "%s/%s", pModuleDefinition->getModulePath(), pDeclaredAssets->getPath()); dSprintf(filePathBuffer, sizeof(filePathBuffer), "%s/%s", pModuleDefinition->getModulePath(), pDeclaredAssets->getPath());
dSprintf(extensionBuffer, sizeof(extensionBuffer), "*.%s", pDeclaredAssets->getExtension());
// Scan declared assets at location. // Scan declared assets at location.
if ( !scanDeclaredAssets( filePathBuffer, pDeclaredAssets->getExtension(), pDeclaredAssets->getRecurse(), pModuleDefinition ) ) if ( !scanDeclaredAssets( filePathBuffer, extensionBuffer, pDeclaredAssets->getRecurse(), pModuleDefinition ) )
{ {
// Warn. // Warn.
Con::warnf( "AssetManager::addModuleDeclaredAssets() - Could not scan for declared assets at location '%s' with extension '%s'.", filePathBuffer, pDeclaredAssets->getExtension() ); Con::warnf( "AssetManager::addModuleDeclaredAssets() - No assets found at location '%s' with extension '%s'.", filePathBuffer, pDeclaredAssets->getExtension() );
} }
} }
@ -289,7 +289,7 @@ bool AssetManager::addDeclaredAsset( ModuleDefinition* pModuleDefinition, const
// Expand asset file-path. // Expand asset file-path.
char assetFilePathBuffer[1024]; char assetFilePathBuffer[1024];
Con::expandPath( assetFilePathBuffer, sizeof(assetFilePathBuffer), pAssetFilePath ); dStrcpy(assetFilePathBuffer, Platform::makeRelativePathName(pAssetFilePath, NULL), sizeof(assetFilePathBuffer));
// Find the final slash which should be just before the file. // Find the final slash which should be just before the file.
char* pFileStart = dStrrchr( assetFilePathBuffer, '/' ); char* pFileStart = dStrrchr( assetFilePathBuffer, '/' );
@ -1479,7 +1479,7 @@ bool AssetManager::loadAssetTags( ModuleDefinition* pModuleDefinition )
} }
// Is the specified file valid? // Is the specified file valid?
if ( Platform::isFile( assetTagsManifestFilePathBuffer ) ) if (Torque::FS::IsFile( assetTagsManifestFilePathBuffer ) )
{ {
// Yes, so read asset tags manifest. // Yes, so read asset tags manifest.
mAssetTagsManifest = mTaml.read<AssetTagsManifest>( assetTagsManifestFilePathBuffer ); mAssetTagsManifest = mTaml.read<AssetTagsManifest>( assetTagsManifestFilePathBuffer );
@ -2298,12 +2298,8 @@ S32 AssetManager::findAssetLooseFile( AssetQuery* pAssetQuery, const char* pLoos
AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." ); AssertFatal( pAssetQuery != NULL, "Cannot use NULL asset query." );
AssertFatal( pLooseFile != NULL, "Cannot use NULL loose file." ); AssertFatal( pLooseFile != NULL, "Cannot use NULL loose file." );
// Expand loose file. // Make game relative path for loose file.
char looseFileBuffer[1024]; StringTableEntry looseFile = Platform::makeRelativePathName(pLooseFile, NULL);;
Con::expandPath(looseFileBuffer, sizeof(looseFileBuffer), pLooseFile, NULL, false );
// Fetch asset loose file.
StringTableEntry looseFile = StringTable->insert( looseFileBuffer );
// Reset result count. // Reset result count.
S32 resultCount = 0; S32 resultCount = 0;
@ -2401,24 +2397,30 @@ bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension
AssertFatal( pExtension != NULL, "Cannot scan declared assets with NULL extension." ); AssertFatal( pExtension != NULL, "Cannot scan declared assets with NULL extension." );
// Expand path location. // Expand path location.
char pathBuffer[1024]; String relativePath = Platform::makeRelativePathName(pPath, NULL);
Con::expandPath( pathBuffer, sizeof(pathBuffer), pPath ); // Strip any trailing slash off the path.
if (relativePath.endsWith("/"))
relativePath = relativePath.substr(0, relativePath.length() - 1);
Torque::Path scanPath = Torque::FS::GetCwd();
scanPath.setPath(relativePath);
// Find files. // Find files.
Vector<Platform::FileInfo> files; Vector<String> files;
if ( !Platform::dumpPath( pathBuffer, files, recurse ? -1 : 0 ) ) S32 numAssets = Torque::FS::FindByPattern(scanPath, pExtension, recurse, files, true);
if (numAssets <= 0)
{ {
// Failed so warn. // Failed so warn. or don't... Common error when scanning modules with no assets
Con::warnf( "Asset Manager: Failed to scan declared assets in directory '%s'.", pathBuffer ); //Con::warnf( "Asset Manager: No declared assets found in directory '%s'.", relativePath.c_str());
return false; return false;
} }
// Is the asset file-path located within the specified module? // Is the asset file-path located within the specified module?
if ( !Con::isBasePath( pathBuffer, pModuleDefinition->getModulePath() ) ) if ( !Con::isBasePath(relativePath.c_str(), pModuleDefinition->getModulePath()) )
{ {
// No, so warn. // No, so warn.
Con::warnf( "Asset Manager: Could not add declared asset file '%s' as file does not exist with module path '%s'", Con::warnf( "Asset Manager: Could not add declared asset file '%s' as file does not exist with module path '%s'",
pathBuffer, pPath,
pModuleDefinition->getModulePath() ); pModuleDefinition->getModulePath() );
return false; return false;
} }
@ -2427,43 +2429,25 @@ bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension
if ( mEchoInfo ) if ( mEchoInfo )
{ {
Con::printSeparator(); Con::printSeparator();
Con::printf( "Asset Manager: Scanning for declared assets in path '%s' for files with extension '%s'...", pathBuffer, pExtension ); Con::printf( "Asset Manager: Scanning for declared assets in path '%s' for files with extension '%s'...", relativePath.c_str(), pExtension );
} }
// Fetch extension length.
const U32 extensionLength = dStrlen( pExtension );
// Fetch module assets. // Fetch module assets.
ModuleDefinition::typeModuleAssetsVector& moduleAssets = pModuleDefinition->getModuleAssets(); ModuleDefinition::typeModuleAssetsVector& moduleAssets = pModuleDefinition->getModuleAssets();
TamlAssetDeclaredVisitor assetDeclaredVisitor; TamlAssetDeclaredVisitor assetDeclaredVisitor;
// Iterate files. // Iterate files.
for ( Vector<Platform::FileInfo>::iterator fileItr = files.begin(); fileItr != files.end(); ++fileItr ) for (S32 i = 0; i < numAssets; ++i)
{ {
// Fetch file info. Torque::Path assetPath = files[i];
Platform::FileInfo& fileInfo = *fileItr;
// Fetch filename.
const char* pFilename = fileInfo.pFileName;
// Find filename length.
const U32 filenameLength = dStrlen( pFilename );
// Skip if extension is longer than filename.
if ( extensionLength > filenameLength )
continue;
// Skip if extension not found.
if ( dStricmp( pFilename + filenameLength - extensionLength, pExtension ) != 0 )
continue;
// Clear declared assets. // Clear declared assets.
assetDeclaredVisitor.clear(); assetDeclaredVisitor.clear();
// Format full file-path. // Format full file-path.
char assetFileBuffer[1024]; char assetFileBuffer[1024];
dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", fileInfo.pFullPath, fileInfo.pFileName ); dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", assetPath.getPath().c_str(), assetPath.getFullFileName().c_str());
// Parse the filename. // Parse the filename.
if ( !mTaml.parse( assetFileBuffer, assetDeclaredVisitor ) ) if ( !mTaml.parse( assetFileBuffer, assetDeclaredVisitor ) )
@ -2585,7 +2569,7 @@ bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension
if ( mEchoInfo ) if ( mEchoInfo )
{ {
Con::printSeparator(); Con::printSeparator();
Con::printf( "Asset Manager: ... Finished scanning for declared assets in path '%s' for files with extension '%s'.", pathBuffer, pExtension ); Con::printf( "Asset Manager: ... Finished scanning for declared assets in path '%s' for files with extension '%s'.", relativePath.c_str(), pExtension );
Con::printSeparator(); Con::printSeparator();
Con::printBlankLine(); Con::printBlankLine();
} }
@ -2605,15 +2589,20 @@ bool AssetManager::scanReferencedAssets( const char* pPath, const char* pExtensi
AssertFatal( pExtension != NULL, "Cannot scan referenced assets with NULL extension." ); AssertFatal( pExtension != NULL, "Cannot scan referenced assets with NULL extension." );
// Expand path location. // Expand path location.
char pathBuffer[1024]; String relativePath = Platform::makeRelativePathName(pPath, NULL);
Con::expandPath( pathBuffer, sizeof(pathBuffer), pPath ); String pattern = "*.";
pattern += pExtension;
Torque::Path scanPath = Torque::FS::GetCwd();
scanPath.setPath(relativePath);
// Find files. // Find files.
Vector<Platform::FileInfo> files; Vector<String> files;
if ( !Platform::dumpPath( pathBuffer, files, recurse ? -1 : 0 ) ) S32 numAssets = Torque::FS::FindByPattern(scanPath, pattern, recurse, files, true);
if (numAssets <= 0)
{ {
// Failed so warn. // Failed so warn.
Con::warnf( "Asset Manager: Failed to scan referenced assets in directory '%s'.", pathBuffer ); Con::warnf( "Asset Manager: Failed to scan referenced assets in directory '%s'.", pPath );
return false; return false;
} }
@ -2621,40 +2610,22 @@ bool AssetManager::scanReferencedAssets( const char* pPath, const char* pExtensi
if ( mEchoInfo ) if ( mEchoInfo )
{ {
Con::printSeparator(); Con::printSeparator();
Con::printf( "Asset Manager: Scanning for referenced assets in path '%s' for files with extension '%s'...", pathBuffer, pExtension ); Con::printf( "Asset Manager: Scanning for referenced assets in path '%s' for files with extension '%s'...", pPath, pExtension );
} }
// Fetch extension length.
const U32 extensionLength = dStrlen( pExtension );
TamlAssetReferencedVisitor assetReferencedVisitor; TamlAssetReferencedVisitor assetReferencedVisitor;
// Iterate files. // Iterate files.
for ( Vector<Platform::FileInfo>::iterator fileItr = files.begin(); fileItr != files.end(); ++fileItr ) for (S32 i = 0; i < numAssets; ++i)
{ {
// Fetch file info. Torque::Path assetPath = files[i];
Platform::FileInfo& fileInfo = *fileItr;
// Fetch filename.
const char* pFilename = fileInfo.pFileName;
// Find filename length.
const U32 filenameLength = dStrlen( pFilename );
// Skip if extension is longer than filename.
if ( extensionLength > filenameLength )
continue;
// Skip if extension not found.
if ( dStricmp( pFilename + filenameLength - extensionLength, pExtension ) != 0 )
continue;
// Clear referenced assets. // Clear referenced assets.
assetReferencedVisitor.clear(); assetReferencedVisitor.clear();
// Format full file-path. // Format full file-path.
char assetFileBuffer[1024]; char assetFileBuffer[1024];
dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", fileInfo.pFullPath, fileInfo.pFileName ); dSprintf( assetFileBuffer, sizeof(assetFileBuffer), "%s/%s", assetPath.getPath().c_str(), assetPath.getFullFileName().c_str());
// Format reference file-path. // Format reference file-path.
typeReferenceFilePath referenceFilePath = StringTable->insert( assetFileBuffer ); typeReferenceFilePath referenceFilePath = StringTable->insert( assetFileBuffer );
@ -2700,7 +2671,7 @@ bool AssetManager::scanReferencedAssets( const char* pPath, const char* pExtensi
// Info. // Info.
if ( mEchoInfo ) if ( mEchoInfo )
{ {
Con::printf( "Asset Manager: ... Finished scanning for referenced assets in path '%s' for files with extension '%s'.", pathBuffer, pExtension ); Con::printf( "Asset Manager: ... Finished scanning for referenced assets in path '%s' for files with extension '%s'.", relativePath.c_str(), pExtension );
Con::printSeparator(); Con::printSeparator();
Con::printBlankLine(); Con::printBlankLine();
} }

View file

@ -198,84 +198,32 @@ bool ModuleManager::scanModules( const char* pPath, const bool rootOnly )
// Sanity! // Sanity!
AssertFatal( pPath != NULL, "Cannot scan module with NULL path." ); AssertFatal( pPath != NULL, "Cannot scan module with NULL path." );
// Expand module location. String relBasePath = Platform::makeRelativePathName(pPath, NULL);
char pathBuffer[1024];
Con::expandPath( pathBuffer, sizeof(pathBuffer), pPath );
// Info. // Info.
if ( mEchoInfo ) if ( mEchoInfo )
{ {
Con::printSeparator(); Con::printSeparator();
Con::printf( "Module Manager: Started scanning '%s'...", pathBuffer ); Con::printf("Module Manager: Started scanning '%s'...", relBasePath.c_str());
} }
Vector<StringTableEntry> directories; String pattern = "*.";
pattern += mModuleExtension;
// Find directories. Torque::Path scanPath = Torque::FS::GetCwd();
if ( !Platform::dumpDirectories( pathBuffer, directories, rootOnly ? 1 : -1 ) ) scanPath.setPath(relBasePath);
{
// Failed so warn.
Con::warnf( "Module Manager: Failed to scan module directories in path '%s'.", pathBuffer );
return false;
}
// Fetch extension length. Vector<String> fileList;
const U32 extensionLength = dStrlen( mModuleExtension ); S32 numModules = Torque::FS::FindByPattern(scanPath, pattern, !rootOnly, fileList, true);
for (S32 i = 0; i < numModules; ++i)
Vector<Platform::FileInfo> files;
// Iterate directories.
for( Vector<StringTableEntry>::iterator basePathItr = directories.begin(); basePathItr != directories.end(); ++basePathItr )
{
// Fetch base path.
StringTableEntry basePath = *basePathItr;
// Skip if we're only processing the root and this is not the root.
if ( rootOnly && basePathItr != directories.begin() )
continue;
// Find files.
files.clear();
if ( !Platform::dumpPath( basePath, files, 0 ) )
{ {
// Failed so warn. Torque::Path modulePath = fileList[i];
Con::warnf( "Module Manager: Failed to scan modules files in directory '%s'.", basePath ); registerModule(modulePath.getPath(), modulePath.getFullFileName());
return false;
}
// Iterate files.
for ( Vector<Platform::FileInfo>::iterator fileItr = files.begin(); fileItr != files.end(); ++fileItr )
{
// Fetch file info.
Platform::FileInfo* pFileInfo = fileItr;
// Fetch filename.
const char* pFilename = pFileInfo->pFileName;
// Find filename length.
const U32 filenameLength = dStrlen( pFilename );
// Skip if extension is longer than filename.
if ( extensionLength > filenameLength )
continue;
// Skip if extension not found.
if ( dStricmp( pFilename + filenameLength - extensionLength, mModuleExtension ) != 0 )
continue;
// Register module.
registerModule( basePath, pFileInfo->pFileName );
}
// Stop processing if we're only processing the root.
if ( rootOnly )
break;
} }
// Info. // Info.
if ( mEchoInfo ) if ( mEchoInfo )
{ {
Con::printf( "Module Manager: Finished scanning '%s'.", pathBuffer ); Con::printf("Module Manager: Finished scanning '%s'.", relBasePath.c_str());
} }
return true; return true;
@ -1065,7 +1013,6 @@ ModuleDefinition* ModuleManager::findModuleByFilePath(StringTableEntry filePath)
String desiredPath = filePath; String desiredPath = filePath;
StringTableEntry coreModuleId = StringTable->insert("CoreModule"); StringTableEntry coreModuleId = StringTable->insert("CoreModule");
StringTableEntry toolsModuleId = StringTable->insert("ToolsModule");
for (typeModuleIdDatabaseHash::iterator moduleIdItr = mModuleIdDatabase.begin(); moduleIdItr != mModuleIdDatabase.end(); ++moduleIdItr) for (typeModuleIdDatabaseHash::iterator moduleIdItr = mModuleIdDatabase.begin(); moduleIdItr != mModuleIdDatabase.end(); ++moduleIdItr)
{ {
@ -2074,12 +2021,6 @@ bool ModuleManager::registerModule( const char* pModulePath, const char* pModule
AssertFatal( pModulePath != NULL, "Cannot scan module with NULL module path." ); AssertFatal( pModulePath != NULL, "Cannot scan module with NULL module path." );
AssertFatal( pModuleFile != NULL, "Cannot scan module with NULL module file." ); AssertFatal( pModuleFile != NULL, "Cannot scan module with NULL module file." );
// Make the module path a full-path.
char fullPathBuffer[1024];
Platform::makeFullPathName( pModulePath, fullPathBuffer, sizeof(fullPathBuffer) );
pModulePath = fullPathBuffer;
char formatBuffer[1024]; char formatBuffer[1024];
// Fetch module path trail character. // Fetch module path trail character.