/** Subscribe listener to events. */ @Override public void register( EventListener listener ) { if ( !listeners.contains(listener) ) { listeners.add(listener); sortDirty =true; } }
/** * Ensure this builder includes the specified component type. * * @param type * @return This instance for chaining. */ public ArchetypeBuilder add(Class<? extends Component> type) { if (!classes.contains(type)) classes.add(type); return this; }
/** * Ensure this builder includes the specified component types. * * @param types * @return This instance for chaining. */ public ArchetypeBuilder add(Class<? extends Component>... types) { for (int i = 0; types.length > i; i++) { Class<? extends Component> type = types[i]; if (!classes.contains(type)) classes.add(type); } return this; }
/** * Ensure this builder includes the specified component type. * * @param type * @return This instance for chaining. */ public ArchetypeBuilder add(Class<? extends Component> type) { if (!classes.contains(type)) classes.add(type); return this; }
/** Subscribe listener to events. */ @Override public void register( EventListener listener ) { if ( !listeners.contains(listener) ) { listeners.add(listener); sortDirty =true; } }
/** * Ensure this builder includes the specified component types. * * @param types * @return This instance for chaining. */ public ArchetypeBuilder add(Class<? extends Component>... types) { for (int i = 0; types.length > i; i++) { Class<? extends Component> type = types[i]; if (!classes.contains(type)) classes.add(type); } return this; }
@Override public void register(EventListener listener) { if ( listener == null ) throw new NullPointerException("Listener required."); // Bind listener to the related event class. Bag<EventListener> listenersFor = getListenersFor(listener.getParameterType(), true); if ( !listenersFor.contains(listener)) { listenersFor.add(listener); // the hierarchical cache is now out of date. purrrrrrrrge! invalidateHierarchicalCache(); } }
/** * Set the group of the entity. * * @param group group to add the entity into * @param e entity to add into the group */ public void add(Entity e, String group) { Bag<Entity> entities = entitiesByGroup.get(group); if (entities == null) { entities = new Bag<>(); entitiesByGroup.put(group, entities); } IntBag identities = identitiesByGroup.get(group); if (identities == null) { identities = new IntBag(); identitiesByGroup.put(group, identities); } if (!entities.contains(e)) { entities.add(e); identities.add(e.getId()); } Bag<String> groups = groupsByEntity.get(e); if (groups == null) { groups = new Bag<>(); groupsByEntity.put(e, groups); } if (!groups.contains(group)) { groups.add(group); } }
/** * Set the group of the entity. * * @param group group to add the entity into * @param e entity to add into the group */ public void add(Entity e, String group) { Bag<Entity> entities = entitiesByGroup.get(group); if (entities == null) { entities = new Bag<>(); entitiesByGroup.put(group, entities); } IntBag identities = identitiesByGroup.get(group); if (identities == null) { identities = new IntBag(); identitiesByGroup.put(group, identities); } if (!entities.contains(e)) { entities.add(e); identities.add(e.getId()); } Bag<String> groups = groupsByEntity.get(e); if (groups == null) { groups = new Bag<>(); groupsByEntity.put(e, groups); } if (!groups.contains(group)) { groups.add(group); } }
@Override public void register(EventListener listener) { if ( listener == null ) throw new NullPointerException("Listener required."); // Bind listener to the related event class. Bag<EventListener> listenersFor = getListenersFor(listener.getParameterType(), true); if ( !listenersFor.contains(listener)) { listenersFor.add(listener); // the hierarchical cache is now out of date. purrrrrrrrge! invalidateHierarchicalCache(); } }
/** * Subscribe T to entity. * <p/> * Does nothing if already subscribed. * * @param subscriber subscriber * @param entityId entity to subscribe. */ public void subscribe(T subscriber, int entityId) { // hook subscriber to entity. IntBag entities = subscriberEntities.get(subscriber); if (entities == null) { entities = new IntBag(); subscriberEntities.put(subscriber, entities); } if (!entities.contains(entityId)) { entities.add(entityId); } // hook entity to subscriber. Bag<T> subscribers = entitySubscribers.get(entityId); if (subscribers == null) { subscribers = new Bag<>(); entitySubscribers.set(entityId, subscribers); } if (!subscribers.contains(subscriber)) { subscribers.add(subscriber); } }
/** * <p>Injects and associates the listener with a specific field for a given * component type.</p> * * <p>Each <code>ComponentType::Field</code> pair can only have one {@link LinkListener}</p> * * @param component component type associated with listener * @param field target field for listener * @param listener link listener */ public void register(Class<? extends Component> component, String field, LinkListener listener) { world.inject(listener); try { Field f = (field != null) ? ClassReflection.getDeclaredField(component, field) : null; ComponentType ct = world.getComponentManager().getTypeFactory().getTypeFor(component); for (LinkSite site : linkSites) { if (ct.equals(site.type) && (f == null || site.field.equals(f))) { site.listener = listener; if (!decoratedLinkSites.contains(site)) decoratedLinkSites.add(site); if (fireEventsOnRegistration) site.inserted(site.subscription.getEntities()); } } } catch (ReflectionException e) { throw new RuntimeException(e); } }
/** * <p>Injects and associates the listener with a specific field for a given * component type.</p> * * <p>Each <code>ComponentType::Field</code> pair can only have one {@link LinkListener}</p> * * @param component component type associated with listener * @param field target field for listener * @param listener link listener */ public void register(Class<? extends Component> component, String field, LinkListener listener) { world.inject(listener); try { Field f = (field != null) ? ClassReflection.getDeclaredField(component, field) : null; ComponentType ct = world.getComponentManager().getTypeFactory().getTypeFor(component); for (LinkSite site : linkSites) { if (ct.equals(site.type) && (f == null || site.field.equals(f))) { site.listener = listener; if (!decoratedLinkSites.contains(site)) decoratedLinkSites.add(site); if (fireEventsOnRegistration) site.inserted(site.subscription.getEntities()); } } } catch (ReflectionException e) { throw new RuntimeException(e); } }