Browse Source

Remove pushFront argument from Node::GetOrCreateComponent, fix issue #579, because it is important than issue #569, I think this function can rename to Node::RequireComponent.

aster2013 11 years ago
parent
commit
700673f556

+ 2 - 2
Source/Engine/LuaScript/pkgs/Scene/Node.pkg

@@ -108,8 +108,8 @@ class Node : public Animatable
     
     // template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
     Component* CreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0);
-    // template <class T> T* GetOrCreateComponent(CreateMode mode = REPLICATED, unsigned id = 0, bool pushFront = false);
-    Component* GetOrCreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0, bool pushFront = false);
+    // template <class T> T* GetOrCreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
+    Component* GetOrCreateComponent(const String type, CreateMode mode = REPLICATED, unsigned id = 0);
     Component* CloneComponent(Component* component, unsigned id = 0);
     Component* CloneComponent(Component* component, CreateMode mode, unsigned id = 0);
 

+ 1 - 1
Source/Engine/Physics/CollisionShape.cpp

@@ -871,7 +871,7 @@ void CollisionShape::OnNodeSet(Node* node)
             if (scene == node)
                 LOGWARNING(GetTypeName() + " should not be created to the root scene node");
 
-            physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld>(REPLICATED, 0, true);
+            physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld>();
             physicsWorld_->AddCollisionShape(this);
         }
         else

+ 1 - 1
Source/Engine/Physics/Constraint.cpp

@@ -448,7 +448,7 @@ void Constraint::OnNodeSet(Node* node)
             if (scene == node)
                 LOGWARNING(GetTypeName() + " should not be created to the root scene node");
 
-            physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld>(REPLICATED, 0, true);
+            physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld>();
             physicsWorld_->AddConstraint(this);
         }
         else

+ 1 - 1
Source/Engine/Physics/RigidBody.cpp

@@ -917,7 +917,7 @@ void RigidBody::OnNodeSet(Node* node)
             if (scene == node)
                 LOGWARNING(GetTypeName() + " should not be created to the root scene node");
 
-            physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld>(REPLICATED, 0, true);
+            physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld>();
             physicsWorld_->AddRigidBody(this);
 
             AddBodyToWorld();

+ 2 - 10
Source/Engine/Scene/Node.cpp

@@ -694,21 +694,13 @@ Component* Node::CreateComponent(StringHash type, CreateMode mode, unsigned id)
     return newComponent;
 }
 
-Component* Node::GetOrCreateComponent(StringHash type, CreateMode mode, unsigned id, bool pushFront)
+Component* Node::GetOrCreateComponent(StringHash type, CreateMode mode, unsigned id)
 {
     Component* oldComponent = GetComponent(type);
     if (oldComponent)
         return oldComponent;
     else
-    {
-        SharedPtr<Component> newComponent(CreateComponent(type, mode, id));
-        if (pushFront)
-        {
-            components_.Remove(newComponent);
-            components_.Insert(0, newComponent);
-        }
-        return newComponent;
-    }
+        return CreateComponent(type, mode, id);
 }
 
 Component* Node::CloneComponent(Component* component, unsigned id)

+ 3 - 3
Source/Engine/Scene/Node.h

@@ -203,7 +203,7 @@ public:
     /// Create a component to this node (with specified ID if provided).
     Component* CreateComponent(StringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
     /// Create a component to this node if it does not exist already.
-    Component* GetOrCreateComponent(StringHash type, CreateMode mode = REPLICATED, unsigned id = 0, bool pushFront = false);
+    Component* GetOrCreateComponent(StringHash type, CreateMode mode = REPLICATED, unsigned id = 0);
     /// Clone a component from another node using its create mode. Return the clone if successful or null on failure.
     Component* CloneComponent(Component* component, unsigned id = 0);
     /// Clone a component from another node and specify the create mode. Return the clone if successful or null on failure.
@@ -231,7 +231,7 @@ public:
     /// Template version of creating a component.
     template <class T> T* CreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
     /// Template version of getting or creating a component.
-    template <class T> T* GetOrCreateComponent(CreateMode mode = REPLICATED, unsigned id = 0, bool pushFront = false);
+    template <class T> T* GetOrCreateComponent(CreateMode mode = REPLICATED, unsigned id = 0);
     /// Template version of removing a component.
     template <class T> void RemoveComponent();
 
@@ -540,7 +540,7 @@ private:
 };
 
 template <class T> T* Node::CreateComponent(CreateMode mode, unsigned id) { return static_cast<T*>(CreateComponent(T::GetTypeStatic(), mode, id)); }
-template <class T> T* Node::GetOrCreateComponent(CreateMode mode, unsigned id, bool pushFront) { return static_cast<T*>(GetOrCreateComponent(T::GetTypeStatic(), mode, id, pushFront)); }
+template <class T> T* Node::GetOrCreateComponent(CreateMode mode, unsigned id) { return static_cast<T*>(GetOrCreateComponent(T::GetTypeStatic(), mode, id)); }
 template <class T> void Node::RemoveComponent() { RemoveComponent(T::GetTypeStatic()); }
 template <class T> void Node::GetChildrenWithComponent(PODVector<Node*>& dest, bool recursive) const { GetChildrenWithComponent(dest, T::GetTypeStatic(), recursive); }
 template <class T> T* Node::GetComponent() const { return static_cast<T*>(GetComponent(T::GetTypeStatic())); }

+ 3 - 3
Source/Engine/Script/APITemplates.h

@@ -477,9 +477,9 @@ static Component* NodeCreateComponent(const String& typeName, CreateMode mode, u
     return ptr->CreateComponent(typeName, mode, id);
 }
 
-static Component* NodeGetOrCreateComponent(const String& typeName, CreateMode mode, unsigned id, bool pushFront, Node* ptr)
+static Component* NodeGetOrCreateComponent(const String& typeName, CreateMode mode, unsigned id, Node* ptr)
 {
-    return ptr->GetOrCreateComponent(typeName, mode, id, pushFront);
+    return ptr->GetOrCreateComponent(typeName, mode, id);
 }
 
 static void NodeRemoveComponent(const String& typeName, Node* ptr)
@@ -635,7 +635,7 @@ template <class T> void RegisterNode(asIScriptEngine* engine, const char* classN
     engine->RegisterObjectMethod(className, "void RemoveChildren(bool, bool, bool)", asMETHOD(T, RemoveChildren), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void Remove()", asMETHOD(T, Remove), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Component@+ CreateComponent(const String&in, CreateMode mode = REPLICATED, uint id = 0)", asFUNCTION(NodeCreateComponent), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod(className, "Component@+ GetOrCreateComponent(const String&in, CreateMode mode = REPLICATED, uint id = 0, bool pushFront = false)", asFUNCTION(NodeGetOrCreateComponent), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod(className, "Component@+ GetOrCreateComponent(const String&in, CreateMode mode = REPLICATED, uint id = 0)", asFUNCTION(NodeGetOrCreateComponent), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "Component@+ CloneComponent(Component@+, uint id = 0)", asMETHODPR(T, CloneComponent, (Component*, unsigned), Component*), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Component@+ CloneComponent(Component@+, CreateMode, uint id = 0)", asMETHODPR(T, CloneComponent, (Component*, CreateMode, unsigned), Component*), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveComponent(Component@+)", asMETHODPR(T, RemoveComponent, (Component*), void), asCALL_THISCALL);

+ 1 - 1
Source/Engine/Script/ScriptInstance.cpp

@@ -639,7 +639,7 @@ void ScriptInstance::UpdateEventSubscription()
 #ifdef URHO3D_PHYSICS
             if (methods_[METHOD_FIXEDUPDATE] || methods_[METHOD_FIXEDPOSTUPDATE])
             {
-                PhysicsWorld* world = scene->GetOrCreateComponent<PhysicsWorld>(REPLICATED, 0, true);
+                PhysicsWorld* world = scene->GetOrCreateComponent<PhysicsWorld>();
                 if (world)
                 {
                     if (methods_[METHOD_FIXEDUPDATE])

+ 1 - 1
Source/Engine/Urho2D/Constraint2D.cpp

@@ -127,7 +127,7 @@ void Constraint2D::OnNodeSet(Node* node)
     if (node)
     {
         Scene* scene = GetScene();
-        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>(REPLICATED, 0, true);
+        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
 
         ownerBody_ = node->GetComponent<RigidBody2D>();
         if (!ownerBody_)

+ 1 - 1
Source/Engine/Urho2D/Drawable2D.cpp

@@ -182,7 +182,7 @@ void Drawable2D::OnNodeSet(Node* node)
         Scene* scene = GetScene();
         if (scene)
         {
-            renderer_ = scene->GetOrCreateComponent<Renderer2D>(REPLICATED, 0, true);
+            renderer_ = scene->GetOrCreateComponent<Renderer2D>();
             if (IsEnabledEffective())
                 renderer_->AddDrawable(this);
         }

+ 1 - 1
Source/Engine/Urho2D/RigidBody2D.cpp

@@ -478,7 +478,7 @@ void RigidBody2D::OnNodeSet(Node* node)
     {
         node->AddListener(this);
         Scene* scene = GetScene();
-        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>(REPLICATED, 0, true);
+        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
 
         CreateBody();
         physicsWorld_->AddRigidBody(this);