Przeglądaj źródła

Resource hot-swap for animation clips

BearishSun 9 lat temu
rodzic
commit
1eb3a2f6f3

+ 11 - 1
Source/BansheeCore/Include/BsAnimation.h

@@ -4,6 +4,7 @@
 
 #include "BsCorePrerequisites.h"
 #include "BsCoreObject.h"
+#include "BsIResourceListener.h"
 #include "BsFlags.h"
 #include "BsSkeleton.h"
 #include "BsSkeletonMask.h"
@@ -214,7 +215,7 @@ namespace BansheeEngine
 	 * thread for updating attached scene objects and bones (if skeleton is attached), or the data is made available for
 	 * manual queries in the case of generic animation.
 	 */
-	class BS_CORE_EXPORT Animation : public CoreObject
+	class BS_CORE_EXPORT Animation : public CoreObject, public IResourceListener
 	{
 	public:
 		~Animation();
@@ -423,6 +424,15 @@ namespace BansheeEngine
 		 */
 		AnimationClipInfo* addClip(const HAnimationClip& clip, UINT32 layer, bool stopExisting = true);
 
+		/** @copydoc IResourceListener::getListenerResources */
+		void getListenerResources(Vector<HResource>& resources) override;
+
+		/** @copydoc IResourceListener::notifyResourceLoaded */
+		void notifyResourceLoaded(const HResource& resource) override;
+
+		/** @copydoc IResourceListener::notifyResourceChanged */
+		void notifyResourceChanged(const HResource& resource) override;
+
 		UINT64 mId;
 		AnimWrapMode mDefaultWrapMode;
 		float mDefaultSpeed;

+ 3 - 3
Source/BansheeCore/Include/BsMeshBase.h

@@ -122,7 +122,7 @@ namespace BansheeEngine
 
 	protected:
 		/** @copydoc CoreObjectCore::syncToCore */
-		virtual void syncToCore(const CoreSyncData& data) override;
+		void syncToCore(const CoreSyncData& data) override;
 
 		MeshProperties mProperties;
 	};
@@ -167,7 +167,7 @@ namespace BansheeEngine
 
 	protected:
 		/** @copydoc CoreObject::syncToCore */
-		virtual CoreSyncData syncToCore(FrameAlloc* allocator) override;
+		CoreSyncData syncToCore(FrameAlloc* allocator) override;
 
 		MeshProperties mProperties;
 
@@ -180,7 +180,7 @@ namespace BansheeEngine
 	public:
 		friend class MeshBaseRTTI;
 		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
+		RTTITypeBase* getRTTI() const override;
 	};
 
 	/** @} */

+ 19 - 0
Source/BansheeCore/Source/BsAnimation.cpp

@@ -915,6 +915,25 @@ namespace BansheeEngine
 		return output;
 	}
 
+	void Animation::getListenerResources(Vector<HResource>& resources)
+	{
+		for (auto& entry : mClipInfos)
+		{
+			if(entry.clip != nullptr)
+				resources.push_back(entry.clip);
+		}
+	}
+
+	void Animation::notifyResourceLoaded(const HResource& resource)
+	{
+		mDirty |= AnimDirtyStateFlag::Layout;
+	}
+
+	void Animation::notifyResourceChanged(const HResource& resource)
+	{
+		mDirty |= AnimDirtyStateFlag::Layout;
+	}
+
 	bool Animation::isPlaying() const
 	{
 		for(auto& clipInfo : mClipInfos)

+ 6 - 0
Source/BansheeEngine/Source/BsRenderable.cpp

@@ -444,12 +444,18 @@ namespace BansheeEngine
 
 	void Renderable::notifyResourceLoaded(const HResource& resource)
 	{
+		if (resource == mMesh)
+			onMeshChanged();
+
 		markDependenciesDirty();
 		markCoreDirty();
 	}
 
 	void Renderable::notifyResourceChanged(const HResource& resource)
 	{
+		if(resource == mMesh)
+			onMeshChanged();
+
 		markDependenciesDirty();
 		markCoreDirty();
 	}