diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-14 11:15:35 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-14 11:15:35 +0200 |
commit | 3a132996f798dbf552ac858b06fa656b6790a501 (patch) | |
tree | 050396efcc609d5234414f15d52b6f4c123e6f80 /src/game-server/entity.h | |
parent | ff7041ab8d0c176a7c9764656c21177944f52c31 (diff) | |
download | manaserv-3a132996f798dbf552ac858b06fa656b6790a501.tar.gz manaserv-3a132996f798dbf552ac858b06fa656b6790a501.tar.bz2 manaserv-3a132996f798dbf552ac858b06fa656b6790a501.tar.xz manaserv-3a132996f798dbf552ac858b06fa656b6790a501.zip |
Use a full user data for Entity references
Only moved a single script function to a member for now, will do others
in a separate commit.
Diffstat (limited to 'src/game-server/entity.h')
-rw-r--r-- | src/game-server/entity.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/game-server/entity.h b/src/game-server/entity.h index 81faa941..2f360df6 100644 --- a/src/game-server/entity.h +++ b/src/game-server/entity.h @@ -44,7 +44,7 @@ class MapComposite; class Entity : public sigc::trackable { public: - Entity(EntityType type, MapComposite *map = 0); + Entity(EntityType type, MapComposite *map = nullptr); virtual ~Entity(); @@ -52,8 +52,7 @@ class Entity : public sigc::trackable template <class T> void addComponent(T *component); template <class T> T *getComponent() const; - - Component *getComponent(ComponentType type) const; + template <class T> bool hasComponent() const; bool isVisible() const; bool canMove() const; @@ -69,6 +68,8 @@ class Entity : public sigc::trackable sigc::signal<void, Entity *> signal_map_changed; private: + Component *getComponent(ComponentType type) const; + MapComposite *mMap; /**< Map the entity is on */ EntityType mType; /**< Type of this entity. */ @@ -101,7 +102,6 @@ inline void Entity::addComponent(T *component) */ inline Component *Entity::getComponent(ComponentType type) const { - assert(mComponents[type]); return mComponents[type]; } @@ -112,7 +112,18 @@ inline Component *Entity::getComponent(ComponentType type) const template <class T> inline T *Entity::getComponent() const { - return static_cast<T*>(getComponent(T::type)); + T *component = static_cast<T*>(getComponent(T::type)); + assert(component); + return component; +} + +/** + * Returns whether this class has a certain component. + */ +template <class T> +inline bool Entity::hasComponent() const +{ + return getComponent(T::type) != nullptr; } /** |