#include "BsManagedDiff.h" #include "BsManagedSerializableDiff.h" #include "BsBinarySerializer.h" #include "BsMemorySerializer.h" #include "BsManagedSerializableObject.h" #include "BsGameObjectManager.h" #include "BsRTTIType.h" namespace BansheeEngine { SPtr ManagedDiff::generateDiff(const SPtr& orgSerzObj, const SPtr& newSerzObj, ObjectMap& objectMap) { BinarySerializer bs; // Need to call GameObjectManager because GameObject handles call it during deserialization, but we don't really need it GameObjectManager::instance().startDeserialization(); SPtr orgObj = std::static_pointer_cast(bs._decodeIntermediate(orgSerzObj)); SPtr newObj = std::static_pointer_cast(bs._decodeIntermediate(newSerzObj)); GameObjectManager::instance().endDeserialization(); ManagedSerializableDiffPtr diff = ManagedSerializableDiff::create(orgObj, newObj); if (diff == nullptr) return nullptr; SPtr output = bs_shared_ptr_new(); output->subObjects.push_back(SerializedSubObject()); SerializedSubObject& subObject = output->subObjects.back(); subObject.typeId = ManagedSerializableObject::getRTTIStatic()->getRTTIId(); SerializedEntry entry; entry.fieldId = 0; entry.serialized = bs._encodeIntermediate(diff.get()); subObject.entries[0] = entry; return output; } void ManagedDiff::applyDiff(const SPtr& object, const SPtr& serzDiff, DiffObjectMap& objectMap, Vector& diffCommands) { SPtr diffObj = std::static_pointer_cast(serzDiff->subObjects[0].entries[0].serialized); BinarySerializer bs; ManagedSerializableDiffPtr diff = std::static_pointer_cast(bs._decodeIntermediate(diffObj)); if (diff != nullptr) { SPtr managedObj = std::static_pointer_cast(object); diff->apply(managedObj); } } }