This article is on wikipedia says that we can change the behavior of the game entity by adding or removing the component at runtime how it goes
i don't know.
What i am doing is, I have a gameObject class which is having four components
class gameObject
{
public:
#define MAX_COMPONENT 4
unsigned int components[MAX_COMPONENT];
gameObject()
{
for(int i=0;i<MAX_COMPONENT;i++)
{
components=0;
}
//parent_id=-1;
}
};
i don't use inheritance, Whenever i make the new game entity i add an gameObject in the gameObjectManger class using the game entities constructor
with all of its components filled at the time of game entity creation like index for rigid body , mesh and etc.
Then i use these gameObjects at individual systems to run the game like below
// For renderer
for(unsigned int i=0;i<manager->gameObjects.size();i++)
{
unsigned int meshIndex = manager->gameObjects.components[MY_MESH]; //mesh data
mat4 trans=(*transforms)[bodyIndex];// The transformation matrix extracted and spitted out by the the Physics engine
mesh_Entries[meshIndex].init();
GLuint lMM = glGetUniformLocation(programHandle,"Model");
glUniformMatrix4fv(lMM, 1, GL_FALSE,&trans[0][0]);
mesh_Entries[meshIndex].bindTexture();
glBindBuffer(GL_ARRAY_BUFFER, mesh_Entries[meshIndex].getVertexBuffer());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh_Entries[meshIndex].getIndexBuffer());
pickColor=vec4(1.0f);
pickScale=mat4(1.0f);
lMM = glGetUniformLocation(programHandle,"pick");
glUniform4fv(lMM,1,&pickColor[0]);
lMM = glGetUniformLocation(programHandle,"pickScale");
glUniformMatrix4fv(lMM,1,GL_FALSE,&pickScale[0][0]);
// This is very basic rendering since all object's indices are treated as
// indexed based. Stored in element buffer with indices and vbo with vertices
// for each single gameObject having their own VAO and IO. Optimization need to be done later on.
glDrawElements(
GL_TRIANGLES, // mode
mesh_Entries[meshIndex].getIndicesSize(), // count
GL_UNSIGNED_SHORT, // type
(void*)0 // element array buffer offset
);
}
but i am not getting it how to add a new component like LogicalData to the gameObject not about how to point from gameObject but how to build one
is this should be my approach
struct LogicalData
{
float running_speed;
vec3 seek_position;
vec3 attack_point;
};
Character : public CharacterController
{
private:
gameObject* me;
public:
// methods to manipulate gameObject content using the component id for each component in their container
// i.e is to update component[LOGICAL_DATA] in the gameLogicContainer
};
and then a global container which hold this logical data and every entity has a id to it using gameobjects
or i should not be doing this at all. i can just put all logical data into the any game entity like this and push the physics and rendering data back to gameobject
Character : public CharacterController
{
private:
float running_speed;
vec3 seek_position;
vec3 attack_point;
public:
// methods to manipulate above
};
Any comments will be greatly appreciated.