librelist archives

« back to archive

Events between Managers.

Events between Managers.

From:
Asmodehn Shade
Date:
2014-07-09 @ 05:34
Hello,

So I have been using entityx quite a bit and I realized this recently :

- We need to force ourselves to divide and simplify components and
systems as much as possible to the atomic level ( cannot divide it
anymore ), It will make changes later on really so much easier.

- I usually transfer "entity-related" information between my systems
via components <added to / removed from> an entity inside an update
call.

- I use events for seldom changes that might not be related to an
entity or does not need an update loop to run.

As a result, when I use events it s usually the manager ( or a system
without update loop ) that receive the event.

Now, since the Manager is receiving events, I might want to transfer
this event directly to another Manager ( just I would do with a usual
signal/slot ) implementation.

So yes I have multiple Managers. This is fine, as an entity in the
world of a manager has a different semantic compared to an entity in
the world of another manager.
But I might want to send the event from one manager, and grab it in
another manager.

More concrete example ( even though I know it might not be what
EntitySystem are designed for, I still find the approach brings a lot
of simplification to many domain ) :

- I have one DownloadManager dealing with entity system design to
download files. One Entity in this world is a file ( that can be
local, online, currently downloading, with or without md5 signature,
etc.)
- I have a LoadingManager dealing with files to be loaded into engine
( cocos2d-x + custom ). One Entity in this world is a file ( that can
be image, json, binary, not loaded, currently loading, loaded )
- I have a DisplayManager that display images ( or other data ) at a
certain point in time.

=> In this setup I would like that the "Downloaded" Event triggered in
the DownloadManager is received by the LoadingManager, so that the
loading manager can add an entity to load the file.
Then the "Loaded" event triggered by the Loading Manager is received
by the DisplayManager, who can now display the file.

My problem now becomes that a Manager initializes un event_manager on
construction and that events cant easily get out of there...

I realize that in my exemple I have a "meta Entity ID concept" ( the
file path that allow me to identify which file I m dealing with ).
I did this split in mutliple Managers to divide complexity vertically
in potentially independent silos of entity system design. But I still
would like them to be able to communicate.
So I think that a Manager does too many things and there might some
benefits in splitting the entity/system design from the event
management...
Afterall It would be useless to implement another set of signal/slot
on top of that, when we have already the event_manager setup...

Thank you for letting me know what your thoughts are about this topic...
If you need any more information/details don't hesitate to ask, most
of the code is on github already.

Thanks a lot !

--
AlexV

Re: [entityx] Events between Managers.

From:
Alec Thomas
Date:
2014-07-09 @ 06:14

On Wednesday, 9 July 2014 at 3:34 pm, Asmodehn Shade wrote:

> Hello,
>  
> So I have been using entityx quite a bit and I realized this recently :
>  
> - We need to force ourselves to divide and simplify components and
> systems as much as possible to the atomic level ( cannot divide it
> anymore ), It will make changes later on really so much easier.
>  
> - I usually transfer "entity-related" information between my systems
> via components <added to / removed from> an entity inside an update
> call.
>  
> - I use events for seldom changes that might not be related to an
> entity or does not need an update loop to run.
>  
> As a result, when I use events it s usually the manager ( or a system
> without update loop ) that receive the event.
>  
> Now, since the Manager is receiving events, I might want to transfer
> this event directly to another Manager ( just I would do with a usual
> signal/slot ) implementation.
>  
> So yes I have multiple Managers. This is fine, as an entity in the
> world of a manager has a different semantic compared to an entity in
> the world of another manager.
> But I might want to send the event from one manager, and grab it in
> another manager.
>  
> More concrete example ( even though I know it might not be what
> EntitySystem are designed for, I still find the approach brings a lot
> of simplification to many domain ) :
>  
> - I have one DownloadManager dealing with entity system design to
> download files. One Entity in this world is a file ( that can be
> local, online, currently downloading, with or without md5 signature,
> etc.)
> - I have a LoadingManager dealing with files to be loaded into engine
> ( cocos2d-x + custom ). One Entity in this world is a file ( that can
> be image, json, binary, not loaded, currently loading, loaded )
> - I have a DisplayManager that display images ( or other data ) at a
> certain point in time.
>  
> => In this setup I would like that the "Downloaded" Event triggered in
> the DownloadManager is received by the LoadingManager, so that the
> loading manager can add an entity to load the file.
> Then the "Loaded" event triggered by the Loading Manager is received
> by the DisplayManager, who can now display the file.
>  
>  

  
>  
> My problem now becomes that a Manager initializes un event_manager on
> construction and that events cant easily get out of there...
>  
> I realize that in my exemple I have a "meta Entity ID concept" ( the
> file path that allow me to identify which file I m dealing with ).
> I did this split in mutliple Managers to divide complexity vertically
> in potentially independent silos of entity system design. But I still
> would like them to be able to communicate.
>  
>  

  
> So I think that a Manager does too many things and there might some
> benefits in splitting the entity/system design from the event
> management...
> Afterall It would be useless to implement another set of signal/slot
> on top of that, when we have already the event_manager setup...
>  
>  


Due to these, along with some other concerns, “Manager" was already 
removed from master. There is still a similar class called EntityX 
(https://github.com/alecthomas/entityx/blob/master/entityx/quick.h), but 
it is just a convenience that bootstraps the entity, event and system 
managers for a quickstart. It is completely optional.

This is the bulk of the code:

  EventManager events;
  EntityManager entities(events);
  SystemManager systems(entities, events);



The dependencies are clear from the constructor parameters, so you can 
easily mix and match them within the provided constraints. There is 
nothing inherent to the EventManager that prevents it being used by 
multiple systems simultaneously. So if you don’t use Manager, but rather 
construct the EventManager, EntityManager and SystemManager directly, you 
should be fine.

So… basically, what you want already exists I think?
  
>  
> Thank you for letting me know what your thoughts are about this topic...
> If you need any more information/details don't hesitate to ask, most
> of the code is on github already.
>  
> Thanks a lot !
>  
> --
> AlexV
>  
>  

Re: [entityx] Events between Managers.

From:
Asmodehn Shade
Date:
2014-07-09 @ 14:54
Yes indeed. I exposed the event manager of one of my manager, pass it to
the second manager who subscribe to it for the event he wants to get, and
everything work as I expected.

I ll check the design without manager next time i will pull the changes
from your master then.

Thanks a lot for the good work !
--
AlexV
On Jul 9, 2014 3:15 PM, "Alec Thomas" <alec@swapoff.org> wrote:

>
>  On Wednesday, 9 July 2014 at 3:34 pm, Asmodehn Shade wrote:
>
> Hello,
>
> So I have been using entityx quite a bit and I realized this recently :
>
> - We need to force ourselves to divide and simplify components and
> systems as much as possible to the atomic level ( cannot divide it
> anymore ), It will make changes later on really so much easier.
>
> - I usually transfer "entity-related" information between my systems
> via components <added to / removed from> an entity inside an update
> call.
>
> - I use events for seldom changes that might not be related to an
> entity or does not need an update loop to run.
>
> As a result, when I use events it s usually the manager ( or a system
> without update loop ) that receive the event.
>
> Now, since the Manager is receiving events, I might want to transfer
> this event di rectly to another Manager ( just I would do with a usual
> signal/slot ) implementation.
>
> So yes I have multiple Managers. This is fine, as an entity in the
> world of a manager has a different semantic compared to an entity in
> the world of another manager.
> But I might want to send the event from one manager, and grab it in
> another manager.
>
> More concrete example ( even though I know it might not be what
> EntitySystem are designed for, I still find the approach brings a lot
> of simplification to many domain ) :
>
> - I have one DownloadManager dealing with entity system design to
> download files. One Entity in this world is a file ( that can be
> local, online, currently downloading, with or without md5 signature,
> etc.)
> - I have a LoadingManager dealing with files to be loaded into engine
> ( cocos2d-x + cus tom ). One Entity in this world is a file ( that can
> be image, json, binary, not loaded, currently loading, loaded )
> - I have a DisplayManager that display images ( or other data ) at a
> certain point in time.
>
> => In this setup I would like that the "Downloaded" Event triggered in
> the DownloadManager is received by the LoadingManager, so that the
> loading manager can add an entity to load the file.
> Then the "Loaded" event triggered by the Loading Manager is received
> by the DisplayManager, who can now display the file.
>
>
>
>
> My problem now becomes that a Manager initializes un event_manager on
> construction and that events cant easily get out of there...
>
> I realize that in my exemple I have a "meta Entity ID concept" ( the
> file path that allow me to identify which file I m dealing with ).
> I did this split in mutliple Managers to divide complexity vertically
> in potentially independent silos of entity system design. But I still
> would like them to be able to communicate.
>
>
>
> So I think that a Manager does too many things and there might some
> benefits in splitting the entity/system design from the event
> management...
> Afterall It would be useless to implement another set of signal/slot
> on top of that, when we have already the event_manager setup...
>
>
> Due to these, along with some other concerns, “Manager" was already
> removed from master. There *is* still a similar class called EntityX
> <https://github.com/alecthomas/entityx/blob/master/entityx/quick.h>, but
> it is just a convenience that bootstraps the entity, event and system
> managers for a quickstart. It is completely optional.
>
> This is the bulk of the code:
>
>   EventManager events;
>   EntityManager entities(events);
>   SystemManager systems(entities, events);
>
>
> The dependencies are clear from the constructor parameters, so you can
> easily mix and match them within the provided constraints. There is nothing
> inherent to the EventManager that prevents it being used by multiple
> systems simultaneously. So if you don’t use Manager, but rather construct
> the EventManager, EntityManager and SystemManager directly, you should be
> fine.
>
> So… basically, what you want already exists I think?
>
>
>
> Thank you for letting me know what your thoughts are about this topic...
> If you need any more information/details don't hesitate to ask, most
> of the code is on github already.
>
> Thanks a lot !
>
> --
> AlexV
>
>
>