Explorar o código

explosion and guiobjectview

marauder2k7 hai 2 meses
pai
achega
51f4255c14

+ 12 - 10
Engine/source/T3D/fx/explosion.cpp

@@ -239,7 +239,7 @@ ExplosionData::ExplosionData()
    explosionScale.set(1.0f, 1.0f, 1.0f);
    playSpeed = 1.0f;
 
-   INIT_ASSET(ExplosionShape);
+   mExplosionShapeAsset.registerRefreshNotify(this);
 
    explosionAnimation = -1;
 
@@ -315,7 +315,7 @@ ExplosionData::ExplosionData(const ExplosionData& other, bool temp_clone) : Game
    particleEmitterId = other.particleEmitterId; // -- for pack/unpack of particleEmitter ptr 
    explosionScale = other.explosionScale;
    playSpeed = other.playSpeed;
-   CLONE_ASSET(ExplosionShape);
+   mExplosionShapeAsset = other.mExplosionShapeAsset;
    explosionAnimation = other.explosionAnimation; // -- from explosionShape sequence "ambient"
    dMemcpy( emitterList, other.emitterList, sizeof( emitterList ) );
    dMemcpy( emitterIDList, other.emitterIDList, sizeof( emitterIDList ) ); // -- for pack/unpack of emitterList ptrs
@@ -360,6 +360,8 @@ ExplosionData::~ExplosionData()
    if (!isTempClone())
       return;
 
+   mExplosionShapeAsset.unregisterRefreshNotify();
+
    // particleEmitter, emitterList[*], debrisList[*], explosionList[*] will delete themselves
 
 #ifdef TRACK_EXPLOSION_DATA_CLONES
@@ -393,7 +395,7 @@ void ExplosionData::initPersistFields()
 {
    docsURL;
    addGroup("Shapes");
-      INITPERSISTFIELD_SHAPEASSET(ExplosionShape, ExplosionData, "@brief Optional shape asset to place at the center of the explosion.\n\n"
+      INITPERSISTFIELD_SHAPEASSET_REFACTOR(ExplosionShape, ExplosionData, "@brief Optional shape asset to place at the center of the explosion.\n\n"
          "The <i>ambient</i> animation of this model will be played automatically at the start of the explosion.");
    endGroup("Shapes");
 
@@ -668,7 +670,7 @@ void ExplosionData::packData(BitStream* stream)
 {
    Parent::packData(stream);
 
-   PACKDATA_ASSET(ExplosionShape);
+   PACKDATA_ASSET_REFACTOR(ExplosionShape);
 
    //PACKDATA_SOUNDASSET(Sound);
    PACKDATA_ASSET(Sound);
@@ -773,7 +775,7 @@ void ExplosionData::unpackData(BitStream* stream)
 {
 	Parent::unpackData(stream);
 
-   UNPACKDATA_ASSET(ExplosionShape);
+   UNPACKDATA_ASSET_REFACTOR(ExplosionShape);
 
    UNPACKDATA_ASSET(Sound);
 
@@ -897,10 +899,10 @@ bool ExplosionData::preload(bool server, String &errorStr)
    if (mExplosionShapeAsset.notNull()) {
 
       // Resolve animations
-      explosionAnimation = mExplosionShape->findSequence("ambient");
+      explosionAnimation = getExplosionShape()->findSequence("ambient");
 
       // Preload textures with a dummy instance...
-      TSShapeInstance* pDummy = new TSShapeInstance(mExplosionShape, !server);
+      TSShapeInstance* pDummy = new TSShapeInstance(getExplosionShape(), !server);
       delete pDummy;
 
    } else {
@@ -1392,8 +1394,8 @@ bool Explosion::explode()
    launchDebris( mInitialNormal );
    spawnSubExplosions();
 
-   if (bool(mDataBlock->mExplosionShape) && mDataBlock->explosionAnimation != -1) {
-      mExplosionInstance = new TSShapeInstance(mDataBlock->mExplosionShape, true);
+   if (bool(mDataBlock->getExplosionShape()) && mDataBlock->explosionAnimation != -1) {
+      mExplosionInstance = new TSShapeInstance(mDataBlock->getExplosionShape(), true);
 
       mExplosionThread   = mExplosionInstance->addThread();
       mExplosionInstance->setSequence(mExplosionThread, mDataBlock->explosionAnimation, 0);
@@ -1403,7 +1405,7 @@ bool Explosion::explode()
       mEndingMS = U32(mExplosionInstance->getScaledDuration(mExplosionThread) * 1000.0f);
 
       mObjScale.convolve(mDataBlock->explosionScale);
-      mObjBox = mDataBlock->mExplosionShape->mBounds;
+      mObjBox = mDataBlock->getExplosionShape()->mBounds;
       resetWorldBox();
    }
 

+ 4 - 4
Engine/source/T3D/fx/explosion.h

@@ -52,7 +52,7 @@ struct DebrisData;
 
 class SFXProfile;
 //--------------------------------------------------------------------------
-class ExplosionData : public GameBaseData {
+class ExplosionData : public GameBaseData, protected AssetPtrCallback {
   public:
    typedef GameBaseData Parent;
 
@@ -79,8 +79,7 @@ class ExplosionData : public GameBaseData {
    Point3F              explosionScale;
    F32                  playSpeed;
 
-   DECLARE_SHAPEASSET(ExplosionData, ExplosionShape, onShapeChanged);
-   DECLARE_ASSET_SETGET(ExplosionData, ExplosionShape);
+   DECLARE_SHAPEASSET_REFACTOR(ExplosionData, ExplosionShape)
 
    S32               explosionAnimation;
 
@@ -143,7 +142,8 @@ public:
    ExplosionData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0);
    bool   allowSubstitutions() const override { return true; }
 
-   void onShapeChanged()
+protected:
+   void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
    {
       reloadOnLocalClient();
    }

+ 36 - 40
Engine/source/T3D/guiObjectView.cpp

@@ -119,8 +119,6 @@ GuiObjectView::GuiObjectView()
    // By default don't do dynamic reflection
    // updates for this viewport.
    mReflectPriority = 0.0f;
-   INIT_ASSET(Model);
-   INIT_ASSET(MountedModel);
 }
 
 //------------------------------------------------------------------------------
@@ -137,7 +135,7 @@ void GuiObjectView::initPersistFields()
 {
    docsURL;
    addGroup( "Model" );   
-      INITPERSISTFIELD_SHAPEASSET(Model, GuiObjectView, "The source shape asset.");
+      INITPERSISTFIELD_SHAPEASSET_REFACTOR(Model, GuiObjectView, "The source shape asset.");
       addField( "skin", TypeRealString, Offset( mSkinName, GuiObjectView ),
          "The skin to use on the object model." );   
    endGroup( "Model" );
@@ -150,7 +148,7 @@ void GuiObjectView::initPersistFields()
    endGroup( "Animation" );
    
    addGroup( "Mounting" );   
-      INITPERSISTFIELD_SHAPEASSET(MountedModel, GuiObjectView, "The mounted shape asset.");
+   INITPERSISTFIELD_SHAPEASSET_REFACTOR(MountedModel, GuiObjectView, "The mounted shape asset.");
       addField( "mountedSkin", TypeRealString, Offset( mMountSkinName, GuiObjectView ),
          "Skin name used on mounted shape file." );
       addField( "mountedNode", TypeRealString, Offset( mMountNodeName, GuiObjectView ),
@@ -335,19 +333,23 @@ bool GuiObjectView::setObjectModel( const String& modelName )
 {
    mRunThread = 0;
 
-   // Load the shape.
-   _setModel(modelName);
-   if( !getModelResource())
+   // Load the shape if its not the one already set.
+   if (modelName.c_str() != _getModelAssetId())
+      _setModel(modelName.c_str());
+   else
+      return true;
+
+   if( !getModel())
    {
       Con::warnf( "GuiObjectView::setObjectModel - Failed to load model '%s'", modelName.c_str() );
       return false;
    }
 
-   if (!getModelResource()->preloadMaterialList(getModelResource().getPath())) return false;
+   if (!getModel()->preloadMaterialList(getModel().getPath())) return false;
 
    // Instantiate it.
 
-   mModelInstance = new TSShapeInstance(getModelResource(), true );
+   mModelInstance = new TSShapeInstance(getModel(), true );
    mModelInstance->resetMaterialList();
    mModelInstance->cloneMaterialList();
    
@@ -359,8 +361,8 @@ bool GuiObjectView::setObjectModel( const String& modelName )
    mModelInstance->initMaterialList();
    // Initialize camera values.
    
-   mOrbitPos = getModelResource()->center;
-   mMinOrbitDist = getModelResource()->mRadius;
+   mOrbitPos = getModel()->center;
+   mMinOrbitDist = getModel()->mRadius;
 
    // Initialize animation.
    
@@ -369,11 +371,6 @@ bool GuiObjectView::setObjectModel( const String& modelName )
    return true;
 }
 
-void GuiObjectView::onModelChanged()
-{
-
-}
-
 //------------------------------------------------------------------------------
 
 void GuiObjectView::setSkin( const String& name )
@@ -389,17 +386,21 @@ void GuiObjectView::setSkin( const String& name )
 
 bool GuiObjectView::setMountedObject( const String& modelName )
 {
-   // Load the model.   
-   _setMountedModel(modelName);
-   if (!getMountedModelResource())
+   // Load the model if it is not already the asset then set it..
+   if (modelName.c_str() != _getMountedModelAssetId())
+      _setMountedModel(modelName.c_str());
+   else
+      return true;
+
+   if (!getMountedModel())
    {
       Con::warnf("GuiObjectView::setMountedObject - Failed to load model '%s'", modelName.c_str());
       return false;
    }
 
-   if (!getMountedModelResource()->preloadMaterialList(getMountedModelResource().getPath())) return false;
+   if (!getMountedModel()->preloadMaterialList(getMountedModel().getPath())) return false;
 
-   mMountedModelInstance = new TSShapeInstance(getMountedModelResource(), true);
+   mMountedModelInstance = new TSShapeInstance(getMountedModel(), true);
    mMountedModelInstance->resetMaterialList();
    mMountedModelInstance->cloneMaterialList();
 
@@ -413,11 +414,6 @@ bool GuiObjectView::setMountedObject( const String& modelName )
    return true;
 }
 
-void GuiObjectView::onMountedModelChanged()
-{
-
-}
-
 //------------------------------------------------------------------------------
 
 void GuiObjectView::setMountSkin(const String& name)
@@ -632,7 +628,7 @@ void GuiObjectView::setLightDirection( const Point3F& direction )
 
 void GuiObjectView::_initAnimation()
 {
-   AssertFatal(getModelResource(), "GuiObjectView::_initAnimation - No model loaded!" );
+   AssertFatal(getModel(), "GuiObjectView::_initAnimation - No model loaded!" );
    
    if( mAnimationSeqName.isEmpty() && mAnimationSeq == -1 )
       return;
@@ -641,13 +637,13 @@ void GuiObjectView::_initAnimation()
             
    if( !mAnimationSeqName.isEmpty() )
    {
-      mAnimationSeq = getModelResource()->findSequence( mAnimationSeqName );
+      mAnimationSeq = getModel()->findSequence( mAnimationSeqName );
       
       if( mAnimationSeq == -1 )
       {
          Con::errorf( "GuiObjectView::_initAnimation - Cannot find animation sequence '%s' on '%s'",
             mAnimationSeqName.c_str(),
-            mModelName
+            _getModelAssetId()
          );
          
          return;
@@ -658,11 +654,11 @@ void GuiObjectView::_initAnimation()
       
    if( mAnimationSeq != -1 )
    {
-      if( mAnimationSeq >= getModelResource()->sequences.size() )
+      if( mAnimationSeq >= getModel()->sequences.size() )
       {
          Con::errorf( "GuiObjectView::_initAnimation - Sequence '%i' out of range for model '%s'",
             mAnimationSeq,
-            mModelName
+            _getModelAssetId()
          );
          
          mAnimationSeq = -1;
@@ -693,12 +689,12 @@ void GuiObjectView::_initMount()
    
    if( !mMountNodeName.isEmpty() )
    {
-      mMountNode = getModelResource()->findNode( mMountNodeName );
+      mMountNode = getModel()->findNode( mMountNodeName );
       if( mMountNode == -1 )
       {
          Con::errorf( "GuiObjectView::_initMount - No node '%s' on '%s'",
             mMountNodeName.c_str(),
-            mModelName
+            _getModelAssetId()
          );
          
          return;
@@ -707,11 +703,11 @@ void GuiObjectView::_initMount()
    
    // Make sure mount node is valid.
    
-   if( mMountNode != -1 && mMountNode >= getModelResource()->nodes.size() )
+   if( mMountNode != -1 && mMountNode >= getModel()->nodes.size() )
    {
       Con::errorf( "GuiObjectView::_initMount - Mount node index '%i' out of range for '%s'",
          mMountNode,
-         mModelName
+         _getModelAssetId()
       );
       
       mMountNode = -1;
@@ -720,11 +716,11 @@ void GuiObjectView::_initMount()
    
    // Look up node on the mounted model from
    // which to mount to the primary model's node.
-   if (!getMountedModelResource()) return;
-   S32 mountPoint = getMountedModelResource()->findNode( "mountPoint" );
+   if (!getMountedModel()) return;
+   S32 mountPoint = getMountedModel()->findNode( "mountPoint" );
    if( mountPoint != -1 )
    {
-      getMountedModelResource()->getNodeWorldTransform(mountPoint, &mMountTransform),
+      getMountedModel()->getNodeWorldTransform(mountPoint, &mMountTransform),
       mMountTransform.inverse();
    }
 }
@@ -745,7 +741,7 @@ DefineEngineMethod( GuiObjectView, getModel, const char*, (),,
    "@return Name of the displayed model.\n\n"
    "@see GuiControl")
 {
-   return Con::getReturnBuffer( object->getModel() );
+   return Con::getReturnBuffer( object->_getModelAssetId() );
 }
 
 //-----------------------------------------------------------------------------
@@ -775,7 +771,7 @@ DefineEngineMethod( GuiObjectView, getMountedModel, const char*, (),,
    "@return Name of the mounted model.\n\n"
    "@see GuiControl")
 {
-   return Con::getReturnBuffer( object->getMountedModel() );
+   return Con::getReturnBuffer( object->_getMountedModelAssetId() );
 }
 
 //-----------------------------------------------------------------------------

+ 15 - 20
Engine/source/T3D/guiObjectView.h

@@ -37,7 +37,7 @@ class LightInfo;
 
 
 /// A control that displays a TSShape in its view.
-class GuiObjectView : public GuiTSCtrl
+class GuiObjectView : public GuiTSCtrl, protected AssetPtrCallback
 {
    public:
    
@@ -70,15 +70,8 @@ class GuiObjectView : public GuiTSCtrl
       /// @{
       
       ///Model loaded for display.
-      DECLARE_SHAPEASSET(GuiObjectView, Model, onModelChanged);
-      static bool _setModelData(void* obj, const char* index, const char* data)\
-      {
-         bool ret = false;
-         GuiObjectView* object = static_cast<GuiObjectView*>(obj);
-         ret = object->setObjectModel(StringTable->insert(data));
-         return ret;
-      }
-      void onModelChanged();
+      DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, Model)
+
       TSShapeInstance* mModelInstance;
       /// Name of skin to use on model.
       String mSkinName;
@@ -109,15 +102,7 @@ class GuiObjectView : public GuiTSCtrl
       /// @{
       
       ///Model to mount to the primary model.
-      DECLARE_SHAPEASSET(GuiObjectView, MountedModel, onMountedModelChanged);
-      static bool _setMountedModelData(void* obj, const char* index, const char* data)\
-      {
-         bool ret = false;
-         GuiObjectView* object = static_cast<GuiObjectView*>(obj);
-         ret = object->setMountedObject(StringTable->insert(data));
-         return ret;
-      }
-      void onMountedModelChanged();
+      DECLARE_SHAPEASSET_REFACTOR(GuiObjectView, MountedModel)
       TSShapeInstance* mMountedModelInstance;
       
       ///
@@ -284,7 +269,17 @@ class GuiObjectView : public GuiTSCtrl
       static void initPersistFields();
 
       DECLARE_CONOBJECT( GuiObjectView );
-      DECLARE_DESCRIPTION( "A control that shows a TSShape model." );   
+      DECLARE_DESCRIPTION( "A control that shows a TSShape model." );
+
+protected:
+   void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
+   {
+      if (mModelAsset.notNull())
+         setObjectModel(_getModelAssetId());
+
+      if (mMountedModelAsset.notNull())
+         setMountedObject(_getMountedModelAssetId());
+   }
 };
 
 #endif // !_GUIOBJECTVIEW_H_