private Set <EventHandlerInfo> selectEventHandlers(Type eventType, EntityRef entity) { Set <EventHandlerInfo> result = Sets.newHashSet(); result.addAll(generalHandlers.get(eventType)); SetMultimap <Type, EventHandlerInfo> handlers = componentSpecificHandlers[eventType]; if (handlers == null) { return(result); } foreach (Type compClass in handlers.Keys) { if (entity.hasComponent(compClass)) { foreach (EventHandlerInfo eventHandler in handlers.get(compClass)) { if (eventHandler.isValidFor(entity)) { result.add(eventHandler); } } } } return(result); }
public virtual void send(EntityRef entity, Event @event, Component component) { if (Thread.CurrentThread != mainThread) { pendingEvents.offer(new PendingEvent(entity, @event, component)); } else { SetMultimap <Type, EventHandlerInfo> handlers = componentSpecificHandlers[@event.GetType()]; if (handlers != null) { IList <EventHandlerInfo> eventHandlers = Lists.newArrayList(handlers.get(component.GetType())); eventHandlers.Sort(priorityComparator); foreach (EventHandlerInfo eventHandler in eventHandlers) { if (eventHandler.isValidFor(entity)) { eventHandler.invoke(entity, @event); } } } } }