Browse Source

Minor bug fix, refactoring and reformatting.

Yao Wei Tjong 姚伟忠 11 years ago
parent
commit
f48ef6f5bd

+ 11 - 8
Source/Engine/Core/Spline.cpp

@@ -39,24 +39,24 @@ template<> InterpolationMode Variant::Get<InterpolationMode>() const
 }
 }
 
 
 Spline::Spline() :
 Spline::Spline() :
-interpolationMode_(BEZIER_CURVE)
+    interpolationMode_(BEZIER_CURVE)
 {
 {
 }
 }
 
 
 Spline::Spline(InterpolationMode mode) :
 Spline::Spline(InterpolationMode mode) :
-interpolationMode_(mode)
+    interpolationMode_(mode)
 {
 {
 }
 }
 
 
 Spline::Spline(const Vector<Variant>& knots, InterpolationMode mode) :
 Spline::Spline(const Vector<Variant>& knots, InterpolationMode mode) :
-interpolationMode_(mode),
-knots_(knots)
+    interpolationMode_(mode),
+    knots_(knots)
 {
 {
 }
 }
 
 
 Spline::Spline(const Spline& rhs) :
 Spline::Spline(const Spline& rhs) :
-interpolationMode_(rhs.interpolationMode_),
-knots_(rhs.knots_)
+    interpolationMode_(rhs.interpolationMode_),
+    knots_(rhs.knots_)
 {
 {
 }
 }
 
 
@@ -73,8 +73,11 @@ Variant Spline::GetPoint(float f) const
     switch (interpolationMode_)
     switch (interpolationMode_)
     {
     {
     case BEZIER_CURVE:
     case BEZIER_CURVE:
-    default:
         return BezierInterpolation(knots_, f);
         return BezierInterpolation(knots_, f);
+
+    default:
+        LOGERROR("Unsupported interpolation mode");
+        return Variant::EMPTY;
     }
     }
 }
 }
 
 
@@ -173,4 +176,4 @@ Variant Spline::LinearInterpolation(const Variant& lhs, const Variant& rhs, floa
     }
     }
 }
 }
 
 
-}
+}

+ 2 - 2
Source/Engine/Core/Spline.h

@@ -77,7 +77,7 @@ public:
     /// Set the InterpolationMode of the Spline.
     /// Set the InterpolationMode of the Spline.
     void SetInterpolationMode(InterpolationMode interpolationMode) { interpolationMode_ = interpolationMode; }
     void SetInterpolationMode(InterpolationMode interpolationMode) { interpolationMode_ = interpolationMode; }
     /// Set the Knots of the Spline.
     /// Set the Knots of the Spline.
-    void SetKnots(const Vector<Variant>& knots) { knots_ = knots_; }
+    void SetKnots(const Vector<Variant>& knots) { knots_ = knots; }
     /// Set the Knot value of an existing Knot.
     /// Set the Knot value of an existing Knot.
     void SetKnot(const Variant& knot, unsigned index);
     void SetKnot(const Variant& knot, unsigned index);
     /// Add a Knot to the end of the Spline.
     /// Add a Knot to the end of the Spline.
@@ -103,4 +103,4 @@ private:
     VariantVector knots_;
     VariantVector knots_;
 };
 };
 
 
-}
+}

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

@@ -77,7 +77,7 @@ class Node : public Serializable
     
     
     Node* CreateChild(const String name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
     Node* CreateChild(const String name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
     
     
-    void AddChild(Node* node);
+    void AddChild(Node* node, unsigned index = M_MAX_UNSIGNED);
     void RemoveChild(Node* node);
     void RemoveChild(Node* node);
     void RemoveAllChildren();
     void RemoveAllChildren();
     void RemoveChildren(bool removeReplicated, bool removeLocal, bool recursive);
     void RemoveChildren(bool removeReplicated, bool removeLocal, bool recursive);

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

@@ -533,11 +533,6 @@ Node* Node::CreateChild(const String& name, CreateMode mode, unsigned id)
     return newNode;
     return newNode;
 }
 }
 
 
-void Node::AddChild(Node* node)
-{
-    AddChild(node, children_.Size());
-}
-
 void Node::AddChild(Node* node, unsigned index)
 void Node::AddChild(Node* node, unsigned index)
 {
 {
     // Check for illegal or redundant parent assignment
     // Check for illegal or redundant parent assignment
@@ -552,11 +547,6 @@ void Node::AddChild(Node* node, unsigned index)
         parent = parent->parent_;
         parent = parent->parent_;
     }
     }
 
 
-    if (index < 0)
-        index = 0;
-    if (index > children_.Size())
-        index = children_.Size();
-
     // Add first, then remove from old parent, to ensure the node does not get deleted
     // Add first, then remove from old parent, to ensure the node does not get deleted
     children_.Insert(index, SharedPtr<Node>(node));
     children_.Insert(index, SharedPtr<Node>(node));
     node->Remove();
     node->Remove();

+ 2 - 4
Source/Engine/Scene/Node.h

@@ -140,10 +140,8 @@ public:
     void MarkDirty();
     void MarkDirty();
     /// Create a child scene node (with specified ID if provided).
     /// Create a child scene node (with specified ID if provided).
     Node* CreateChild(const String& name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
     Node* CreateChild(const String& name = String::EMPTY, CreateMode mode = REPLICATED, unsigned id = 0);
-    /// Add a child scene node.
-    void AddChild(Node* node);
-    /// Add a child scene node at a specific index.
-    void AddChild(Node* node, unsigned index);
+    /// Add a child scene node at a specific index. If index is not explicitly specified or is greater than current children size, append the new child at the end.
+    void AddChild(Node* node, unsigned index = M_MAX_UNSIGNED);
     /// Remove a child scene node.
     /// Remove a child scene node.
     void RemoveChild(Node* node);
     void RemoveChild(Node* node);
     /// Remove all child scene nodes.
     /// Remove all child scene nodes.

+ 1 - 2
Source/Engine/Script/APITemplates.h

@@ -602,8 +602,7 @@ template <class T> void RegisterNode(asIScriptEngine* engine, const char* classN
     engine->RegisterObjectMethod(className, "void Scale(float)", asMETHODPR(T, Scale, (float), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void Scale(float)", asMETHODPR(T, Scale, (float), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void Scale(const Vector3&in)", asMETHODPR(T, Scale, (const Vector3&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void Scale(const Vector3&in)", asMETHODPR(T, Scale, (const Vector3&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Node@+ CreateChild(const String&in name = String(), CreateMode mode = REPLICATED, uint id = 0)", asMETHODPR(T, CreateChild, (const String&, CreateMode, unsigned), Node*), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Node@+ CreateChild(const String&in name = String(), CreateMode mode = REPLICATED, uint id = 0)", asMETHODPR(T, CreateChild, (const String&, CreateMode, unsigned), Node*), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void AddChild(Node@+)", asMETHODPR(T, AddChild, (Node*), void), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void AddChild(Node@+, uint)", asMETHODPR(T, AddChild, (Node*, unsigned), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void AddChild(Node@+, uint index = M_MAX_UNSIGNED)", asMETHOD(T, AddChild), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveChild(Node@+)", asMETHODPR(T, RemoveChild, (Node*), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveChild(Node@+)", asMETHODPR(T, RemoveChild, (Node*), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveAllChildren()", asMETHOD(T, RemoveAllChildren), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveAllChildren()", asMETHOD(T, RemoveAllChildren), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveChildren(bool, bool, bool)", asMETHOD(T, RemoveChildren), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveChildren(bool, bool, bool)", asMETHOD(T, RemoveChildren), asCALL_THISCALL);