فهرست منبع

Added a function for components to list the nodes they depend on.

Lasse Öörni 14 سال پیش
والد
کامیت
bddedd7fd2
7فایلهای تغییر یافته به همراه41 افزوده شده و 15 حذف شده
  1. 8 13
      Engine/Network/Connection.cpp
  2. 2 2
      Engine/Network/Connection.h
  3. 9 0
      Engine/Physics/Joint.cpp
  4. 2 0
      Engine/Physics/Joint.h
  5. 2 0
      Engine/Scene/Component.h
  6. 16 0
      Engine/Scene/Node.cpp
  7. 2 0
      Engine/Scene/Node.h

+ 8 - 13
Engine/Network/Connection.cpp

@@ -244,24 +244,19 @@ String Connection::ToString() const
 
 void Connection::ProcessNode(Node* node)
 {
-    unsigned nodeID = node->GetID();
-    if (processedNodes_.Contains(nodeID))
+    if (!node || processedNodes_.Contains(node))
         return;
     
-    processedNodes_.Insert(nodeID);
+    processedNodes_.Insert(node);
     
-    // Process parent node first
-    Node* parent = node->GetParent();
-    if (parent)
-    {
-        // If parent is local, proceed to first non-local node in hierarchy
-        while (parent->GetID() >= FIRST_LOCAL_ID)
-            parent = parent->GetParent();
-        ProcessNode(parent);
-    }
+    // Process depended upon nodes first
+    PODVector<Node*> depends;
+    node->GetDependencyNodes(depends);
+    for (PODVector<Node*>::ConstIterator i = depends.Begin(); i != depends.End(); ++i)
+        ProcessNode(*i);
     
     // Check if the client's scene state already has this node
-    if (sceneState_.Find(nodeID) != sceneState_.End())
+    if (sceneState_.Find(node->GetID()) != sceneState_.End())
         ProcessExistingNode(node);
     else
         ProcessNewNode(node);

+ 2 - 2
Engine/Network/Connection.h

@@ -129,8 +129,8 @@ private:
     PODVector<unsigned char> deltaUpdateBits_;
     /// Internal set for node's variable map changes
     HashSet<ShortStringHash> changedVars_;
-    /// Internal set for processed node ID's during an update
-    HashSet<unsigned> processedNodes_;
+    /// Internal set for already processed nodes during an update
+    HashSet<Node*> processedNodes_;
     /// Reused message buffer
     VectorBuffer msg_;
     /// Current controls

+ 9 - 0
Engine/Physics/Joint.cpp

@@ -101,6 +101,14 @@ void Joint::FinishUpdate()
     }
 }
 
+void Joint::GetDependencyNodes(PODVector<Node*>& dest)
+{
+    if (bodyA_ && bodyA_->GetNode())
+        dest.Push(bodyA_->GetNode());
+    if (bodyB_ && bodyB_->GetNode())
+        dest.Push(bodyB_->GetNode());
+}
+
 void Joint::Clear()
 {
     if (joint_)
@@ -200,6 +208,7 @@ void Joint::SetAxis(Vector3 axis)
         
         switch (type)
         {
+        case dJointTypeHinge:
             dJointSetHingeAxis(joint_, axis.x_, axis.y_, axis.z_);
             break;
         }

+ 2 - 0
Engine/Physics/Joint.h

@@ -55,6 +55,8 @@ public:
     virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& value);
     /// Perform finalization after a scene load or network update
     virtual void FinishUpdate();
+    /// Return the depended on nodes to order network updates
+    virtual void GetDependencyNodes(PODVector<Node*>& dest);
     
     /// Remove the joint
     void Clear();

+ 2 - 0
Engine/Scene/Component.h

@@ -45,6 +45,8 @@ public:
     virtual void OnNodeSet(Node* node) {};
     /// Handle scene node transform dirtied
     virtual void OnMarkedDirty(Node* node) {};
+    /// Return the depended on nodes to order network updates
+    virtual void GetDependencyNodes(PODVector<Node*>& dest) {};
     
     /// Remove from the scene node. If no other shared pointer references exist, causes immediate deletion
     void Remove();

+ 16 - 0
Engine/Scene/Node.cpp

@@ -590,6 +590,22 @@ Component* Node::GetComponent(ShortStringHash type, unsigned index) const
     return 0;
 }
 
+void Node::GetDependencyNodes(PODVector<Node*>& dest) const
+{
+    // Add the parent node, but if it is local, traverse to the first non-local node
+    if (parent_ && parent_ != scene_)
+    {
+        Node* current = parent_;
+        while (current->id_ >= FIRST_LOCAL_ID)
+            current = current->parent_;
+        dest.Push(current);
+    }
+    
+    // Then let the components add their dependencies
+    for (Vector<SharedPtr<Component> >::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
+        (*i)->GetDependencyNodes(dest);
+}
+
 void Node::SetID(unsigned id)
 {
     id_ = id;

+ 2 - 0
Engine/Scene/Node.h

@@ -223,6 +223,8 @@ public:
     const Vector<WeakPtr<Component> > GetListeners() const { return listeners_; }
     /// Return user variables
     VariantMap& GetVars() { return vars_; }
+    /// Return the depended on nodes to order network updates
+    void GetDependencyNodes(PODVector<Node*>& dest) const;
     /// Template version of returning child nodes with a specific component
     template <class T> void GetChildrenWithComponent(PODVector<Node*>& dest, bool recursive = false) const;
     /// Template version of returning a component by type