Question on Entity Component System (rendering related)

Started by
9 comments, last by Irlan Robson 10 years, 6 months ago

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. ?

Advertisement

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.

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.

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.


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).

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...


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?


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.


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?


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

Yes.

This topic is closed to new replies.

Advertisement