void Node::SetParent(Node* parent) { if(parent != nullptr) { if(parent->FindChildNode(mName, false) == nullptr) { // we are not already a child of the new parent if(mParent != nullptr) { // Remove it from its original parent. auto iter = mParent->mChildren.find(mName); parent->mChildren.insert(mName, mParent->mChildren.release(iter).release()); mParent = parent; } else { parent->AddChildNode(this); } return; } } /* if(mParent != parent && mParent != nullptr) { // new parent mParent->RemoveChildNode(mName); } */ mParent = parent; // the absolute position might have changed! _UpdateAllComponents(0); }
ComponentType* AddComponent(ComponentType* component) { const QString& cname = component->GetName(); if(!HasComponent(cname)) { std::shared_ptr<Component> ptr(component); ptr->SetNode(this); ptr->Initialize(); std::pair<QString, std::shared_ptr<Component> > pair(cname, ptr); mComponents.insert(pair); if(!mIsEnabled) component->Disable(); _UpdateAllComponents(0); } else { Logger::Get().Error("Cannot add component " + cname + ": a component with this name already exists."); } return FindComponent<ComponentType>(cname); }
void Node::SetParent(Node* parent) { if(parent != nullptr) { if(parent->FindChildNode(mName, false) == nullptr) { // we are not already a child of the new parent parent->AddChildNode(this); return; } } /* if(mParent != parent && mParent != nullptr) { // new parent mParent->RemoveChildNode(mName); } */ mParent = parent; // the absolute position might have changed! _UpdateAllComponents(0); }
void Node::OnUpdate(double time_diff) { if(mIsEnabled) { _UpdateAllChildren(time_diff); _UpdateAllComponents(time_diff); } }