00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __ENTITYCOMPONENT_H__
00017 #define __ENTITYCOMPONENT_H__
00018
00019
00020 #include "../dependencies.h"
00021 #include "Entity.h"
00022 #include "../scripting/ScriptManager.h"
00023
00024
00025 class Entity;
00026
00027
00028
00030 class EntityComponent : public sigslot::has_slots<>
00031 {
00032 public:
00033
00034
00037 EntityComponent(Entity *parent);
00039 virtual ~EntityComponent();
00040
00041
00044 static EntityComponent* refFactory(Entity *parent);
00047 void refAdd();
00050 void refRelease();
00051
00052
00054 u32 getID() const;
00055
00057 const std::string& getName() const;
00059 const Entity* getParent();
00060
00062 void setName(const std::string &name);
00063
00064 protected:
00065
00066
00067 Entity *pParent;
00068
00069 u32 mID;
00070 std::string mName;
00071
00072 private:
00073
00074
00075 static u32 mIDCount;
00076
00077
00078 s32 mRefCount;
00079 };
00080
00081
00082
00084 extern void bindEntityComponent(asIScriptEngine *engine);
00085
00088 template<typename T>
00089 void bindEntityComponentBase(asIScriptEngine *engine, const char *type)
00090 {
00091
00092 int r;
00093 std::string sType = type;
00094
00095
00096 r = engine->RegisterObjectBehaviour(type, asBEHAVE_ADDREF, "void f()",
00097 asMETHOD(T, refAdd), asCALL_THISCALL); assert(r >= 0);
00098 r = engine->RegisterObjectBehaviour(type, asBEHAVE_RELEASE, "void f()",
00099 asMETHOD(T, refRelease), asCALL_THISCALL); assert(r >= 0);
00100
00101 r = engine->RegisterGlobalBehaviour(asBEHAVE_REF_CAST, std::string(sType + "@ f(EntityComponent @)").c_str(),
00102 asFUNCTION((asRefCast<EntityComponent,T>)), asCALL_CDECL); assert( r >= 0 );
00103 r = engine->RegisterGlobalBehaviour(asBEHAVE_IMPLICIT_REF_CAST, std::string("EntityComponent@ f(" + sType +" @)").c_str(),
00104 asFUNCTION((asRefCast<T,EntityComponent>)), asCALL_CDECL); assert( r >= 0 );
00105
00106
00107 r = engine->RegisterObjectMethod(type, "u32 getID()",
00108 asMETHOD(T, getID), asCALL_THISCALL); assert(r >= 0);
00109
00110 r = engine->RegisterObjectMethod(type, "void setName(const string &)",
00111 asMETHOD(T, setName), asCALL_THISCALL); assert(r >= 0);
00112 r = engine->RegisterObjectMethod(type, "const string& getName()",
00113 asMETHOD(T, getName), asCALL_THISCALL); assert(r >= 0);
00114
00115 r = engine->RegisterObjectMethod(type, "Entity@ getParent()",
00116 asMETHOD(T, getParent), asCALL_THISCALL); assert(r >= 0);
00117 }
00118 #endif