Преглед изворни кода

Slight optimization of skeleton reset.

Lasse Öörni пре 15 година
родитељ
комит
f345ef3776
4 измењених фајлова са 47 додато и 38 уклоњено
  1. 1 1
      Engine/Audio/Song.h
  2. 8 1
      Engine/Renderer/Skeleton.cpp
  3. 32 22
      Engine/Scene/Node.cpp
  4. 6 14
      Engine/Scene/Node.h

+ 1 - 1
Engine/Audio/Song.h

@@ -32,7 +32,7 @@
 class Audio;
 class Channel;
 
-//! Base class for sound resources
+//! Base class for tracked format song resources
 class Song : public Resource
 {
 public:

+ 8 - 1
Engine/Renderer/Skeleton.cpp

@@ -176,8 +176,15 @@ void Skeleton::define(const std::vector<SharedPtr<Bone > >& srcBones)
 
 void Skeleton::reset(bool force)
 {
+    // Start with resetting the root bone so that node dirtying is done most efficiently
+    if (mRootBone)
+        mRootBone->reset(force);
+    // Then reset the rest of the bones
     for (std::vector<SharedPtr<Bone> >::iterator i = mBones.begin(); i != mBones.end(); ++i)
-        (*i)->reset(force);
+    {
+        if ((*i) != mRootBone)
+            (*i)->reset(force);
+    }
 }
 
 Bone* Skeleton::getBone(unsigned index) const

+ 32 - 22
Engine/Scene/Node.cpp

@@ -312,6 +312,7 @@ void Node::interpolate(bool snapToEnd)
             mScale = mInterpolationScale;
         mInterpolationFlags = INTERP_NONE;
     }
+    
     markDirty();
 }
 
@@ -565,6 +566,15 @@ Node* Node::getChild(StringHash nameHash, bool recursive) const
     return 0;
 }
 
+void Node::markDirty()
+{
+    mDirty = true;
+    onMarkedDirty();
+    
+    for (std::vector<SharedPtr<Node> >::iterator i = mChildren.begin(); i != mChildren.end(); ++i)
+        (*i)->markDirty();
+}
+
 void Node::getNetTransform(Vector3& position, Quaternion& rotation, Vector3& scale, ComponentRef& parentRef, const NetUpdateInfo& info)
 {
     // Use the parent node only if it will be synced
@@ -586,14 +596,26 @@ void Node::getNetTransform(Vector3& position, Quaternion& rotation, Vector3& sca
     }
 }
 
-void Node::getChildrenRecursive(unsigned nodeFlags, std::vector<Node*>& dest) const
+void Node::updateWorldPosition()
 {
-    for (std::vector<SharedPtr<Node> >::const_iterator i = mChildren.begin(); i != mChildren.end(); ++i)
+    if (mParent)
     {
-        if ((*i)->mNodeFlags & nodeFlags)
-            dest.push_back(*i);
-        (*i)->getChildrenRecursive(nodeFlags, dest);
+        const Quaternion& parentRotation = mParent->getWorldRotation();
+        const Vector3& parentScale = mParent->getWorldScale();
+        
+        mWorldPosition = mParent->getWorldPosition() + (parentRotation * (parentScale * mPosition));
+        mWorldRotation = parentRotation * mRotation;
+        mWorldScale = parentScale * mScale;
+    }
+    else
+    {
+        mWorldPosition = mPosition;
+        mWorldRotation = mRotation;
+        mWorldScale = mScale;
     }
+    
+    mDirty = false;
+    mWorldTransformDirty = true;
 }
 
 void Node::removeChild(std::vector<SharedPtr<Node> >::iterator i, bool setWorldTransform, bool calledFromDestructor)
@@ -610,24 +632,12 @@ void Node::removeChild(std::vector<SharedPtr<Node> >::iterator i, bool setWorldT
     mChildren.erase(i);
 }
 
-void Node::updateWorldPosition()
+void Node::getChildrenRecursive(unsigned nodeFlags, std::vector<Node*>& dest) const
 {
-    if (mParent)
-    {
-        const Quaternion& parentRotation = mParent->getWorldRotation();
-        const Vector3& parentScale = mParent->getWorldScale();
-        
-        mWorldPosition = mParent->getWorldPosition() + (parentRotation * (parentScale * mPosition));
-        mWorldRotation = parentRotation * mRotation;
-        mWorldScale = parentScale * mScale;
-    }
-    else
+    for (std::vector<SharedPtr<Node> >::const_iterator i = mChildren.begin(); i != mChildren.end(); ++i)
     {
-        mWorldPosition = mPosition;
-        mWorldRotation = mRotation;
-        mWorldScale = mScale;
+        if ((*i)->mNodeFlags & nodeFlags)
+            dest.push_back(*i);
+        (*i)->getChildrenRecursive(nodeFlags, dest);
     }
-    
-    mDirty = false;
-    mWorldTransformDirty = true;
 }

+ 6 - 14
Engine/Scene/Node.h

@@ -194,6 +194,8 @@ public:
 protected:
     //! Construct with node flags and name
     Node(unsigned flags, const std::string& name = std::string());
+    //! Mark node and child nodes to need world transform recalculation
+    void markDirty();
     //! Return transform for network replication (return world transform is parent scene node is not replicated)
     void getNetTransform(Vector3& position, Quaternion& rotation, Vector3& scale, ComponentRef& parentRef, const NetUpdateInfo& info);
     
@@ -206,16 +208,6 @@ protected:
     //! A child scene node has been removed. Perform subclass-specific operations
     virtual void onChildRemoved(Node* node) {}
     
-    //! Mark node and child node needing world transform recalculation
-    void markDirty()
-    {
-        mDirty = true;
-        onMarkedDirty();
-        
-        for (std::vector<SharedPtr<Node> >::iterator i = mChildren.begin(); i != mChildren.end(); ++i)
-            (*i)->markDirty();
-    }
-    
     //! Parent scene node
     Node* mParent;
     //! Child scene nodes
@@ -233,12 +225,12 @@ protected:
     unsigned char mInterpolationFlags;
     
 private:
-    //! Return child nodes recursively
-    void getChildrenRecursive(unsigned nodeFlags, std::vector<Node*>& dest) const;
-    //! Remove child node by iterator
-    void removeChild(std::vector<SharedPtr<Node> >::iterator i, bool setWorldTransform = false, bool calledFromDestructor = false);
     //! Recalculate the world transform
     void updateWorldPosition();
+    //! Remove child node by iterator
+    void removeChild(std::vector<SharedPtr<Node> >::iterator i, bool setWorldTransform = false, bool calledFromDestructor = false);
+    //! Return child nodes recursively
+    void getChildrenRecursive(unsigned nodeFlags, std::vector<Node*>& dest) const;
     
     //! Node flags
     unsigned mNodeFlags;