Blender  V2.59
SG_Node.h
Go to the documentation of this file.
00001 /*
00002  * $Id: SG_Node.h 35082 2011-02-22 19:30:37Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00034 #ifndef __SG_NODE_H
00035 #define __SG_NODE_H
00036 
00037 #include "SG_Spatial.h"
00038 #include <vector>
00039 
00040 typedef std::vector<SG_Node*> NodeList;
00041 
00045 class SG_Node : public SG_Spatial
00046 {
00047 public:
00048         SG_Node(
00049                 void* clientobj,
00050                 void* clientinfo,
00051                 SG_Callbacks& callbacks
00052         );
00053 
00054         SG_Node(
00055                 const SG_Node & other
00056         );
00057 
00058         virtual ~SG_Node();
00059 
00060 
00068                 void    
00069         AddChild(
00070                 SG_Node* child
00071         );
00072 
00080                 void    
00081         RemoveChild(
00082                 SG_Node* child
00083         );
00084 
00088                 bool
00089         IsAncessor(
00090                 const SG_Node* child
00091         ) const;
00099         NodeList& GetSGChildren()
00100         {
00101                 return this->m_children;
00102         }
00103 
00109         const NodeList& GetSGChildren() const
00110         {
00111                 return this->m_children;
00112         }
00113 
00118         void ClearSGChildren()
00119         {
00120                 m_children.clear();
00121         }
00122 
00127         SG_Node* GetSGParent() const 
00128         { 
00129                 return m_SGparent;
00130         }
00131 
00136         void SetSGParent(SG_Node* parent)
00137         {
00138                 m_SGparent = parent;
00139         }
00140 
00145         const 
00146                 SG_Node* 
00147         GetRootSGParent(
00148         ) const;
00149 
00154                 void                            
00155         DisconnectFromParent(
00156         );
00157 
00161         bool IsVertexParent()
00162         {
00163                 if (m_parent_relation)
00164                 {
00165                         return m_parent_relation->IsVertexRelation();
00166                 }
00167                 return false;
00168         }
00169 
00170 
00175         bool IsSlowParent()
00176         {
00177                 if (m_parent_relation)
00178                 {
00179                         return m_parent_relation->IsSlowRelation();
00180                 }
00181                 return false;
00182         }
00183 
00184 
00185 
00186 
00192                 void            
00193         UpdateWorldData(
00194                 double time,
00195                 bool parentUpdated=false
00196         );
00197 
00203                 void            
00204         SetSimulatedTime(
00205                 double time,
00206                 bool recurse
00207         );
00208 
00212         bool Schedule(SG_QList& head)
00213         {
00214                 // Put top parent in front of list to make sure they are updated before their
00215                 // children => the children will be udpated and removed from the list before
00216                 // we get to them, should they be in the list too.
00217                 return (m_SGparent)?head.AddBack(this):head.AddFront(this);
00218         }
00219 
00223         static SG_Node* GetNextScheduled(SG_QList& head)
00224         {
00225                 return static_cast<SG_Node*>(head.Remove());
00226         }
00227 
00232         bool Reschedule(SG_QList& head)
00233         {
00234                 return head.QAddBack(this);
00235         }
00236 
00240         static SG_Node* GetNextRescheduled(SG_QList& head)
00241         {
00242                 return static_cast<SG_Node*>(head.QRemove());
00243         }
00244 
00249                 SG_Node*        
00250         GetSGReplica(
00251         );
00252 
00253                 void            
00254         Destruct(
00255         );
00256         
00257 private:
00258 
00259                 void            
00260         ProcessSGReplica(
00261                 SG_Node** replica
00262         );
00263 
00267         NodeList m_children;
00268 
00272         SG_Node* m_SGparent;
00273 
00274 
00275 #ifdef WITH_CXX_GUARDEDALLOC
00276 public:
00277         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_Node"); }
00278         void operator delete( void *mem ) { MEM_freeN(mem); }
00279 #endif
00280 };
00281 
00282 #endif //__SG_NODE_H
00283