From d849aae7a61c4c945230c6af051e8c9d5a071380 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 20 May 2018 21:28:00 +0100 Subject: Component pool now in entities --- yage/entity/entity.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 yage/entity/entity.cpp (limited to 'yage/entity/entity.cpp') 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 + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "entity.h" + +#include + +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 -- cgit