Ejemplo n.º 1
0
        /// <summary>
        /// Creates a scene graph node with the specified node name.
        /// </summary>
        /// <param name="name">The name of this node</param>
        public Node(String name)
        {
            this.name = name;
            id = State.GetNextNodeID();
            groupID = 0;
            enabled = true;

            parent = null;

            scene = null;
            userData = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clones this scene node without its children
        /// </summary>
        /// <returns>A cloned node</returns>
        public virtual Node CloneNode() 
        {
            Node node = new Node();
            node.Name = this.Name + node.ID;
            node.GroupID = this.GroupID;
            node.Enabled = this.Enabled;

            return node;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Disposes this node.
 /// </summary>
 public virtual void Dispose()
 {
     parent = null;
     scene = null;
 }
Ejemplo n.º 4
0
 protected void PropagateSceneGraph(Node node)
 {
     node.SceneGraph = node.Parent.SceneGraph;
     if(node is BranchNode)
         foreach (Node child in ((BranchNode)node).Children)
             PropagateSceneGraph(child);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Check whether this node is part of a cyclic graph
 /// </summary>
 /// <param name="node"></param>
 protected void CheckForLoops(Node node)
 {
     Node predecessor = this;
     while (predecessor.Parent != null)
     {
         predecessor = predecessor.Parent;
         if (predecessor == node)
             throw new GoblinException("Not allowed to create cyclic scene graph");
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Removes a child from this node.
        /// </summary>
        /// <param name="node">The child to be removed</param>
        public virtual void RemoveChild(Node node)
        {
            if (!children.Contains(node))
                return;

            node.Parent = null;
            node.SceneGraph = null;
            if(node is BranchNode)
                foreach (Node child in ((BranchNode)node).Children)
                    PropagateSceneGraph(child);

            // at this time, still don't remove the node from children to guarantee thread-safe operation
            // will be actually removed during processing the scene graph in Scene class
            NodeChangeInfo info = new NodeChangeInfo();
            info.Node = node;
            info.Type = ChangeType.Remove;
            changeList.Add(info);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a child to this node.
        /// </summary>
        /// <param name="node">The child node to be added</param>
        public virtual void AddChild(Node node)
        {
            if (node.Parent != null)
                throw new GoblinException(node.Name + " already has a parent");
            if (children.Contains(node))
                throw new GoblinException("This child is already added to this node");
            if (node == this)
                throw new GoblinException("You cannot add a node to itself");
            if (node.Parent == this)
                throw new GoblinException(Name + " already has " + node.Name + " as child");

            CheckForLoops(node);

            if (scene != null && scene.IsStarted)
            {
                // at this time, still don't add the node to children to guarantee thread-safe operation
                // will be actually added during processing the scene graph in Scene class
                NodeChangeInfo info = new NodeChangeInfo();
                info.Node = node;
                info.Type = ChangeType.Add;
                changeList.Add(info);
            }
            // if the scene hasn't started processing the tree yet, then it's safe to add now
            else
                children.Add(node);
            
            node.Parent = this;
            PropagateSceneGraph(node);
        }
Ejemplo n.º 8
0
        public override void AddChild(Node node)
        {
            base.AddChild(node);

            if (SwitchID < 0)
                SwitchID = 0;
        }