Browse Source

Added owner connection pointer to Node for multiplayer.

Lasse Öörni 14 years ago
parent
commit
5bde56d248
3 changed files with 33 additions and 17 deletions
  1. 16 10
      Engine/Scene/Node.cpp
  2. 12 6
      Engine/Scene/Node.h
  3. 5 1
      Engine/Scene/Scene.cpp

+ 16 - 10
Engine/Scene/Node.cpp

@@ -42,6 +42,7 @@ Node::Node(Context* context) :
     id_(0),
     parent_(0),
     scene_(0),
+    owner_(0),
     position_(Vector3::ZERO),
     rotation_(Quaternion::IDENTITY),
     scale_(Vector3::UNITY),
@@ -599,6 +600,21 @@ Component* Node::GetComponent(ShortStringHash type, unsigned index) const
     return 0;
 }
 
+void Node::SetID(unsigned id)
+{
+    id_ = id;
+}
+
+void Node::SetScene(Scene* scene)
+{
+    scene_ = scene;
+}
+
+void Node::SetOwner(Connection* owner)
+{
+    owner_ = owner;
+}
+
 bool Node::Load(Deserializer& source, bool readChildren)
 {
     // Remove all children and components first in case this is not a fresh load
@@ -760,13 +776,3 @@ void Node::GetChildrenWithComponentRecursive(std::vector<Node*>& dest, ShortStri
             node->GetChildrenRecursive(dest);
     }
 }
-
-void Node::SetID(unsigned id)
-{
-    id_ = id;
-}
-
-void Node::SetScene(Scene* scene)
-{
-    scene_ = scene;
-}

+ 12 - 6
Engine/Scene/Node.h

@@ -29,6 +29,7 @@
 #include <vector>
 
 class Component;
+class Connection;
 class Scene;
 
 /// Scene node that may contain components and child nodes
@@ -36,8 +37,6 @@ class Node : public Serializable
 {
     OBJECT(Node);
     
-    friend class Scene;
-    
 public:
     /// Construct
     Node(Context* context);
@@ -136,6 +135,8 @@ public:
     Node* GetParent() const { return parent_; }
     /// Return scene
     Scene* GetScene() const { return scene_; }
+    /// Return owner connection in multiplayer
+    Connection* GetOwner() const { return owner_; }
     /// Return position
     const Vector3& GetPosition() const { return position_; }
     /// Return rotation
@@ -233,6 +234,13 @@ public:
     /// Template version of checking whether has a specific component
     template <class T> bool HasComponent() const;
     
+    /// Set ID. Called by Scene
+    void SetID(unsigned id);
+    /// Set scene. Called by Scene
+    void SetScene(Scene* scene);
+    /// Set owner connection for multiplayer
+    void SetOwner(Connection* owner);
+    
     /// User variables
     VariantMap vars_;
     
@@ -255,10 +263,6 @@ private:
     void GetChildrenRecursive(std::vector<Node*>& dest) const;
     /// Return child nodes with a specific component recursively
     void GetChildrenWithComponentRecursive(std::vector<Node*>& dest, ShortStringHash type) const;
-    /// Set ID. Called by Scene
-    void SetID(unsigned id);
-    /// Set scene. Called by Scene
-    void SetScene(Scene* scene);
     
     /// Unique ID within the scene
     unsigned id_;
@@ -266,6 +270,8 @@ private:
     Node* parent_;
     /// Scene (root node)
     Scene* scene_;
+    /// Owner connection in multiplayer
+    Connection* owner_;
     /// Position
     Vector3 position_;
     /// Rotation

+ 5 - 1
Engine/Scene/Scene.cpp

@@ -57,9 +57,12 @@ Scene::Scene(Context* context) :
 
 Scene::~Scene()
 {
-    // Remove scene reference from all nodes that still exist
+    // Remove scene reference and owner from all nodes that still exist
     for (std::map<unsigned, Node*>::iterator i = allNodes_.begin(); i != allNodes_.end(); ++i)
+    {
         i->second->SetScene(0);
+        i->second->SetOwner(0);
+    }
 }
 
 void Scene::RegisterObject(Context* context)
@@ -356,6 +359,7 @@ void Scene::NodeAdded(Node* node)
     {
         LOGWARNING("Overwriting node with ID " + ToString(id));
         i->second->SetScene(0);
+        i->second->SetOwner(0);
     }
     
     allNodes_[id] = node;