Node* Node::CloneRecursive(Node* parent, SceneResolver& resolver, CreateMode mode) { // Create clone node Node* cloneNode = parent->CreateChild(0, (mode == REPLICATED && id_ < FIRST_LOCAL_ID) ? REPLICATED : LOCAL); resolver.AddNode(id_, cloneNode); // Copy attributes const Vector<AttributeInfo>* attributes = GetAttributes(); for (unsigned j = 0; j < attributes->Size(); ++j) { const AttributeInfo& attr = attributes->At(j); // Do not copy network-only attributes, as they may have unintended side effects if (attr.mode_ & AM_FILE) cloneNode->SetAttribute(j, GetAttribute(j)); } // Clone components for (Vector<SharedPtr<Component> >::ConstIterator i = components_.Begin(); i != components_.End(); ++i) { Component* component = *i; Component* cloneComponent = cloneNode->SafeCreateComponent(component->GetTypeName(), component->GetType(), (mode == REPLICATED && component->GetID() < FIRST_LOCAL_ID) ? REPLICATED : LOCAL, 0); if (!cloneComponent) { LOGERROR("Could not clone component " + component->GetTypeName()); continue; } resolver.AddComponent(component->GetID(), cloneComponent); const Vector<AttributeInfo>* compAttributes = component->GetAttributes(); if (compAttributes) { for (unsigned j = 0; j < compAttributes->Size(); ++j) { const AttributeInfo& attr = compAttributes->At(j); if (attr.mode_ & AM_FILE) cloneComponent->SetAttribute(j, component->GetAttribute(j)); } } } // Clone child nodes recursively for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i) { Node* node = *i; node->CloneRecursive(cloneNode, resolver, mode); } return cloneNode; }
Node* Node::CloneRecursive(Node* parent, SceneResolver& resolver, CreateMode mode) { // Create clone node Node* cloneNode = parent->CreateChild(0, (mode == REPLICATED && id_ < FIRST_LOCAL_ID) ? REPLICATED : LOCAL); resolver.AddNode(id_, cloneNode); // Copy attributes unsigned numAttributes = GetNumAttributes(); for (unsigned j = 0; j < numAttributes; ++j) cloneNode->SetAttribute(j, GetAttribute(j)); // Clone components for (Vector<SharedPtr<Component> >::ConstIterator i = components_.Begin(); i != components_.End(); ++i) { Component* component = *i; Component* cloneComponent = cloneNode->CreateComponent(component->GetType(), (mode == REPLICATED && component->GetID() < FIRST_LOCAL_ID) ? REPLICATED : LOCAL); if (!cloneComponent) { LOGERROR("Could not clone component " + component->GetTypeName()); continue; } resolver.AddComponent(component->GetID(), cloneComponent); numAttributes = component->GetNumAttributes(); for (unsigned j = 0; j < numAttributes; ++j) cloneComponent->SetAttribute(j, component->GetAttribute(j)); } // Clone child nodes recursively for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i) { Node* node = *i; node->CloneRecursive(cloneNode, resolver, mode); } return cloneNode; }