From our last post on an eBus implementation. We talk about that how you can implement the Observer pattern so your can decouple the code from the callers to its callees. The perfect use case for that is obviously to register the observers for certain events such as ticks,
For example, a keyboard event listener may looks like this:
//the listener will override those methods
struct keyboard_input_listener : public ebus_handler<keyboard_events>
{
virtual void on_enter(keyboard_t* keyboard,
surface_t* surf, uint32_t key) override;
virtual void on_leave(keyboard_t* keyboard, surface_t *surf) override;
virtual void on_key(keyboard_t* keyboard,
uint32_t key, uint32_t state) override;
//other events ...
};
//then listen on the events.
keyboard_input_listener listener;
listener.connect();
//certain point a system will trigger events
ebus<keyboard_events>::event(&keyboard_events::on_enter, ...);
ebus<keyboard_events>::event(&keyboard_events::on_key, ...);
///...
ebus<keyboard_events>::event(&keyboard_events::on_leave, ...);
But actually the power of the eBus is far beyond this. On top of this system, we can build other system as well. In this post, we are going to build a (async) task system.