|
@@ -19,9 +19,20 @@ const uint32_t MAX_COMPONENTS = 32;
|
|
|
|
|
|
typedef std::bitset<MAX_COMPONENTS> Signature;
|
|
|
|
|
|
-class Component
|
|
|
+struct IComponent
|
|
|
{
|
|
|
+protected:
|
|
|
+ static uint32_t nextId;
|
|
|
+};
|
|
|
|
|
|
+template <typename T> class Component: public IComponent
|
|
|
+{
|
|
|
+public:
|
|
|
+ static uint32_t getId()
|
|
|
+ {
|
|
|
+ static auto id = IComponent::nextId++;
|
|
|
+ return id;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
class Entity
|
|
@@ -44,12 +55,20 @@ public:
|
|
|
System() = default;
|
|
|
~System() = default;
|
|
|
|
|
|
- void addEntity(Entity entity);
|
|
|
- void removeEntity(Entity entity);
|
|
|
- std::vector<Entity> getEntities() const;
|
|
|
- Signature& getComponentSignature() const;
|
|
|
+ void addEntity(Entity entity);
|
|
|
+ void removeEntity(Entity entity);
|
|
|
+ std::vector<Entity> getEntities() const;
|
|
|
+ const Signature& getComponentSignature() const;
|
|
|
+
|
|
|
+ template<typename T> void requireComponent();
|
|
|
};
|
|
|
|
|
|
+template<typename T> void System::requireComponent()
|
|
|
+{
|
|
|
+ const auto componentId = Component<T>::getId();
|
|
|
+ this->componentSignature.set(componentId);
|
|
|
+}
|
|
|
+
|
|
|
class Registry
|
|
|
{
|
|
|
|