21 #ifndef OPHIDIAN_SRC_ENTITY_SYSTEM_ENTITY_SYSTEM_H
22 #define OPHIDIAN_SRC_ENTITY_SYSTEM_ENTITY_SYSTEM_H
26 #include <unordered_set>
30 namespace entity_system{
32 using entities_storage =
typename std::vector<entity>;
33 using entities_index_storage =
typename std::vector<entity_index>;
41 entities_storage m_entities;
42 entities_index_storage m_id_to_index;
44 std::unordered_set<property *> m_associated_properties;
47 std::size_t m_last_prealloc_qnt;
49 inline void m_live_entity_check(entity_index e_index)
const {
50 if(e_index == invalid_entity_index)
51 throw std::out_of_range(
"lookup::_invalid_entity");
69 entity_system(std::size_t qnt) : m_entities(qnt), m_id_to_index(qnt), m_next(0), m_last_prealloc_qnt(0){
82 std::size_t
size()
const {
return m_entities.size(); }
89 bool empty()
const {
return m_entities.empty(); }
97 entities_storage::const_iterator
begin()
const {
return m_entities.begin(); }
104 entities_storage::const_iterator
end()
const {
return m_entities.end(); }
111 const entities_storage &
entities()
const {
return m_entities; }
149 inline entity_index
lookup(entity e)
const {
150 entity_index e_index = m_id_to_index.at(e);
151 m_live_entity_check(e_index);
159 #endif //OPHIDIAN_SRC_ENTITY_SYSTEM_ENTITY_SYSTEM_H
entity_system(std::size_t qnt)
Constructor.
Definition: entity_system.h:69
void preallocate(std::size_t qnt)
Preallocate method.
Definition: entity_system.cpp:53
bool empty() const
Returns if the system is empty.
Definition: entity_system.h:89
const entities_storage & entities() const
Entities getter.
Definition: entity_system.h:111
entity_system()
Constructor.
Definition: entity_system.h:60
entities_storage::const_iterator begin() const
Begin iterator.
Definition: entity_system.h:97
void destroy(entity e)
Destroy an entity.
Definition: entity_system.cpp:27
entity create()
Creates an entity.
Definition: entity_system.cpp:42
Property class.
Definition: property.h:33
entity_system class.
Definition: entity_system.h:40
entities_storage::const_iterator end() const
End iterator.
Definition: entity_system.h:104
std::size_t size() const
Returns the size of the system.
Definition: entity_system.h:82
entity_index lookup(entity e) const
Gets the index of an entity.
Definition: entity_system.h:149
void register_property(property *property)
Registers property.
Definition: entity_system.cpp:61