diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-20 21:28:00 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2018-05-20 21:28:00 +0100 |
commit | d849aae7a61c4c945230c6af051e8c9d5a071380 (patch) | |
tree | aad0b48821f11dd49fe6a2be67d016f9e5f5443c /yage/entity/entity.cpp | |
parent | 97448eb557d23138e6a460f496d981ced56b59c9 (diff) | |
download | YAGE-d849aae7a61c4c945230c6af051e8c9d5a071380.tar.gz YAGE-d849aae7a61c4c945230c6af051e8c9d5a071380.zip |
Component pool now in entities
Diffstat (limited to 'yage/entity/entity.cpp')
-rw-r--r-- | yage/entity/entity.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/yage/entity/entity.cpp b/yage/entity/entity.cpp new file mode 100644 index 00000000..c7e8fd50 --- /dev/null +++ b/yage/entity/entity.cpp @@ -0,0 +1,41 @@ +/** --------------------------------------------------------------------------- + * @file: entity.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "entity.h" + +#include <algorithm> + +namespace yage +{ + +BaseComponent::Group BaseComponent::group_id_counter_ = 0; + +EntityManager::EntityManager(Space *space) : space_(space) {} + +EntityManager::EntityManager(Space *space, std::size_t n) : space_(space) +{ + entities_.reserve(n); +} + +Entity EntityManager::createEntity() +{ + Entity entity = next_entity_++; + entities_.push_back(entity); + return entity; +} + +void EntityManager::deleteEntity(Entity entity) +{ + auto index = std::find_if(entities_.begin(), entities_.end(), + [&](Entity &value) { return value == entity; }); + if (index != entities_.end()) { + entities_.erase(index); + } +} + +} // namespace yage |