Browse Source

Separates out acquireAsset call for importing assets until after all assets have been imported, then runs it as a post step to ensure all assets are properly loaded before they're used

JeffR 3 năm trước cách đây
mục cha
commit
1c7c32baa6

+ 0 - 5
Engine/source/T3D/assets/MaterialAsset.cpp

@@ -174,11 +174,6 @@ void MaterialAsset::initializeAsset()
       return;
    }
 
-   if (mMatDefinitionName == StringTable->insert("DetailBlue"))
-   {
-      bool asdfsd = true;
-   }
-
    if (size() != 0 && mScriptPath == StringTable->EmptyString())
    {
       mLoadedState = EmbeddedDefinition;

+ 32 - 5
Engine/source/T3D/assets/assetImporter.cpp

@@ -1727,7 +1727,8 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
 
       //If there was no existing assetId, then lets see if it already exists in a legacy file, like a materials.cs or materials.tscript
       //If it does, we'll just make our asset point to that instead of a new file
-      Material* mat = MATMGR->getMaterialDefinitionByName(assetName);
+      Material* mat;
+      Sim::findObject(assetName, mat);
 
       if (!mat)
          mat = MATMGR->getMaterialDefinitionByMapTo(assetName);
@@ -2618,6 +2619,8 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath, String typ
    else
    {
       importAssets();
+
+      acquireAssets();
    }
 
    dumpActivityLog();
@@ -2729,10 +2732,6 @@ void AssetImporter::importAssets(AssetImportObject* assetItem)
                      tss->setShapeAssetId(assetId);
                }
             }
-
-            //Go ahead and force the asset to load now just to kick it for immediate use
-            AssetBase* assetDef = AssetDatabase.acquireAsset<AssetBase>(assetId);
-            AssetDatabase.releaseAsset(assetId);
          }
          else
          {
@@ -2757,6 +2756,34 @@ void AssetImporter::importAssets(AssetImportObject* assetItem)
    dumpActivityLog();
 }
 
+void AssetImporter::acquireAssets(AssetImportObject* assetItem)
+{
+   Vector<AssetImportObject*> itemList = importingAssets;
+   if (assetItem != nullptr)
+      itemList = assetItem->childAssetItems;
+
+   for (U32 i = 0; i < itemList.size(); i++)
+   {
+      AssetImportObject* item = itemList[i];
+      if (item->importStatus == AssetImportObject::Skipped ||
+         item->importStatus == AssetImportObject::NotProcessed ||
+         item->importStatus == AssetImportObject::Error)
+         continue;
+
+      //recurse if needed, we want to process child items first for dependency reasons
+      acquireAssets(item);
+
+      //Go ahead and force the asset to load now just to kick it for immediate use
+      String assetId = item->moduleName + ":" + item->assetName;
+
+      if (AssetDatabase.isDeclaredAsset(assetId))
+      {
+         AssetBase* assetDef = AssetDatabase.acquireAsset<AssetBase>(assetId);
+         AssetDatabase.releaseAsset(assetId);
+      }
+   }
+}
+
 //
 // Type-specific import logic
 //

+ 6 - 0
Engine/source/T3D/assets/assetImporter.h

@@ -914,6 +914,12 @@ public:
    /// </summary>
    Torque::Path importShapeAnimationAsset(AssetImportObject* assetItem);
 
+   /// <summary>
+   /// Iterates over all the items in the current session and acquires them, which jumpstarts the loading/init'ng process on them, making the available for use immediately
+   /// <para>@param assetItem, if null, will loop over and recurse the main import asset items, if a specific AssetImportObject is passed in, it will recurse it's children</para>
+   /// </summary>
+   void acquireAssets(AssetImportObject* assetItem = nullptr);
+
    //
    /// <summary>
    /// Gets the currently active import configuration

+ 3 - 1
Engine/source/T3D/assets/assetImporter_ScriptBinding.h

@@ -92,7 +92,9 @@ DefineEngineMethod(AssetImporter, resolveAssetItemIssues, void, (AssetImportObje
 DefineEngineMethod(AssetImporter, importAssets, void, (),,
    "Runs the actual import action on the items.")
 {
-   return object->importAssets();
+   object->importAssets();
+
+   object->acquireAssets();
 }
 
 DefineEngineMethod(AssetImporter, getAssetItemCount, S32, (),,