amethyst/legion

Entity eventing

Closed this issue · 0 comments

There is currently no easy way to determine when an entity is created, deleted, or its composition is changed. This makes building out-of-bound data structures which store data about entities that a system is interested in difficult. Typically, ECS systems provide entity added/deleted events, with the ID of the entity provided as event payload.

I mentioned my thoughts on what legion needs for eventing in #11:

The problem with global added/deleted events is that the entity IDs alone aren't enough to determine if the entity is/was of interest to the system. What it really needs is information about the component composition of the entity, too. This is further complicated by entity mutations, which could move an entity in/out of interest without creating or destroying it.

Entity deletion events can safely be used by a system to clean up it's state, although every system with such state will have to listen to all such events and determine for themselves if said entity is one they are managing.

Entity mutation (component/tag add/remove) events are very difficult to work with. It is not going to be very clear when a given change will cause an entity to no longer be of interest (especially if the system is using complex queries with component_a | component_b conditions) and be of no use in determining if the entity has become of interest.

Entity added events are almost useless, outside of some logging or metrics events.

What I would like to do is support an eventing API that allows the user to register to recieve entity events for all entities that match an EntityFilter. Such event channels would attach themselves to all chunks that match the query, and would fire added/removed events when an entity is moved into or out of said chunk.