Sign in to follow this  
Irlan

Question on Entity Component System (rendering related)

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites


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

Share this post


Link to post
Share on other sites

 


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

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

 


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this