I'm trying to make ECS (Entity-Component-System) in C++ right now.
Here is my GameObject class :
class GameObject
{
private:
int ID
/*gameobject name, tranform */
public:
int GetID();
template<class component>
void AddComponent()
{
component::ComponentAdded(this->ID);
}
template<class component>
component& GetComponent()
{
return component(); //todo :: think about how to access
}
};
and here is Meshrenderer(one of my components) :
struct MeshRenderer
{
MeshRenderer();
static std::vector<Mesh> meshes;
static std::vector<Material> materials;
static std::unordered_map<int, std::pair< int , int>> renderables; // gameobjectID, <mesh, material>
static void ComponentAdded(int gameObjectID);
static void SetMesh(int gameObjectID, Mesh& mesh);
static void SetMaterial(int gameObjectID, Material& material);
};
I'm trying to fix getcomponent :
scene->gameObjects[2]->GetComponent<MeshRenderer>().SetMesh(scene->gameObjects[2]->GetID(), object);
to :
scene->gameObjects[2]->GetComponent<MeshRenderer>().SetMesh(object);
but I don't know how to automatically give gameObject's ID when calling certain components function.
I would appreciate if you give me any advice.