From 5c730a63695da5e3e29954c69c6241511838cfe4 Mon Sep 17 00:00:00 2001 From: sara Date: Tue, 23 Jan 2024 19:13:02 +0100 Subject: [PATCH] refactor done --- include/Component.h | 17 ++++++++++++++--- include/Entity.h | 3 +-- include/TransformComponent.h | 2 +- src/Entity.cpp | 26 -------------------------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/include/Component.h b/include/Component.h index 095b370..a798dc8 100644 --- a/include/Component.h +++ b/include/Component.h @@ -7,9 +7,20 @@ class Component public: Entity* entity; - virtual void init() {} - virtual void update() {} - virtual void draw() {} + virtual void init() + { + // implementation in derived classes (when neccessary) + } + + virtual void update() + { + // implementation in derived classes (when neccessary) + } + + virtual void draw() + { + // implementation in derived classes (when neccessary) + } virtual ~Component() = default; }; \ No newline at end of file diff --git a/include/Entity.h b/include/Entity.h index a85a80f..9244252 100644 --- a/include/Entity.h +++ b/include/Entity.h @@ -8,7 +8,6 @@ #include "ECS.h" class Manager; -//class Component; using ComponentBitSet = std::bitset; using GroupBitSet = std::bitset; @@ -59,7 +58,7 @@ private: bool active = true; std::vector> components; - ComponentArray componentArray; + ComponentArray componentArray = {}; ComponentBitSet componentBitSet; GroupBitSet groupBitSet; }; \ No newline at end of file diff --git a/include/TransformComponent.h b/include/TransformComponent.h index 9404277..4d9b077 100644 --- a/include/TransformComponent.h +++ b/include/TransformComponent.h @@ -16,7 +16,7 @@ public: int speed = 3; TransformComponent(); - TransformComponent(int scale); + explicit TransformComponent(int scale); TransformComponent(float x, float y); TransformComponent(float x, float y, int scale); TransformComponent(float x, float y, int w, int h, int scale); diff --git a/src/Entity.cpp b/src/Entity.cpp index 799445e..5f199ea 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -2,7 +2,6 @@ #include "Entity.h" #include "Manager.h" #include "Component.h" -//#include "ECS.h" void Entity::update() const { @@ -29,28 +28,3 @@ void Entity::delGroup(Group mGroup) { groupBitSet[mGroup] = false; } - -//template bool Entity::hasComponent() const -//{ -// return componentBitSet[getComponentTypeID()]; -//} - -//template T& Entity::addComponent(TArgs&&...mArgs) -//{ -// T* c(new T(std::forward(mArgs)...)); -// c->entity = this; -// std::unique_ptr uPtr{ c }; -// this->components.emplace_back(std::move(uPtr)); -// -// componentArray[getComponentTypeID()] = c; -// componentBitSet[getComponentTypeID()] = true; -// -// c->init(); -// return *c; -//}; - -//template T& Entity::getComponent() const -//{ -// auto ptr(componentArray[getComponentTypeID()]); -// return *static_cast(ptr); -//} \ No newline at end of file