4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
37 #include "SG_Spatial.h"
40 typedef std::vector<SG_Node*> NodeList;
45 class SG_Node : public SG_Spatial
51 SG_Callbacks& callbacks
62 * Add a child to this object. This also informs the child of
64 * This just stores a pointer to the child and does not
74 * Remove a child node from this object. This just removes the child
75 * pointer from the list of children - it does not destroy the child.
76 * This does not inform the child that this node is no longer it's parent.
77 * If the node was not a child of this object no action is performed.
86 * Return true if the node is the ancessor of child
93 * Get the current list of children. Do not use this interface for
94 * adding or removing children please use the methods of this class for
96 * @return a reference to the list of children of this node.
99 NodeList& GetSGChildren()
101 return this->m_children;
105 * Get the current list of children.
106 * @return a const reference to the current list of children of this node.
109 const NodeList& GetSGChildren() const
111 return this->m_children;
115 * Clear the list of children associated with this node
118 void ClearSGChildren()
124 * return the parent of this node if it exists.
127 SG_Node* GetSGParent() const
133 * Set the parent of this node.
136 void SetSGParent(SG_Node* parent)
142 * Return the top node in this node's Scene graph hierarchy
151 * Disconnect this node from it's parent
155 DisconnectFromParent(
159 * Return vertex parent status.
161 bool IsVertexParent()
163 if (m_parent_relation)
165 return m_parent_relation->IsVertexRelation();
172 * Return slow parent status.
177 if (m_parent_relation)
179 return m_parent_relation->IsSlowRelation();
188 * Update the spatial data of this node. Iterate through
189 * the children of this node and update their world data.
195 bool parentUpdated=false
199 * Update the simulation time of this node. Iterate through
200 * the children nodes and update their simulated time.
210 * Schedule this node for update by placing it in head queue
212 bool Schedule(SG_QList& head)
214 // Put top parent in front of list to make sure they are updated before their
215 // children => the children will be udpated and removed from the list before
216 // we get to them, should they be in the list too.
217 return (m_SGparent)?head.AddBack(this):head.AddFront(this);
221 * Used during Scenegraph update
223 static SG_Node* GetNextScheduled(SG_QList& head)
225 return static_cast<SG_Node*>(head.Remove());
229 * Make this node ready for schedule on next update. This is needed for nodes
230 * that must always be updated (slow parent, bone parent)
232 bool Reschedule(SG_QList& head)
234 return head.QAddBack(this);
238 * Used during Scenegraph update
240 static SG_Node* GetNextRescheduled(SG_QList& head)
242 return static_cast<SG_Node*>(head.QRemove());
246 * Node replication functions.
265 * The list of children of this node.
270 * The parent of this node may be NULL
275 #ifdef WITH_CXX_GUARDEDALLOC
277 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_Node"); }
278 void operator delete( void *mem ) { MEM_freeN(mem); }