aboutsummaryrefslogtreecommitdiffstats
path: root/yage/entity/entity.cpp
blob: c7e8fd509e21d5c9b94bce43688a75633b526775 (plain)
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
/** ---------------------------------------------------------------------------
 * @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