Note that there are some explanatory texts on larger screens.

plurals
  1. POEncapsulated event handling with Enums
    primarykey
    data
    text
    <p>My Application Layer/View has a event dispatching system aka blackboard. In it listeners are stored by a hashmap with keys being event types implemented as an enum EventType and values being the listener references listening to this event type. E.g. a model object is listening to event type "LOCAL_PLAYER_INPUT", blackboard processes and notifies the player since player implements EventHandler interface.</p> <p>I would like to decouple my model further by implementing a standalone blackboard for model. It would then be added as a listener to the application layer blackboard since application layer is getting I/O from keyboard or touch. Model blackboard would itself delegate events further then. For this I wanted to create an enum hierachy where the event is categorized in this manner:</p> <pre><code>MODEL.LOCAL.PLAYER_INPUT </code></pre> <p>Model would be registered as listener in view blackboard only by passing MODEL like this: </p> <pre><code>addListener(model.blackboard, MODEL); //Types: (EventHandler, EventType) </code></pre> <p>By combining interfaces with enums I achieved, that I can write eventtypes like MODEL.X.Y but it won't be accepted by addListener although MODEL is implementing EventType interface. </p> <p><strong>What should I do?</strong></p> <p><em>EDIT: Some more code</em></p> <p>addListener Method:</p> <pre><code> public void addListener(EventHandler handler, EventType eventType) { getListener(eventType).add(handler);} private Array&lt;EventHandler&gt; getListener(EventType eventType) { if(map.containsKey(eventType)) return map.get(eventType); else { Array&lt;EventHandler&gt; tmp = new Array&lt;EventHandler&gt;(false, 1, EventHandler.class); map.put(eventType, tmp); return tmp; } } </code></pre> <p>Enums:</p> <pre><code>public interface WL extends EventType { public static enum LOCAL { PLAYER_INPUT, NPC_INPUT } </code></pre> <p>}</p> <p>GameEvent:</p> <pre><code> public GameEvent(EventType eventType, Object message) { this.eventType = eventType; this.message = message; timeStamp = System.currentTimeMillis(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload