• Create Account

## Question on Entity Component System (rendering related)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1Irlan Robson  Members

3961
Like
0Likes
Like

Posted 21 October 2013 - 07:57 AM

In my class I'm doing this:

class RenderableSystem {

public:
RenderableSystem() {
}

Run(Graphics* graphics, RenderableComponent* component)  {

graphics->DrawModel(component->model);

}

};


Don't know if I'm doing it right. Now suppose I'm creating a CameraSystem that operates on a Camera Component. I have to put another graphics pointer on the CameraSystem class? Could the ECS have acess and modify separeted classes like Graphics, Input, Timer etc. ?

Edited by irlanrobson, 21 October 2013 - 08:27 AM.

### #2wintertime  Members

3826
Like
0Likes
Like

Posted 21 October 2013 - 09:37 AM

What you have looks kinda like a hollow shell. The system in an ECS is supposed to update all components of a type for one call, not a single one.

Btw., Run is kinda suggesting a thread-method that is started once, Update and/or Draw would fit better.

If you have a CameraSystem you could call the update of that system to set up the viewmatrix and then call the update for the system with the Renderables which draws everything. If there can be more than one CameraComponent active it gets a bit messy when you need to render things more than one time.

The systems are where most of the work happens in ECS, so each needs access to one of the helpers to do its duty. You would then sort the update calls to the systems such that everything works out.

### #3Irlan Robson  Members

3961
Like
0Likes
Like

Posted 23 October 2013 - 09:02 AM

Ah, just a example.

Now I'm working in getting components for a current entity just by a entity ID. Seems like have multiple ways of doing this.

From my point of view I have a component that have a ID (a primary key) a EntityManager that store a map<ID, SomeDerivedComponent>.

Then I have a RenderableSystem that operates on a PositionComponent (a Transform Matrix) and a RenderableComponent. So, in my RenderableSystem I have to find all entities that have Position and Renderable component using the entity ID. If they have both, operate, else don't operate. Every time that I add a component I have to insert the component in the system using something like insert<ID, RenderableComponent>.

eg:

id = 5;

Spatial s;

Renderable r;

s.id = id;

r.id = id;

spatials.insert(id, s);

renderables.insert(id, r);

for all entities e
if(spatials.find(e) && renderables.find(e))
//update with renderable system


What I want to know if is there some better ways of doing this or I must perform this loop every update.

Edited by irlanrobson, 23 October 2013 - 09:03 AM.

### #4wintertime  Members

3826
Like
1Likes
Like

Posted 23 October 2013 - 09:19 AM

There are a number of other threads on ECS already you could do a search for, for example http://www.gamedev.net/topic/648465-csfml-ecs-how-to-deal-with-the-entities/ tells about that.

### #5phil_t  Members

7653
Like
1Likes
Like

Posted 23 October 2013 - 11:07 AM

spatials.insert(id, s);
renderables.insert(id, r);
for all entities e
if(spatials.find(e) && renderables.find(e))
//update with renderable system
What I want to know if is there some better ways of doing this or I must perform this loop every update.

In my implementation, a system declares which types of components it's interested in. If an entity has all those components, then its id is added to a list in that system. So in the particular system's update, it just needs to iterate over those ids. This at least eliminates the need to enumerate over all entities.

In the case where a system only requires one type of component, then it can just iterate over the relevant component list directly (not even caring which entity it belongs to).

### #6Irlan Robson  Members

3961
Like
0Likes
Like

Posted 23 October 2013 - 01:45 PM

http://gamedev.stackexchange.com/questions/46729/retrieving-components-from-game-objects-entities

I'm trying to implement this. But I'm still searching for better methods...

Edited by irlanrobson, 23 October 2013 - 01:45 PM.

### #7Irlan Robson  Members

3961
Like
0Likes
Like

Posted 23 October 2013 - 03:42 PM

spatials.insert(id, s);
renderables.insert(id, r);
for all entities e
if(spatials.find(e) && renderables.find(e))
//update with renderable system
What I want to know if is there some better ways of doing this or I must perform this loop every update.

In my implementation, a system declares which types of components it's interested in. If an entity has all those components, then its id is added to a list in that system. So in the particular system's update, it just needs to iterate over those ids. This at least eliminates the need to enumerate over all entities.

In the case where a system only requires one type of component, then it can just iterate over the relevant component list directly (not even caring which entity it belongs to).

RenderableComponent { position, sprite }
MovementComponent { position, velocity }

The data needs to be duplicated? Eg.: the position. Or the systems must do the inter-communication?

Edited by irlanrobson, 23 October 2013 - 03:56 PM.

### #8phil_t  Members

7653
Like
0Likes
Like

Posted 23 October 2013 - 03:52 PM

A Renderable System interacts with Position Component and a Model Component. My question is: how I can choose these components between systems that use both?
The Renderable Component is dependent of or has a Position Component and a Model Component? A Movement Component has a Position Component and a Velocity Component?

What is Renderable Component?

The Renderable System should process entities that have both a Position and Model component. There is no Renderable component.

Similarly, a Movement System could process entities that have both a Position and Velocity compoent.

### #9Irlan Robson  Members

3961
Like
0Likes
Like

Posted 23 October 2013 - 04:05 PM

A Renderable System interacts with Position Component and a Model Component. My question is: how I can choose these components between systems that use both?
The Renderable Component is dependent of or has a Position Component and a Model Component? A Movement Component has a Position Component and a Velocity Component?

What is Renderable Component?

The Renderable System should process entities that have both a Position and Model component. There is no Renderable component.

Similarly, a Movement System could process entities that have both a Position and Velocity compoent.

Ah, ok. For me a Entity ID is just an index so in that case I have to pass some EntityManager to all systems to perform the look up, right?

Edited by irlanrobson, 23 October 2013 - 04:06 PM.

### #10phil_t  Members

7653
Like
1Likes
Like

Posted 23 October 2013 - 04:57 PM

I have to pass some EntityManager to all systems to perform the look up, right?

Yes.

### #11Irlan Robson  Members

3961
Like
0Likes
Like

Posted 23 October 2013 - 05:25 PM

I have to pass some EntityManager to all systems to perform the look up, right?

Yes.

Aha. Thanks.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.