Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Entity/Component System - Understanding Event Priority

  • You cannot reply to this topic
4 replies to this topic

#1 UnscrypteD   Members   -  Reputation: 104

Like
0Likes
Like

Posted Yesterday, 04:18 PM

Hello!

 

So I have been working with implementing various types of Entity/Component Systems, and I really like the model which follows:

 

Entities are only IDs, Components are bags of data/properties, Systems act on one or more components that they're interested in.

 

This is all fine, but here's something I don't quite get ---

 

In my model, when something happens to a component, an event is raised, and other systems that care about that event respond.  How does one determine the "firing" order of these events so that it's not totally random the order in which systems respond to events?

 

For example, in a CollisionSystem, if two entities have a CollisionComponent and collide, the system would fire off an event into the wild saying so.  How can you efficiently guarantee the the responses to this event are fired in the right order?

 



Sponsor:

#2 Khaiy   Crossbones+   -  Reputation: 1609

Like
0Likes
Like

Posted Yesterday, 05:05 PM

It may depend on how the events are consumed, but couldn't you just fire the events into a buffer and then consume them in order?



#3 phil_t   Crossbones+   -  Reputation: 5596

Like
3Likes
Like

Posted Yesterday, 05:33 PM

If you need to control the order things are processed in, you could (instead of firing an event and having the receiver process it immediately) set information in the CollisionComponent describing the collision. Then you would have a system (which by nature are updated in a specific order) that processes the result of the collision.


Edited by phil_t, Yesterday, 05:34 PM.


#4 stein102   Members   -  Reputation: 511

Like
0Likes
Like

Posted Yesterday, 06:11 PM

When an event fires, you could place it in a queue and during the game loop, iterate through it and handle them accordingly.

#5 SeanMiddleditch   Crossbones+   -  Reputation: 10081

Like
1Likes
Like

Posted Yesterday, 09:34 PM

If you're using a true ECS pattern (sounds like you are), read these:

http://bitsquid.blogspot.com/2009/12/events.html
http://bitsquid.blogspot.com/2011/01/managing-coupling.html
http://bitsquid.blogspot.com/2011/02/managing-decoupling-part-2-polling.html
http://bitsquid.blogspot.com/2011/02/some-systems-need-to-manipulate-objects.html

Then read every other Bitsquid blog article.

Then head over and read the Molecular Musings blog (https://molecularmusings.wordpress.com/).





PARTNERS