aboutsummaryrefslogtreecommitdiffstats
path: root/yage/entity/component.h
blob: a21409ff60ce8be81931cae3735ac26c66380593 (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
#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
{
    GroupId getGroup() override;
};

class ComponentGroup
{
public:
    std::vector<std::unique_ptr<BaseComponent>> components_;
};

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

} // namespace yage