00001 // ///////////////////////////////////////////////////////////////////////////// 00002 // 00003 // Name: Entity.h 00004 // Author: Michael Bartsch (ZCCdark203) 00005 // 00006 // Desc : Declaration of the Entity class. 00007 // 00008 // License: Copyright (C) 2009 Michael Bartsch and Contributors 00009 // 00010 // This program is free software: you can redistribute it 00011 // and/or modify it under the terms of the zlib/libpng License. 00012 // See main.cpp for conditions of distribution and use. 00013 // 00014 // ///////////////////////////////////////////////////////////////////////////// 00015 00016 #ifndef __ENTITY_H__ 00017 #define __ENTITY_H__ 00018 00019 // Include files 00020 #include "../dependencies.h" 00021 #include "ReferenceCounted.h" 00022 #include "AssetGroup.h" 00023 #include "HasEvents.h" 00024 #include "EntityComponent.h" 00025 00026 // Forward declarations 00027 class EntityComponent; 00028 00029 00030 // Entity class 00042 class Entity : public sigslot::has_slots<>, public ReferenceCounted, public HasEvents 00043 { 00044 public: 00045 00046 // Initialisation and deinitialisation 00052 Entity(const std::string &name, Entity *parent = NULL, AssetGroup *group = NULL); 00054 ~Entity(); 00055 00056 // Methods 00058 u32 getID() const; 00060 const std::string& getName() const; 00061 00065 bool addChild(Entity *entity); 00069 bool addComponent(EntityComponent *component); 00070 00073 AssetGroup* getAssetGroup(); 00074 00077 Entity* getChild(const u32 id); 00080 Entity* getChild(const std::string &name); 00083 EntityComponent* getComponent(const u32 id); 00086 EntityComponent* getComponent(const std::string &name); 00087 00090 Entity *getParent() const; 00091 00093 const vector3df& getAbsolutePosition() const; 00095 const vector3df& getPosition() const; 00097 const vector3df& getAbsoluteRotation() const; 00099 const vector3df& getRotation() const; 00100 00103 bool loadXML(const std::string &fileName); 00106 bool loadXML(IXMLReader *file); 00107 00109 void removeChildren(); 00111 void removeComponents(); 00115 bool removeChild(Entity *entity); 00119 bool removeChild(const u32 id); 00123 bool removeChild(const std::string &name); 00127 bool removeComponent(EntityComponent *component); 00131 bool removeComponent(const u32 id); 00135 bool removeComponent(const std::string &name); 00137 void removeParent(); 00138 00147 void setAbsolutePosition(const vector3df &position); 00156 void setPosition(const vector3df &position); 00165 void setAbsoluteRotation(const vector3df &rotation); 00174 void setRotation(const vector3df &rotation); 00175 00178 bool setParent(Entity *parent); 00179 00180 // Events 00183 void onPositionChange(void *p); 00186 void onRotationChange(void *p); 00189 void onUpdate(void *p); 00192 void onRender(void *p); 00195 void onPause(void *p); 00198 void onUnPause(void *p); 00199 00200 private: 00201 00202 // Static members 00203 static u32 mIDCount; 00204 00205 // Normal members 00206 Entity *pParent; 00207 AssetGroup *pAssetGroup; 00208 00209 u32 mID; 00210 std::string mName; 00211 00212 vector3df mPosition; 00213 vector3df mRotation; 00214 vector3df mAbsolutePosition; // We store the absolute values too so that we don't have to 00215 vector3df mAbsoluteRotation; // recalculate these values when we need them. 00216 00217 bool mIsAddingChild; 00218 00219 vector<Entity*> mChildren; 00220 vector<EntityComponent*> mComponents; 00221 }; 00222 00223 #endif