diff options
Diffstat (limited to 'yage/entity/component.h')
-rw-r--r-- | yage/entity/component.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/yage/entity/component.h b/yage/entity/component.h new file mode 100644 index 00000000..a21409ff --- /dev/null +++ b/yage/entity/component.h @@ -0,0 +1,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 |