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 "EntityComponent.h" 00022 00023 // Forward declarations 00024 class EntityComponent; 00025 00026 00027 // Entity class 00029 class Entity : public sigslot::has_slots<> 00030 { 00031 public: 00032 00033 // Initialisation and deinitialisation 00037 Entity(const std::string &name, Entity *parent = NULL); 00039 ~Entity(); 00040 00041 // AngelScript binding 00044 static Entity* refFactory(const std::string &name); 00047 void refAdd(); 00050 void refRelease(); 00051 00052 // Methods 00054 u32 getID() const; 00056 const std::string& getName() const; 00057 00061 bool addComponent(EntityComponent *component); 00062 00065 Entity* getChild(const u32 id); 00068 Entity* getChild(const std::string &name); 00071 EntityComponent* getComponent(const u32 id); 00074 EntityComponent* getComponent(const std::string &name); 00075 00078 Entity *getParent() const; 00079 00081 const vector3df& getPosition() const; 00082 00084 void removeAllChildren(); 00086 void removeAllComponents(); 00090 bool removeChild(Entity *entity); 00094 bool removeChild(const u32 id); 00098 bool removeChild(const std::string &name); 00102 bool removeComponent(EntityComponent *component); 00106 bool removeComponent(const u32 id); 00110 bool removeComponent(const std::string &name); 00111 00114 void setPosition(const vector3df &position); 00115 00116 // Events 00119 void onPositionChange(void *p); 00122 void onUpdate(void *p); 00125 void onRender(void *p); 00128 void onPause(void *p); 00131 void onUnPause(void *p); 00132 00133 private: 00134 00135 // Private methods 00136 bool addChild(Entity *entity); 00137 00138 // Static members 00139 static u32 mIDCount; 00140 00141 // Angelscript members 00142 s32 mRefCount; 00143 00144 // Normal members 00145 Entity *pParent; 00146 00147 u32 mID; 00148 std::string mName; 00149 00150 vector3df mPosition; 00151 00152 vector<Entity*> mChildren; 00153 vector<EntityComponent*> mComponents; 00154 }; 00155 00156 00157 // Entity Angelscript binding. 00159 extern void bindEntity(asIScriptEngine *engine); 00160 00161 #endif