mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 10:13:42 +00:00
refactor done
This commit is contained in:
parent
5d4512133c
commit
5c730a6369
@ -7,9 +7,20 @@ class Component
|
|||||||
public:
|
public:
|
||||||
Entity* entity;
|
Entity* entity;
|
||||||
|
|
||||||
virtual void init() {}
|
virtual void init()
|
||||||
virtual void update() {}
|
{
|
||||||
virtual void draw() {}
|
// 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;
|
virtual ~Component() = default;
|
||||||
};
|
};
|
||||||
@ -8,7 +8,6 @@
|
|||||||
#include "ECS.h"
|
#include "ECS.h"
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
//class Component;
|
|
||||||
|
|
||||||
using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
|
using ComponentBitSet = std::bitset<MAX_COMPONENTS>;
|
||||||
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
using GroupBitSet = std::bitset<MAX_GROUPS>;
|
||||||
@ -59,7 +58,7 @@ private:
|
|||||||
bool active = true;
|
bool active = true;
|
||||||
std::vector<std::unique_ptr<Component>> components;
|
std::vector<std::unique_ptr<Component>> components;
|
||||||
|
|
||||||
ComponentArray componentArray;
|
ComponentArray componentArray = {};
|
||||||
ComponentBitSet componentBitSet;
|
ComponentBitSet componentBitSet;
|
||||||
GroupBitSet groupBitSet;
|
GroupBitSet groupBitSet;
|
||||||
};
|
};
|
||||||
@ -16,7 +16,7 @@ public:
|
|||||||
int speed = 3;
|
int speed = 3;
|
||||||
|
|
||||||
TransformComponent();
|
TransformComponent();
|
||||||
TransformComponent(int scale);
|
explicit TransformComponent(int scale);
|
||||||
TransformComponent(float x, float y);
|
TransformComponent(float x, float y);
|
||||||
TransformComponent(float x, float y, int scale);
|
TransformComponent(float x, float y, int scale);
|
||||||
TransformComponent(float x, float y, int w, int h, int scale);
|
TransformComponent(float x, float y, int w, int h, int scale);
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
//#include "ECS.h"
|
|
||||||
|
|
||||||
void Entity::update() const
|
void Entity::update() const
|
||||||
{
|
{
|
||||||
@ -29,28 +28,3 @@ void Entity::delGroup(Group mGroup)
|
|||||||
{
|
{
|
||||||
groupBitSet[mGroup] = false;
|
groupBitSet[mGroup] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//template <typename T> bool Entity::hasComponent() const
|
|
||||||
//{
|
|
||||||
// return componentBitSet[getComponentTypeID<T>()];
|
|
||||||
//}
|
|
||||||
|
|
||||||
//template <typename T, typename...TArgs> T& Entity::addComponent(TArgs&&...mArgs)
|
|
||||||
//{
|
|
||||||
// T* c(new T(std::forward<TArgs>(mArgs)...));
|
|
||||||
// c->entity = this;
|
|
||||||
// std::unique_ptr<Component> uPtr{ c };
|
|
||||||
// this->components.emplace_back(std::move(uPtr));
|
|
||||||
//
|
|
||||||
// componentArray[getComponentTypeID<T>()] = c;
|
|
||||||
// componentBitSet[getComponentTypeID<T>()] = true;
|
|
||||||
//
|
|
||||||
// c->init();
|
|
||||||
// return *c;
|
|
||||||
//};
|
|
||||||
|
|
||||||
//template <typename T> T& Entity::getComponent() const
|
|
||||||
//{
|
|
||||||
// auto ptr(componentArray[getComponentTypeID<T>()]);
|
|
||||||
// return *static_cast<T*>(ptr);
|
|
||||||
//}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user