2
0
Эх сурвалжийг харах

Merge pull request #1515 from Azaezel/alpha41/preLoad

try to load shapes during preload
Brian Roberts 2 сар өмнө
parent
commit
5c9e34a90c

+ 6 - 6
Engine/source/T3D/assets/ShapeAsset.h

@@ -122,7 +122,7 @@ public:
 
    U32 load() override;
 
-   TSShape* getShape() { return mShape; }
+   TSShape* getShape() { load(); return mShape; }
 
    Resource<TSShape> getShapeResource() { load(); return mShape; }
 
@@ -295,7 +295,7 @@ public:
    };                                                                                                                                                                         \
                                                                                                                                                                               \
    inline StringTableEntry _get##name##AssetId(void) const { return m##name##Asset.getAssetId(); }                                                                            \
-   Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); }                  \
+   TSShape* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShape(); else return NULL; }                                                                \
    AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; }                                                                                                     \
    static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; }  \
    StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapeFile() : ""; }
@@ -353,12 +353,12 @@ public:
    };                                                                                                                                                                         \
                                                                                                                                                                               \
    inline StringTableEntry _get##name##AssetId(void) const { return m##name##Asset.getAssetId(); }                                                                            \
-   Resource<TSShape> get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShapeResource(); else return ResourceManager::get().load( "" ); }                  \
+   TSShape* get##name() { if (m##name##Asset.notNull()) return m##name##Asset->getShape(); else return NULL; }                                                                \
    AssetPtr<ShapeAsset> get##name##Asset(void) { return m##name##Asset; }                                                                                                     \
    static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false; }  \
    StringTableEntry get##name##File() { return m##name##Asset.notNull() ? m##name##Asset->getShapeFile() : ""; }  
 
-#define INITPERSISTFIELD_SHAPEASSET_REFACTOR(name, consoleClass, docs)                                                                                                                \
+#define INITPERSISTFIELD_SHAPEASSET_REFACTOR(name, consoleClass, docs)                                                                                                        \
    addProtectedField(assetText(name, Asset), TypeShapeAssetPtr, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.)); \
    addProtectedField(assetText(name, File), TypeFilename, Offset(m##name##File, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, file docs.));
 
@@ -414,7 +414,7 @@ public:
    };                                                                                                                                                                         \
                                                                                                                                                                               \
    inline StringTableEntry _get##name##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); }                                                         \
-   Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \
+   TSShape* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShape(); else return NULL; }                                  \
    AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; }                                                                                  \
    static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
    StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapeFile() : ""; }
@@ -472,7 +472,7 @@ public:
    };                                                                                                                                                                         \
                                                                                                                                                                               \
    inline StringTableEntry _get##name##AssetId(const U32& index) const { return m##name##Asset[index].getAssetId(); }                                                         \
-   Resource<TSShape> get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShapeResource(); else return ResourceManager::get().load( "" ); } \
+   TSShape* get##name(const U32& index) { if (m##name##Asset[index].notNull()) return m##name##Asset[index]->getShape(); else return NULL; }                                   \
    AssetPtr<ShapeAsset> get##name##Asset(const U32& index) { return m##name##Asset[index]; }                                                                                  \
    static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data), dAtoi(index)); return false;}\
    StringTableEntry get##name##File(const U32& idx) { return m##name##Asset[idx].notNull() ? m##name##Asset[idx]->getShapeFile() : ""; }

+ 7 - 8
Engine/source/T3D/debris.cpp

@@ -274,21 +274,20 @@ bool DebrisData::preload(bool server, String &errorStr)
 
    if( server ) return true;
 
-   if (mShapeAsset.notNull())
+   if (getShape())
    {
-      if (!getShape())
-      {
-         errorStr = String::ToString("DebrisData::load: Couldn't load shape \"%s\"", _getShapeAssetId());
-         return false;
-      }
-      else
       {
          TSShapeInstance* pDummy = new TSShapeInstance(getShape(), !server);
          delete pDummy;
-         if (!server && !getShape()->preloadMaterialList(getShape().getPath()) && NetConnection::filesWereDownloaded())
+         if (!server && !getShape()->preloadMaterialList(getShapeFile()) && NetConnection::filesWereDownloaded())
             return false;
       }
    }
+   else
+   {
+      errorStr = String::ToString("DebrisData::load: Couldn't load shape \"%s\"", _getShapeAssetId());
+      return false;
+   }
 
    return true;
 }

+ 1 - 1
Engine/source/T3D/examples/renderShapeExample.cpp

@@ -191,7 +191,7 @@ void RenderShapeExample::createShape()
 
    // Attempt to preload the Materials for this shape
    if ( isClientObject() && 
-        !getShape()->preloadMaterialList(getShape().getPath() ) &&
+        !getShape()->preloadMaterialList(getShapeFile()) &&
         NetConnection::filesWereDownloaded() )
    {
       return;

+ 1 - 1
Engine/source/T3D/fx/explosion.cpp

@@ -896,7 +896,7 @@ bool ExplosionData::preload(bool server, String &errorStr)
          }
    }
 
-   if (mExplosionShapeAsset.notNull()) {
+   if (getExplosionShape()) {
 
       // Resolve animations
       explosionAnimation = getExplosionShape()->findSequence("ambient");

+ 1 - 1
Engine/source/T3D/fx/groundCover.cpp

@@ -889,7 +889,7 @@ void GroundCover::_initShapes()
       if ( mShapeAsset[i].isNull() || getShape(i) == nullptr)
          continue;
 
-      if ( isClientObject() && !getShape(i)->preloadMaterialList(getShape(i).getPath()) && NetConnection::filesWereDownloaded() )
+      if ( isClientObject() && !getShape(i)->preloadMaterialList(getShapeFile(i)) && NetConnection::filesWereDownloaded() )
       {
          Con::warnf( "GroundCover::_initShapes() material preload failed for shape: %s", _getShapeAssetId(i));
          continue;

+ 2 - 2
Engine/source/T3D/guiObjectView.cpp

@@ -345,7 +345,7 @@ bool GuiObjectView::setObjectModel( const String& modelName )
       return false;
    }
 
-   if (!getModel()->preloadMaterialList(getModel().getPath())) return false;
+   if (!getModel()->preloadMaterialList(getModelFile())) return false;
 
    // Instantiate it.
 
@@ -398,7 +398,7 @@ bool GuiObjectView::setMountedObject( const String& modelName )
       return false;
    }
 
-   if (!getMountedModel()->preloadMaterialList(getMountedModel().getPath())) return false;
+   if (!getMountedModel()->preloadMaterialList(getMountedModelFile())) return false;
 
    mMountedModelInstance = new TSShapeInstance(getMountedModel(), true);
    mMountedModelInstance->resetMaterialList();

+ 2 - 2
Engine/source/T3D/guiObjectView.h

@@ -274,10 +274,10 @@ class GuiObjectView : public GuiTSCtrl, protected AssetPtrCallback
 protected:
    void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
    {
-      if (mModelAsset.notNull())
+      if (getModel())
          setObjectModel(_getModelAssetId());
 
-      if (mMountedModelAsset.notNull())
+      if (getMountedModel())
          setMountedObject(_getMountedModelAssetId());
    }
 };

+ 1 - 1
Engine/source/T3D/physics/physicsDebris.cpp

@@ -97,7 +97,7 @@ bool PhysicsDebrisData::preload( bool server, String &errorStr )
 
    if ( server ) return true;
 
-   if ( mShapeAsset.notNull() )
+   if ( getShape() )
    {
       // Create a dummy shape to force the generation of shaders and materials
       // during the level load and not during gameplay.

+ 7 - 8
Engine/source/T3D/physics/physicsShape.cpp

@@ -285,16 +285,15 @@ bool PhysicsShapeData::preload( bool server, String &errorBuffer )
 
    bool shapeError = false;
 
-   if (mShapeAsset.notNull())
+   if (getShape())
    {
-      if (bool(getShape()) == false)
-      {
-         errorBuffer = String::ToString("PhysicsShapeData: Couldn't load shape \"%s\"", _getShapeAssetId());
-         return false;
-      }
-      if (!server && !getShape()->preloadMaterialList(getShape().getPath()) && NetConnection::filesWereDownloaded())
+      if (!server && !getShape()->preloadMaterialList(getShapeFile()) && NetConnection::filesWereDownloaded())
          shapeError = true;
-
+   }
+   else
+   {
+      errorBuffer = String::ToString("PhysicsShapeData: Couldn't load shape \"%s\"", _getShapeAssetId());
+      return false;
    }
 
    // Prepare the shared physics collision shape.

+ 3 - 3
Engine/source/T3D/player.cpp

@@ -615,18 +615,18 @@ bool PlayerData::preload(bool server, String &errorStr)
             return false;
          }
 
-         if (!server && !getShapeFP(i)->preloadMaterialList(getShapeFP(i).getPath()) && NetConnection::filesWereDownloaded())
+         if (!server && !getShapeFP(i)->preloadMaterialList(getShapeFPFile(i)) && NetConnection::filesWereDownloaded())
             shapeError = true;
 
          if (computeCRC)
          {
             Con::printf("Validation required for mounted image %d shape: %s", i, _getShapeFPAssetId(i));
 
-            Torque::FS::FileNodeRef    fileRef = Torque::FS::GetFileNode(getShapeFP(i).getPath());
+            Torque::FS::FileNodeRef    fileRef = Torque::FS::GetFileNode(getShapeFPFile(i));
 
             if (!fileRef)
             {
-               errorStr = String::ToString("PlayerData: Mounted image %d loading failed, shape \"%s\" is not found.", i, getShapeFP(i).getPath().getFullPath().c_str());
+               errorStr = String::ToString("PlayerData: Mounted image %d loading failed, shape \"%s\" is not found.", i, getShapeFPFile(i));
                return false;
             }
 

+ 10 - 14
Engine/source/T3D/projectile.cpp

@@ -381,22 +381,18 @@ bool ProjectileData::preload(bool server, String &errorStr)
             Con::errorf(ConsoleLogEntry::General, "ProjectileData::preload: Invalid packet, bad datablockid(lightDesc): %d", lightDescId);   
    }
 
-   if (mProjectileShapeAsset.notNull())
+   if (getProjectileShape())
    {
-      //If we've got a shapeAsset assigned for our projectile, but we failed to load the shape data itself, report the error
-      if (!getProjectileShape())
-      {
-         errorStr = String::ToString("ProjectileData::load: Couldn't load shape \"%s\"", _getProjectileShapeAssetId());
-         return false;
-      }
-      else
-      {
-         activateSeq = getProjectileShape()->findSequence("activate");
-         maintainSeq = getProjectileShape()->findSequence("maintain");
+      activateSeq = getProjectileShape()->findSequence("activate");
+      maintainSeq = getProjectileShape()->findSequence("maintain");
 
-         TSShapeInstance* pDummy = new TSShapeInstance(getProjectileShape(), !server);
-         delete pDummy;
-      }
+      TSShapeInstance* pDummy = new TSShapeInstance(getProjectileShape(), !server);
+      delete pDummy;
+   }
+   else
+   {
+      errorStr = String::ToString("ProjectileData::load: Couldn't load shape \"%s\"", _getProjectileShapeAssetId());
+      return false;
    }
 
    return true;

+ 4 - 3
Engine/source/T3D/shapeBase.cpp

@@ -343,7 +343,7 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
             "ShapeBaseData::preload: invalid debris data");
       }
 
-      if(mDebrisShapeAsset.notNull())
+      if(getDebrisShape())
       {
          TSShapeInstance* pDummy = new TSShapeInstance(getDebrisShape(), !server);
          delete pDummy;
@@ -351,12 +351,13 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
    }
 
    S32 i;
-   if (mShapeAsset.notNull())
+   if (getShape())
    {
+      //mShapeAsset->load();
       U32 assetStatus = ShapeAsset::getAssetErrCode(mShapeAsset);
       if (assetStatus == AssetBase::Ok || assetStatus == AssetBase::UsingFallback)
       {
-         if (!server && !getShape()->preloadMaterialList(getShape().getPath()) && NetConnection::filesWereDownloaded())
+         if (!server && !getShape()->preloadMaterialList(getShapeFile()) && NetConnection::filesWereDownloaded())
             shapeError = true;
 
          if (computeCRC)

+ 1 - 1
Engine/source/T3D/shapeImage.cpp

@@ -461,7 +461,7 @@ bool ShapeBaseImageData::preload(bool server, String &errorStr)
          {
             Con::printf("Validation required for shape asset: %s", mShapeAsset[i]->getAssetId());
 
-            Torque::FS::FileNodeRef    fileRef = Torque::FS::GetFileNode(getShape(i).getPath());
+            Torque::FS::FileNodeRef    fileRef = Torque::FS::GetFileNode(getShapeFile(i));
 
             if (!fileRef)
             {

+ 7 - 8
Engine/source/T3D/tsStatic.cpp

@@ -390,16 +390,10 @@ bool TSStatic::_createShape()
    mAmbientThread = NULL;
    //mShape = NULL;
 
-   if (mShapeAsset.notNull())
+   if (getShape())
    {
-      if (!getShape())
-      {
-         Con::errorf("TSStatic::_createShape() - Shape Asset %s had no valid shape!", mShapeAsset.getAssetId());
-         return false;
-      }
-
       if (isClientObject() &&
-         !getShape()->preloadMaterialList(getShape().getPath()) &&
+         !getShape()->preloadMaterialList(getShapeFile()) &&
          NetConnection::filesWereDownloaded())
          return false;
 
@@ -440,6 +434,11 @@ bool TSStatic::_createShape()
          Sim::findObject(cubeDescId, reflectorDesc);
       }
    }
+   else
+   {
+      Con::errorf("TSStatic::_createShape() - Shape Asset %s had no valid shape!", mShapeAsset.getAssetId());
+      return false;
+   }
 
    //Set up the material slot vars for easy manipulation
    /*S32 materialCount = mShape->materialList->getMaterialNameList().size(); //mMeshAsset->getMaterialCount();

+ 1 - 1
Engine/source/afx/afxMagicMissile.h

@@ -139,7 +139,7 @@ public:
   */
 
    // variables set on preload:
-  Resource<TSShape>     projectileShape;
+  TSShape*     projectileShape;
   /*
   S32 activateSeq;
   S32 maintainSeq;

+ 6 - 8
Engine/source/afx/ce/afxModel.cpp

@@ -127,14 +127,8 @@ bool afxModelData::preload(bool server, String &errorStr)
   if (server) 
     return true;
   
-  if (mShapeAsset.notNull())
+  if (getShape())
   {
-    if (!getShape())
-    {
-      errorStr = String::ToString("afxModelData::load: Failed to load shape \"%s\"", _getShapeAssetId());
-      return false;
-    }
-
     // just parse up the string and collect the remappings in txr_tag_remappings.
     if (remap_txr_tags != ST_NULLSTRING)
     {
@@ -167,7 +161,11 @@ bool afxModelData::preload(bool server, String &errorStr)
       delete pDummy;
     }
   }
-
+  else
+  {
+     errorStr = String::ToString("afxModelData::load: Failed to load shape \"%s\"", _getShapeAssetId());
+     return false;
+  }
   return true;
 }
 

+ 1 - 1
Engine/source/forest/forestItem.h

@@ -143,7 +143,7 @@ public:
       return theSignal;
    }
 
-   Resource<TSShape> mShape;
+   TSShape* mShape;
 
 protected:
    void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override

+ 2 - 2
Engine/source/forest/ts/tsForestItemData.cpp

@@ -127,7 +127,7 @@ void TSForestItemData::_loadShape()
       return;
 
    if ( mIsClientObject && 
-       !mShape->preloadMaterialList(mShape.getPath()) )
+       !mShape->preloadMaterialList(getShapeFile()) )
       return;
    
    // Lets add an autobillboard detail if don't have one.
@@ -177,7 +177,7 @@ void TSForestItemData::_checkLastDetail()
    // TODO: Expose some real parameters to the datablock maybe?
    if ( detail->subShapeNum != -1 )
    {
-      mShape->addImposter(mShape.getPath(), 10, 4, 0, 0, 256, 0, 0);
+      mShape->addImposter(getShapeFile(), 10, 4, 0, 0, 256, 0, 0);
 
       // HACK: If i don't do this it crashes!
       while ( mShape->detailCollisionAccelerators.size() < mShape->details.size() )