Просмотр исходного кода

Record SO transform and active state in prefab-diff
Only record SO name change diff if it is actually different

BearishSun 10 лет назад
Родитель
Сommit
a3cc2221ca

+ 21 - 1
BansheeCore/Include/BsPrefabDiff.h

@@ -3,6 +3,8 @@
 #include "BsCorePrerequisites.h"
 #include "BsCorePrerequisites.h"
 #include "BsIReflectable.h"
 #include "BsIReflectable.h"
 #include "BsGameObject.h"
 #include "BsGameObject.h"
+#include "BsVector3.h"
+#include "BsQuaternion.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -26,6 +28,18 @@ namespace BansheeEngine
 		virtual RTTITypeBase* getRTTI() const override;
 		virtual RTTITypeBase* getRTTI() const override;
 	};
 	};
 
 
+	/**
+	 * @brief	Flags that mark which portion of a scene-object is modified.
+	 */
+	enum class SceneObjectDiffFlags
+	{
+		Name = 0x01,
+		Position = 0x02,
+		Rotation = 0x04,
+		Scale = 0x08,
+		Active = 0x10
+	};
+
 	/**
 	/**
 	 * @brief	Contains a set of prefab differences for a single scene object.
 	 * @brief	Contains a set of prefab differences for a single scene object.
 	 *
 	 *
@@ -33,8 +47,14 @@ namespace BansheeEngine
 	 */
 	 */
 	struct BS_CORE_EXPORT PrefabObjectDiff : public IReflectable
 	struct BS_CORE_EXPORT PrefabObjectDiff : public IReflectable
 	{
 	{
-		UINT32 id;
+		UINT32 id = 0;
+
 		String name;
 		String name;
+		Vector3 position;
+		Quaternion rotation;
+		Vector3 scale;
+		bool isActive = false;
+		UINT32 soFlags = 0;
 
 
 		Vector<SPtr<PrefabComponentDiff>> componentDiffs;
 		Vector<SPtr<PrefabComponentDiff>> componentDiffs;
 		Vector<UINT32> removedComponents;
 		Vector<UINT32> removedComponents;

+ 12 - 0
BansheeCore/Include/BsPrefabDiffRTTI.h

@@ -42,7 +42,13 @@ namespace BansheeEngine
 	{
 	{
 	private:
 	private:
 		BS_PLAIN_MEMBER(id)
 		BS_PLAIN_MEMBER(id)
+
 		BS_PLAIN_MEMBER(name)
 		BS_PLAIN_MEMBER(name)
+		BS_PLAIN_MEMBER(position);
+		BS_PLAIN_MEMBER(rotation);
+		BS_PLAIN_MEMBER(scale);
+		BS_PLAIN_MEMBER(isActive);
+		BS_PLAIN_MEMBER(soFlags);
 
 
 		BS_REFLPTR_MEMBER_VEC(componentDiffs)
 		BS_REFLPTR_MEMBER_VEC(componentDiffs)
 		BS_PLAIN_MEMBER_VEC(removedComponents)
 		BS_PLAIN_MEMBER_VEC(removedComponents)
@@ -64,6 +70,12 @@ namespace BansheeEngine
 			BS_ADD_REFLPTR_FIELD_ARR(childDiffs, 5);
 			BS_ADD_REFLPTR_FIELD_ARR(childDiffs, 5);
 			BS_ADD_PLAIN_FIELD_ARR(removedChildren, 6);
 			BS_ADD_PLAIN_FIELD_ARR(removedChildren, 6);
 			BS_ADD_REFLPTR_FIELD_ARR(addedChildren, 7);
 			BS_ADD_REFLPTR_FIELD_ARR(addedChildren, 7);
+
+			BS_ADD_PLAIN_FIELD(position, 8);
+			BS_ADD_PLAIN_FIELD(rotation, 9);
+			BS_ADD_PLAIN_FIELD(scale, 10);
+			BS_ADD_PLAIN_FIELD(isActive, 11);
+			BS_ADD_PLAIN_FIELD(soFlags, 12);
 		}
 		}
 
 
 		virtual const String& getRTTIName() override
 		virtual const String& getRTTIName() override

+ 53 - 4
BansheeCore/Source/BsPrefabDiff.cpp

@@ -62,7 +62,20 @@ namespace BansheeEngine
 
 
 	void PrefabDiff::applyDiff(const SPtr<PrefabObjectDiff>& diff, const HSceneObject& object)
 	void PrefabDiff::applyDiff(const SPtr<PrefabObjectDiff>& diff, const HSceneObject& object)
 	{
 	{
-		object->setName(diff->name);
+		if ((diff->soFlags & (UINT32)SceneObjectDiffFlags::Name) != 0)
+			object->setName(diff->name);
+
+		if ((diff->soFlags & (UINT32)SceneObjectDiffFlags::Position) != 0)
+			object->setPosition(diff->position);
+
+		if ((diff->soFlags & (UINT32)SceneObjectDiffFlags::Rotation) != 0)
+			object->setRotation(diff->rotation);
+
+		if ((diff->soFlags & (UINT32)SceneObjectDiffFlags::Scale) != 0)
+			object->setScale(diff->scale);
+
+		if ((diff->soFlags & (UINT32)SceneObjectDiffFlags::Active) != 0)
+			object->setActive(diff->isActive);
 
 
 		// Note: It is important to remove objects and components first, before adding them.
 		// Note: It is important to remove objects and components first, before adding them.
 		//		 Some systems rely on the fact that applyDiff added components/objects are 
 		//		 Some systems rely on the fact that applyDiff added components/objects are 
@@ -145,6 +158,45 @@ namespace BansheeEngine
 		{
 		{
 			if (output == nullptr)
 			if (output == nullptr)
 				output = bs_shared_ptr_new<PrefabObjectDiff>();
 				output = bs_shared_ptr_new<PrefabObjectDiff>();
+
+			output->name = instance->getName();
+			output->soFlags |= (UINT32)SceneObjectDiffFlags::Name;
+		}
+
+		if (prefab->getPosition() != instance->getPosition())
+		{
+			if (output == nullptr)
+				output = bs_shared_ptr_new<PrefabObjectDiff>();
+
+			output->position = instance->getPosition();
+			output->soFlags |= (UINT32)SceneObjectDiffFlags::Position;
+		}
+
+		if (prefab->getRotation() != instance->getRotation())
+		{
+			if (output == nullptr)
+				output = bs_shared_ptr_new<PrefabObjectDiff>();
+
+			output->rotation = instance->getRotation();
+			output->soFlags |= (UINT32)SceneObjectDiffFlags::Rotation;
+		}
+
+		if (prefab->getScale() != instance->getScale())
+		{
+			if (output == nullptr)
+				output = bs_shared_ptr_new<PrefabObjectDiff>();
+
+			output->scale = instance->getScale();
+			output->soFlags |= (UINT32)SceneObjectDiffFlags::Scale;
+		}
+
+		if (prefab->getActive() != instance->getActive())
+		{
+			if (output == nullptr)
+				output = bs_shared_ptr_new<PrefabObjectDiff>();
+
+			output->isActive = instance->getActive();
+			output->soFlags |= (UINT32)SceneObjectDiffFlags::Active;
 		}
 		}
 
 
 		UINT32 prefabChildCount = prefab->getNumChildren();
 		UINT32 prefabChildCount = prefab->getNumChildren();
@@ -315,10 +367,7 @@ namespace BansheeEngine
 		}
 		}
 
 
 		if (output != nullptr)
 		if (output != nullptr)
-		{
-			output->name = instance->getName();
 			output->id = instance->getLinkId();
 			output->id = instance->getLinkId();
-		}
 
 
 		return output;
 		return output;
 	}
 	}