aboutsummaryrefslogtreecommitdiffstats
path: root/yage/entity/component.h
blob: 3f2b3a8167c94ad758f03e9876aaa08088478e69 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once

#include <bitset>
#include <memory>
#include <vector>

namespace yage
{

/**
 * The component mask represents all the components that the entity is
 * currently attached to.
 */
typedef std::bitset<64> ComponentMask;

typedef unsigned int GroupId;

class BaseComponent
{
protected:
    virtual GroupId getGroup() = 0;
    static GroupId group_id_counter_;

private:
    friend class EntityManager;
};

template <typename T>
class Component : public BaseComponent
{
private:
    GroupId getGroup() override;
};

class ComponentGroup
{
public:
    typedef std::vector<std::unique_ptr<BaseComponent>> Container;

    ComponentGroup &add(std::unique_ptr<BaseComponent> &&component);
    Container::iterator begin();
    Container::iterator end();

private:
    Container components_;
};

template <typename T>
GroupId Component<T>::getGroup()
{
    static GroupId group_id = group_id_counter_++;
    return group_id;
}

} // namespace yage