-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathentity.hpp
More file actions
86 lines (85 loc) · 3.8 KB
/
entity.hpp
File metadata and controls
86 lines (85 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include <fea/config.hpp>
#include <fea/entity/entitymanager.hpp>
namespace fea
{
class FEA_API Entity
{
public:
Entity(EntityId id, EntityManager& entityManager);
template<class DataType>
const DataType& getAttribute(const std::string& attribute) const;
template<class DataType>
DataType& getAttribute(const std::string& attribute);
template<class DataType>
void setAttribute(const std::string& attribute, DataType value) const;
bool hasAttribute(const std::string& attribute) const;
EntityId getId() const;
std::unordered_set<std::string> getAttributes() const;
private:
EntityId mId;
EntityManager& mEntityManager;
};
#include <fea/entity/entity.inl>
/** @addtogroup EntitySystem
*@{
* @class Entity
*@}
***
* @class Entity
* @brief Represents a single game entity.
*
* A game entity is no more than a collection of attributes, associated with the same entity ID. An attribute is a named value of any type. An example of an attribute would be an int named "health points" storing the value 23. An entity may have an arbitrary amount of attributes and every entity has a unique entity ID.
*
* Although usage may vary and is not restricted, the entities are meant to be used for ingame objects that need to store data. These could include the player, enemies, pickups, bullets, and so on.
***
* @fn Entity::Entity(EntityId i, EntityManager& m)
* @brief Construct an Entity.
*
* This sets the EntityId to the supplied ID. The entity stores the EntityManager reference internally for using when getting and setting attributes.
*
* Observe that entities aren't mean to be created manually, but using the EntityManager::CreateEntity function.
* @param i ID of the new entity.
* @param m EntityManager that the entity will use.
***
* @fn const DataType& Entity::getAttribute(const std::string& attribute) const
* @brief Get the value of an attribute of the entity.
*
* Assert/undefined behavior when the attribute does not exist or the wrong template argument is provided.
* @tparam Type of the attribute to get.
* @param attribute Name of the attribute to get.
* @return Attribute value.
***
* @fn DataType& Entity::getAttribute(const std::string& attribute)
* @brief Get the value of an attribute of the entity.
*
* Assert/undefined behavior when the attribute does not exist or the wrong template argument is provided.
* @tparam Type of the attribute to get.
* @param attribute Name of the attribute to get.
* @return Attribute value.
***
* @fn void Entity::setAttribute(const std::string& attribute, DataType value) const
* @brief Set the value of an attribute of the entity.
*
* Assert/undefined behavior when the attribute does not exist or the wrong template argument is provided.
* @tparam Type of the attribute to set.
* @param attribute Name of the attribute to set.
* @param value Value to set the attribute to.
***
* @fn bool Entity::hasAttribute(const std::string& attribute) const
* @brief Check if the entity has an attribute.
*
* @param attribute Name of the attribute to check.
* @return True if the attribute exists.
***
* @fn EntityId Entity::getId() const
* @brief Get the ID of an entity.
* @return The ID.
***
* @fn std::unordered_set<std::string> Entity::getAttributes() const
* @brief Get a set containing all the attributes of the entity.
*
* Assert/undefined behavior if the entity does not exist.
* @return Set with attributes.
***/
}