Entity header
#include "Common.h"
#include "Components.h"
class EntityManager;
typedef std::tuple<
CTransform,
CLifeSpan,
CInput,
CBoundingBox,
CAnimation,
CState,
CFollowPlayer,
CPatrol,
CDamage,
CHealth,
CInvincibility,
COwner
> ComponentTuple;
class Entity
{
friend class EntityManager;
bool m_active = true;
std::string m_tag = "default";
size_t m_id = 0;
ComponentTuple m_components;
// constructor is private so we can never create
// entities outside the EntityManager which had friend access
Entity(const size_t & id, const std::string & tag);
Components header
#pragma once
#include "Animation.h"
#include "Assets.h"
class Component
{
public:
bool has = false;
};
class COwner : public Component
{
public:
std::shared_ptr<void> owner = nullptr;
COwner() {}
COwner(const std::shared_ptr<void>& o)
:owner(o) {}
};
class CTransform : public Component
{
public:
Vec2 pos = { 0.0, 0.0 };
Vec2 prevPos = { 0.0, 0.0 };
Vec2 scale = { 1.0, 1.0 };
Vec2 velocity = { 0.0, 0.0 };
Vec2 facing = { 0.0, 1.0 };
float angle = 0;
CTransform() {}
CTransform(const Vec2& p)
: pos(p) {}
CTransform(const Vec2& p, const Vec2& sp, const Vec2& sc, float a)
: pos(p), prevPos(p), velocity(sp), scale(sc), angle(a) {}
};
// ALL OTHER COMPONENTS BELOW...
The focus is on COwner. I would like COwner to hold a shared_ptr to an Entity. But after adding shared_ptr I get an error because now Entity needs Components.h and Components.h needs Entity.h . I tried to get around this by using shared_ptr but I have no success on using that to access the class that the pointer points to use its functions .
is there anyway to solve this? If there is missing info, let me know and I will add it.
Aucun commentaire:
Enregistrer un commentaire