This question was given attention on a discord server and several very helpful blocks of rust code were provided.
The most important to me was seeing in code the creation of an event listener function. In rust the following closure was provided by azrael in the amethyst discord server.
let player_entity = unimplemented!("fill this in");
let my_event_listener = |world: &mut World, event: &InputEvent| {
if event.attack_pressed {
let players = world.write_storage<Player>();
let mut player_component = players.get_mut(player_entity).unwrap();
player_component.set_state(Attacking);
}
}
here we demonstrate a even listener that has the ability to change the player entity to indicate its new state after the event for an attack button getting pressed is triggered.
the event listener would go in a collection
separate to the event queue
(i suspect you want to add/remove the event listeners separately)
now a demonstration of the actual connection of events to listeners is demonstrated. The events variable would be populated in input processing or game state changes, and then shared with each listener that we iterate over in the bottom of the game loop.
loop {
// receive events from windowing system, and perhaps other system.
let events = // ...
// these may also be inserted into the world, and maybe the ECS systems also add more events.
// run systems
dispatcher.update(&mut world)
// event listeners
for event_listener in event_listeners.iter() {
event_listener(world, events);
}
}
All in all, this represents one concrete pattern for registering listeners with an event queue.