#ifndef ENGINE_INCLUDE_ECS_H_ #define ENGINE_INCLUDE_ECS_H_ #include #include #include #include #include #include #include namespace engine { class Scene; using Entity = uint32_t; // ECS entity constexpr size_t kMaxComponents = 10; class IComponentArray { public: virtual ~IComponentArray() = default; }; template class ComponentArray : public IComponentArray { public: void InsertData(Entity entity, const T& component) { if (component_array_.size() < entity + 1) { component_array_.resize(entity + 1); } // bounds checking here as not performance critical component_array_.at(entity) = component; } void DeleteData(Entity entity) { (void)entity; // TODO } T* GetData(Entity entity) { assert(entity < component_array_.size()); return &component_array_[entity]; } private: std::vector component_array_{}; }; class System { public: System(Scene* scene, std::set required_component_hashes); virtual ~System() {} System(const System&) = delete; System& operator=(const System&) = delete; virtual void OnUpdate(float ts) = 0; virtual void OnComponentInsert(Entity) {} virtual void OnComponentRemove(Entity) {} Scene* const scene_; std::bitset signature_; // entities that contain the needed components std::set entities_{}; }; } // namespace engine #endif