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

PrefabDiff tested, fixed and working

Marko Pintera 10 лет назад
Родитель
Сommit
5ac5f7fec0

+ 1 - 1
BansheeCore/Include/BsSceneObject.h

@@ -537,7 +537,7 @@ namespace BansheeEngine
 		 *							right away. Otherwise the deallocation will be delayed to the end of
 		 *							frame (preferred method).
 		 */
-		void destroyComponent(const HComponent& component, bool immediate = false);
+		void destroyComponent(const HComponent component, bool immediate = false);
 
 		/**
 		 * @brief	Removes the component from this object, and deallocates it.

+ 5 - 1
BansheeCore/Source/BsPrefab.cpp

@@ -13,7 +13,7 @@ namespace BansheeEngine
 
 	HPrefab Prefab::create(const HSceneObject& sceneObject)
 	{
-		assert(sceneObject->mPrefabLink != nullptr);
+		assert(sceneObject->mPrefabLink == nullptr);
 
 		PrefabPtr newPrefab = createEmpty();
 		newPrefab->initialize(sceneObject);
@@ -57,6 +57,10 @@ namespace BansheeEngine
 				else
 					existingIds.insert(component->mLinkId);
 			}
+
+			UINT32 numChildren = (UINT32)currentSO->getNumChildren();
+			for (UINT32 i = 0; i < numChildren; i++)
+				todo.push(currentSO->getChild(i));
 		}
 
 		auto setIter = existingIds.begin();

+ 8 - 4
BansheeCore/Source/BsPrefabDiff.cpp

@@ -43,7 +43,9 @@ namespace BansheeEngine
 		if (mRoot == nullptr)
 			return;
 
+		GameObjectManager::instance().startDeserialization();
 		applyDiff(mRoot, object);
+		GameObjectManager::instance().endDeserialization();
 	}
 
 	void PrefabDiff::applyDiff(const SPtr<PrefabObjectDiff>& diff, const HSceneObject& object)
@@ -56,7 +58,7 @@ namespace BansheeEngine
 		const Vector<HComponent>& components = object->getComponents();
 		for (auto& removedId : diff->removedComponents)
 		{
-			for (auto& component : components)
+			for (auto component : components)
 			{
 				if (removedId == component->getLinkId())
 				{
@@ -66,9 +68,9 @@ namespace BansheeEngine
 			}
 		}
 
-		UINT32 childCount = object->getNumChildren();
 		for (auto& removedId : diff->removedChildren)
 		{
+			UINT32 childCount = object->getNumChildren();
 			for (UINT32 i = 0; i < childCount; i++)
 			{
 				HSceneObject child = object->getChild(i);
@@ -92,6 +94,7 @@ namespace BansheeEngine
 			BinarySerializer bs;
 			SPtr<SceneObject> sceneObject = std::static_pointer_cast<SceneObject>(bs._decodeIntermediate(addedChildData));
 			sceneObject->setParent(object);
+			sceneObject->instantiate();
 		}
 
 		for (auto& componentDiff : diff->componentDiffs)
@@ -109,6 +112,7 @@ namespace BansheeEngine
 
 		for (auto& childDiff : diff->childDiffs)
 		{
+			UINT32 childCount = object->getNumChildren();
 			for (UINT32 i = 0; i < childCount; i++)
 			{
 				HSceneObject child = object->getChild(i);
@@ -269,7 +273,7 @@ namespace BansheeEngine
 			bool foundMatching = false;
 			if (instanceComponent->getLinkId() != -1)
 			{
-				for (UINT32 j = 0; j < prefabChildCount; j++)
+				for (UINT32 j = 0; j < prefabComponentCount; j++)
 				{
 					HComponent prefabComponent = prefabComponents[j];
 
@@ -289,7 +293,7 @@ namespace BansheeEngine
 				if (output == nullptr)
 					output = bs_shared_ptr<PrefabObjectDiff>();
 
-				output->addedChildren.push_back(obj);
+				output->addedComponents.push_back(obj);
 			}
 		}
 

+ 1 - 1
BansheeCore/Source/BsSceneObject.cpp

@@ -539,7 +539,7 @@ namespace BansheeEngine
 		return HComponent();
 	}
 
-	void SceneObject::destroyComponent(const HComponent& component, bool immediate)
+	void SceneObject::destroyComponent(const HComponent component, bool immediate)
 	{
 		if(component == nullptr)
 		{

+ 1 - 1
BansheeEditor/Source/BsEditorTestSuite.cpp

@@ -585,7 +585,7 @@ namespace BansheeEngine
 		HSceneObject so1_3, so2_1, so3;
 		{
 			cmp0->obj.strA = "banana";
-			so1_0->destroy();
+			so0_0->destroy();
 			cmp0_1_A->destroy();
 
 			so1_3 = SceneObject::create("so1_2");

+ 2 - 2
BansheeUtility/Source/BsBinaryCloner.cpp

@@ -94,7 +94,7 @@ namespace BansheeEngine
 							}
 
 							subObjectData->children.push_back(ObjectReferenceData());
-							ObjectReferenceData childData = subObjectData->children.back();
+							ObjectReferenceData& childData = subObjectData->children.back();
 							childData.fieldId = fieldId;
 
 							gatherReferences(childObj, childData);
@@ -136,7 +136,7 @@ namespace BansheeEngine
 						}
 
 						subObjectData->children.push_back(ObjectReferenceData());
-						ObjectReferenceData childData = subObjectData->children.back();
+						ObjectReferenceData& childData = subObjectData->children.back();
 						childData.fieldId = fieldId;
 
 						gatherReferences(childObj, childData);

+ 3 - 1
BansheeUtility/Source/BsSerializedObject.cpp

@@ -36,7 +36,9 @@ namespace BansheeEngine
 			for (auto& entryPair : subObject.entries)
 			{
 				SerializedEntry entry = entryPair.second;
-				entry.serialized = entry.serialized->clone(cloneData);
+
+				if (entry.serialized != nullptr)
+					entry.serialized = entry.serialized->clone(cloneData);
 
 				copy->subObjects[i].entries[entryPair.first] = entry;
 			}