I'm working on a Entity Component System for learning purpose. I made major changes with my design so I was wondering if I could pick a better design for my event system.
The purpose of the event system (if you don't know ECS), is to allow communication between process. For example, in a video game (that's always more easy to understand with video games) your collision system may want to tell to other system when there is a collision and with which entities.
With this little context, my current design for the event system was more :
- When an event is emit -> save it into event manager (shared ptr)
- Then call every subscribers and send them a shared ptr of the data (thanks to Bart van Ingen Schenau)
- Inside the callback, save the event into a queue to consume it on the next update call
But events are read only, so I wonder if something like that won't be better:
- When an event is emit -> call every subscribers and send them a copy of the event
- Inside the callback, move the event into a queue to consume it on the next update call
The systems will be multithreading (which mean at least than events can be emit on any thread).
One of the most important part of my new design, is that system are "split" in blocs (you can see that like several update function). But events are for the whole system. So copies will mean that I'll need some garbage collector function for each system to free events which where consume. Well in fact I still need that with shared ptr.
There is probably a lot of other designs. So if you think of something good for an ECS generic (not only for video games), where events subscriber tend to regroup, give me your thought please.