aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-06-22 00:08:12 +0100
committerYann Herklotz <ymherklotz@gmail.com>2018-06-22 00:08:12 +0100
commit3702e753a5f7b31c31261c968757e19e808a84ec (patch)
tree2cbfdab552025af7a8772069b9f9935f9c9f387f
parentf4b6f813db1721421cadaf906c2763546e0190b4 (diff)
downloadYAGE-3702e753a5f7b31c31261c968757e19e808a84ec.tar.gz
YAGE-3702e753a5f7b31c31261c968757e19e808a84ec.zip
Adding components implementation
-rw-r--r--yage/entity/component.cpp10
-rw-r--r--yage/entity/component.h36
2 files changed, 39 insertions, 7 deletions
diff --git a/yage/entity/component.cpp b/yage/entity/component.cpp
index 83fe4424..eba2ad0a 100644
--- a/yage/entity/component.cpp
+++ b/yage/entity/component.cpp
@@ -1,6 +1,8 @@
#include "component.h"
-GroupId BaseComponent::getGroup() {
- static GroupId group_id = group_id_counter_++;
- return group_id;
-}
+namespace yage
+{
+
+GroupId BaseComponent::group_id_counter_ = 0;
+
+} // namespace yage
diff --git a/yage/entity/component.h b/yage/entity/component.h
index 84eb8b54..a21409ff 100644
--- a/yage/entity/component.h
+++ b/yage/entity/component.h
@@ -1,17 +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:
- GroupId getGroup();
+ virtual GroupId getGroup() = 0;
+ static GroupId group_id_counter_;
private:
friend class EntityManager;
-
- static GroupId group_id_counter_;
};
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