• Create Account

### #ActualThe King2

Posted 13 March 2013 - 04:47 AM

Hello,

I've started implement an Entitiy-System as described in the first article, using an implementation as offered in the topmost answer in the second link:

http://www.gamasutra.com/blogs/MeganFox/20101208/88590/Game_Engines_101_The_EntityComponent_Model.php

http://gamedev.stackexchange.com/questions/17746/entity-component-systems-in-c-how-do-i-discover-types-and-construct-component

Works unexepectably well on the first shot, but what bugs me is this:

class Entity {

void AttachComponent(ComponentType, argumentList, name)

...

}


That code snippet from Gamasutra shows a similar method that I implemented:

void Entity::AttachComponent(LPCSTR lpComponentType, LPCSTR lpName)
{
Component* pComponent = component::create(lpComponentType); //get component by type
m_mComponents[lpName] = pComponent; //register component from name
m_mTypeComponents[lpComponentType].push_back(pComponent); //register component from type
}


Now there is one important detail left in comparison to the Gamastura-code: The argumentList. Obviously I am going to need to pass some sort of arguments to the component on creation, be it a pointer to the render-queue or the filename of the mesh I want to render. How would I implement that?

The only thing I really can think about is to change the method to something like this:

void Entity::AttachComponent(Component& component, LPCSTR lpComponentType, LPCSTR lpName)
{
m_mComponents[lpName] = component; //register component from name
m_mTypeComponents[lpComponentType].push_back(component); //register component from type
}


and then create the component outside of the entity, using its "startup/init/whatever" method to initialize it. But I don't really think this is a good approach, is it?

The other thing I had in mind is to make an "argumentList" - object, inheriting it for every component, passing it to its "startup"-method and therefore to the AttachComponent-method, creating it before calling it. The "arguments" would therefore be data members, and each component would need to cast the passed argumentList. Would that be a better approach?

If not, what else could/should I do?

### #1The King2

Posted 13 March 2013 - 04:21 AM

Hello,

I've started implement an Entitiy-System as described in the first article, using an implementation as offered in the topmost answer in the second link:

http://www.gamasutra.com/blogs/MeganFox/20101208/88590/Game_Engines_101_The_EntityComponent_Model.php

http://gamedev.stackexchange.com/questions/17746/entity-component-systems-in-c-how-do-i-discover-types-and-construct-component

Works unexepectably well on the first shot, but what bugs me is this:

class Entity {

void AttachComponent(ComponentType, argumentList, name)

...

}


That code snippet from Gamasutra shows a similar method that I implemented:

void Entity::AttachComponent(LPCSTR lpComponentType, LPCSTR lpName)
{
Component* pComponent = component::create(lpComponentType); //get component by type
m_mComponents[lpName] = pComponent; //register component from name
m_mTypeComponents[lpComponentType].push_back(pComponent); //register component from type
}


Now there is one important detail left in comparison to the Gamastura-code: The argumentList. Obviously I am going to need to pass some sort of arguments to the component on creation, be it a pointer to the render-queue or the filename of the mesh I want to render. How would I implement that?

The only thing I really can think about is to change the method to something like this:

void Entity::AttachComponent(Component& component, LPCSTR lpComponentType, LPCSTR lpName)
{
m_mComponents[lpName] = component; //register component from name
m_mTypeComponents[lpComponentType].push_back(component); //register component from type
}


and then create the component outside of the entity, using its "startup/init/whatever" method to initialize it. But I don't really think this is a good approach, is it?

The other thing I had in mind is to make an "argumentList" - object, inheriting it for every component, passing it to its "startup"-method and therefore to the AttachComponent-method, creating it before calling it. Would that be a better approach?

If not, what else could/should I do?

PARTNERS