Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members

ILevelNode.hpp

Go to the documentation of this file.
00001 // Copyright (c) 2007-2008 Tomer Nosrati
00002 // This file is part of the "NUSoftware Game Engine".
00003 // For conditions of distribution and use, see copyright notice in nge.hpp
00004 
00005 #pragma once
00006 #ifndef __I_LEVEL_NODE_H__
00007 #define __I_LEVEL_NODE_H__
00008 
00009 #include "ILevelManager.hpp"
00010 #include "ELevelNodeTypes.hpp"
00011 #include "EDebugLevelTypes.hpp"
00012 
00013 namespace nge
00014 {
00015         namespace engine
00016         {
00017 
00018                 class ILevelNode : public virtual IReferenceCounted
00019                 {
00020                 public:
00022                         ILevelNode(ILevelNode* parent, ILevelManager* lmgr, s32 id=-1)
00023                                 : Parent(parent), ID(id), LevelManager(lmgr), IsIdle(false),
00024                                 DebugDataVisible(EDL_OFF)
00025                         {
00026                                 if(Parent)
00027                                         Parent->addChild(this);
00028                         }
00029 
00030 
00032                         virtual ~ILevelNode()
00033                         {
00034                                 // delete all children
00035                                 removeChildren();
00036                         }
00037 
00038 
00040 
00053                         virtual void OnRegisterLevelNode()
00054                         {
00055                                 if(!IsIdle)
00056                                 {
00057                                         list<ILevelNode*>::Iterator it = Children.begin();
00058                                         for(; it != Children.end(); ++it)
00059                                                 (*it)->OnRegisterLevelNode();
00060                                 }
00061                         }
00062 
00063 
00064                         virtual void OnEvent(const NGEReceiver* event)
00065                         {
00066                         }
00067 
00068 
00070                         virtual void drawDebugData()
00071                         {
00072                                 list<ILevelNode*>::Iterator it = Children.begin();
00073                                 for(; it != Children.end(); ++it)
00074                                         (*it)->drawDebugData();
00075                         }
00076 
00077 
00079                         virtual void process() = 0;
00080 
00081 
00084                         virtual const c8* getName() const
00085                         {
00086                                 return Name.c_str();
00087                         }
00088 
00089 
00092                         virtual void setName(const c8* name)
00093                         {
00094                                 Name = name;
00095                         }
00096 
00097 
00099                         virtual bool isIdle() const
00100                         {
00101                                 return IsIdle;
00102                         }
00103 
00104 
00107                         virtual void setIdle(bool isIdle)
00108                         {
00109                                 IsIdle = isIdle;
00110                         }
00111 
00112 
00114                         virtual s32 getID() const
00115                         {
00116                                 return ID;
00117                         }
00118 
00119 
00121                         virtual void setID(s32 id)
00122                         {
00123                                 ID = id;
00124                         }
00125 
00126 
00129                         virtual void addChild(ILevelNode* child)
00130                         {
00131                                 if(child)
00132                                 {
00133                                         child->grab();
00134                                         child->remove(); // remove from old parent
00135                                         Children.push_back(child);
00136                                         child->Parent = this;
00137                                 }
00138                         }
00139 
00140 
00143                         virtual bool removeChild(ILevelNode* child)
00144                         {
00145                                 list<ILevelNode*>::Iterator it = Children.begin();
00146                                 for(; it != Children.end(); ++it)
00147                                         if((*it) == child)
00148                                         {
00149                                                 (*it)->Parent = 0;
00150                                                 (*it)->drop();
00151                                                 Children.erase(it);
00152                                                 return true;
00153                                         }
00154 
00155                                         return false;
00156                         }
00157 
00158 
00160                         virtual void removeChildren()
00161                         {
00162                                 list<ILevelNode*>::Iterator it = Children.begin();
00163                                 for(; it != Children.end(); ++it)
00164                                 {
00165                                         (*it)->Parent = 0;
00166                                         (*it)->drop();
00167                                 }
00168 
00169                                 Children.clear();
00170                         }
00171 
00172 
00174                         virtual void remove()
00175                         {
00176                                 if(Parent)
00177                                         Parent->removeChild(this);
00178                         }
00179 
00180 
00182                         virtual void setDebugDataVisible(E_DEBUG_LEVEL_TYPE Visible)
00183                         {
00184                                 DebugDataVisible = Visible;
00185                         }
00186 
00187 
00189                         E_DEBUG_LEVEL_TYPE isDebugDataVisible() const
00190                         {
00191                                 return DebugDataVisible;
00192                         }
00193 
00194 
00196                         list<ILevelNode*>& getChildren()
00197                         {
00198                                 return Children;
00199                         }
00200 
00201 
00203                         virtual void setParent(ILevelNode* newParent)
00204                         {
00205                                 // 'I' grab() before removing parent so parent 
00206                                 // wont remove 'me' when removed
00207                                 grab();
00208                                 remove();
00209 
00210                                 Parent = newParent;
00211 
00212                                 if(Parent)
00213                                         Parent->addChild(this);
00214 
00215                                 drop();
00216                         }
00217 
00218 
00220                         ILevelNode* getParent() const
00221                         {
00222                                 return Parent;
00223                         }
00224 
00225 
00227                         virtual E_LEVEL_NODE_TYPE getType() const
00228                         {
00229                                 return ELNT_UNKNOWN;
00230                         }
00231 
00232 
00234                         virtual ILevelNode* clone(ILevelNode* newParent=0, ILevelManager* newManager=0) 
00235                         { 
00236                                 return 0; // to be implemented by derived classes
00237                         }
00238 
00239                 protected:
00241                         void cloneMembers(ILevelNode* toCopyFrom, ILevelManager* newManager)
00242                         {
00243                                 Name = toCopyFrom->Name;                
00244                                 ID = toCopyFrom->ID;
00245                                 DebugDataVisible = toCopyFrom->DebugDataVisible;
00246                                 IsIdle = toCopyFrom->IsIdle;
00247 
00248                                 if(newManager)
00249                                         LevelManager = newManager;
00250                                 else
00251                                         LevelManager = toCopyFrom->LevelManager;
00252 
00253                                 // clone children
00254 
00255                                 list<ILevelNode*>::Iterator it = toCopyFrom->Children.begin();
00256                                 for(; it != toCopyFrom->Children.end(); ++it)
00257                                         (*it)->clone(this, newManager);
00258                         }
00259 
00260                         void processEvent(const NGEReceiver* event)
00261                         {
00262                                 if(event)
00263                                 {
00264                                         list<ILevelNode*>::Iterator it = Children.begin();
00265                                         for(; it != Children.end(); ++it)
00266                                         {
00267                                                 (*it)->OnEvent(event);
00268                                                 (*it)->processEvent(event);
00269                                         }
00270                                 }
00271                         }
00272 
00274                         stringc Name;
00275 
00277                         ILevelNode* Parent;
00278 
00280                         list<ILevelNode*> Children;
00281 
00283                         s32 ID;
00284 
00286                         ILevelManager* LevelManager;
00287 
00289                         bool IsIdle;
00290 
00292                         E_DEBUG_LEVEL_TYPE DebugDataVisible;
00293                 };
00294 
00295         } // namespace engine
00296 } // namespace nge
00297 
00298 #endif // __I_LEVEL_NODE_H__

The NUSoftware Game Engine
The NUSoftware Game Engine Documentation © 2007-2008 by Tomer Nosrati. Generated on Sat Apr 26 16:52:34 2008 by Doxygen (1.5.5)