/** * @return entity subscription backing this system. */ public EntitySubscription getSubscription() { final AspectSubscriptionManager sm = world.getAspectSubscriptionManager(); return sm.get(aspectConfiguration); }
/** * <p>Gets the entity subscription for the {@link Aspect}. * Subscriptions are only created once per aspect.</p> * * Be careful when calling this within {@link BaseSystem#processSystem()}. * If the subscription does not exist yet, the newly created subscription * will reflect all the chances made by the currently processing system, * NOT the state before the system started processing. This might cause * the system to behave differently when run the first time (as * subsequent calls won't have this issue). * See https://github.com/junkdog/artemis-odb/issues/551 * * @param builder Aspect to match. * @return {@link EntitySubscription} for aspect. */ public EntitySubscription get(Aspect.Builder builder) { EntitySubscription subscription = subscriptionMap.get(builder); return (subscription != null) ? subscription : createSubscription(builder); }
/** * Fetches unique identifier for composition. * * @param componentBits composition to fetch unique identifier for. * @return Unique identifier for passed composition. */ public int compositionIdentity(BitVector componentBits) { int identity = identityResolver.getIdentity(componentBits); if (identity == -1) { identity = identityResolver.allocateIdentity(componentBits, this); world.getAspectSubscriptionManager() .processComponentIdentity(identity, componentBits); } return identity; }
void update() { while(!changed.isEmpty() || !deleted.isEmpty()) { asm.process(changed, deleted); purgeComponents(); } clean(); }
/** * Informs all listeners of added, changedBits and deletedBits changes. * * Order of {@link EntitySubscription.SubscriptionListener} can vary * (typically ordinal, except for subscriptions created in process, * initialize instead of setWorld). * * {@link com.artemis.EntitySubscription.SubscriptionListener#inserted(IntBag)} * {@link com.artemis.EntitySubscription.SubscriptionListener#removed(IntBag)} * * @param changedBits Entities with changedBits composition or state. * @param deletedBits Entities removed from world. */ void process(BitVector changedBits, BitVector deletedBits) { toEntityIntBags(changedBits, deletedBits); // note: processAll != process subscriptions.get(0).processAll(changed, deleted); for (int i = 1, s = subscriptions.size(); s > i; i++) { subscriptions.get(i).process(changed, deleted); } }
/** * Creates a new world. * <p> * {@link com.artemis.EntityManager}, {@link ComponentManager} and {@link AspectSubscriptionManager} are * available by default, on top of your own systems. * </p> * @see WorldConfigurationBuilder * @see WorldConfiguration */ public World(WorldConfiguration configuration) { partition = new WorldSegment(configuration); systemsBag = configuration.systems; final ComponentManager lcm = (ComponentManager) systemsBag.get(COMPONENT_MANAGER_IDX); final EntityManager lem = (EntityManager) systemsBag.get(ENTITY_MANAGER_IDX); final AspectSubscriptionManager lasm = (AspectSubscriptionManager) systemsBag.get(ASPECT_SUBSCRIPTION_MANAGER_IDX); cm = lcm == null ? new ComponentManager(configuration.expectedEntityCount()) : lcm; em = lem == null ? new EntityManager(configuration.expectedEntityCount()) : lem; asm = lasm == null ? new AspectSubscriptionManager() : lasm; batchProcessor = new BatchChangeProcessor(this); alwaysDelayComponentRemoval = configuration.isAlwaysDelayComponentRemoval(); configuration.initialize(this, partition.injector, asm); }
/** * Fetches unique identifier for composition. * * @param componentBits composition to fetch unique identifier for. * @return Unique identifier for passed composition. */ public int compositionIdentity(BitVector componentBits) { int identity = identityResolver.getIdentity(componentBits); if (identity == -1) { identity = identityResolver.allocateIdentity(componentBits, this); world.getAspectSubscriptionManager() .processComponentIdentity(identity, componentBits); } return identity; }
void update() { while(!changed.isEmpty() || !deleted.isEmpty()) { asm.process(changed, deleted); purgeComponents(); } clean(); }
/** * Informs all listeners of added, changedBits and deletedBits changes. * * Order of {@link EntitySubscription.SubscriptionListener} can vary * (typically ordinal, except for subscriptions created in process, * initialize instead of setWorld). * * {@link com.artemis.EntitySubscription.SubscriptionListener#inserted(IntBag)} * {@link com.artemis.EntitySubscription.SubscriptionListener#removed(IntBag)} * * @param changedBits Entities with changedBits composition or state. * @param deletedBits Entities removed from world. */ void process(BitVector changedBits, BitVector deletedBits) { toEntityIntBags(changedBits, deletedBits); // note: processAll != process subscriptions.get(0).processAll(changed, deleted); for (int i = 1, s = subscriptions.size(); s > i; i++) { subscriptions.get(i).process(changed, deleted); } }
/** * Creates a new world. * <p> * {@link com.artemis.EntityManager}, {@link ComponentManager} and {@link AspectSubscriptionManager} are * available by default, on top of your own systems. * </p> * @see WorldConfigurationBuilder * @see WorldConfiguration */ public World(WorldConfiguration configuration) { partition = new WorldSegment(configuration); systemsBag = configuration.systems; final ComponentManager lcm = (ComponentManager) systemsBag.get(COMPONENT_MANAGER_IDX); final EntityManager lem = (EntityManager) systemsBag.get(ENTITY_MANAGER_IDX); final AspectSubscriptionManager lasm = (AspectSubscriptionManager) systemsBag.get(ASPECT_SUBSCRIPTION_MANAGER_IDX); cm = lcm == null ? new ComponentManager(configuration.expectedEntityCount()) : lcm; em = lem == null ? new EntityManager(configuration.expectedEntityCount()) : lem; asm = lasm == null ? new AspectSubscriptionManager() : lasm; batchProcessor = new BatchChangeProcessor(this); alwaysDelayComponentRemoval = configuration.isAlwaysDelayComponentRemoval(); configuration.initialize(this, partition.injector, asm); }
/** * @return entity subscription backing this system. */ public EntitySubscription getSubscription() { final AspectSubscriptionManager sm = world.getAspectSubscriptionManager(); return sm.get(aspectConfiguration); }
/** * Fetches unique identifier for composition. * * @param componentBits composition to fetch unique identifier for. * @return Unique identifier for passed composition. */ public int compositionIdentity(BitVector componentBits) { int identity = identityResolver.getIdentity(componentBits); if (identity == -1) { identity = identityResolver.allocateIdentity(componentBits, this); world.getAspectSubscriptionManager() .processComponentIdentity(identity, componentBits); } return identity; }
/** * <p>Gets the entity subscription for the {@link Aspect}. * Subscriptions are only created once per aspect.</p> * * Be careful when calling this within {@link BaseSystem#processSystem()}. * If the subscription does not exist yet, the newly created subscription * will reflect all the chances made by the currently processing system, * NOT the state before the system started processing. This might cause * the system to behave differently when run the first time (as * subsequent calls won't have this issue). * See https://github.com/junkdog/artemis-odb/issues/551 * * @param builder Aspect to match. * @return {@link EntitySubscription} for aspect. */ public EntitySubscription get(Aspect.Builder builder) { EntitySubscription subscription = subscriptionMap.get(builder); return (subscription != null) ? subscription : createSubscription(builder); }
public EntitySubscription getSubscription(Aspect.Builder aspectA) { final AspectSubscriptionManager sm = world.getSystem(AspectSubscriptionManager.class); return sm.get(aspectA); }
void initialize(World world, Injector injector, AspectSubscriptionManager asm) { if (invocationStrategy == null) invocationStrategy = new InvocationStrategy(); invocationStrategy.setWorld(world); world.invocationStrategy = invocationStrategy; systems.set(COMPONENT_MANAGER_IDX, world.getComponentManager()); systems.set(ENTITY_MANAGER_IDX, world.getEntityManager()); systems.set(ASPECT_SUBSCRIPTION_MANAGER_IDX, asm); for (BaseSystem system : systems) { world.partition.systems.put(system.getClass(), system); system.setWorld(world); if (ClassReflection.isInstance(Manager.class, system)) { ((Manager) system).registerManager(); } } injector.initialize(world, injectables); initializeSystems(injector); asm.processComponentIdentity(NO_COMPONENTS, new BitVector()); invocationStrategy.setSystems(systems); invocationStrategy.initialize(); }
public EntitySubscription getSubscription(Aspect.Builder aspectA) { final AspectSubscriptionManager sm = world.getSystem(AspectSubscriptionManager.class); return sm.get(aspectA); }
void initialize(World world, Injector injector, AspectSubscriptionManager asm) { if (invocationStrategy == null) invocationStrategy = new InvocationStrategy(); invocationStrategy.setWorld(world); world.invocationStrategy = invocationStrategy; systems.set(COMPONENT_MANAGER_IDX, world.getComponentManager()); systems.set(ENTITY_MANAGER_IDX, world.getEntityManager()); systems.set(ASPECT_SUBSCRIPTION_MANAGER_IDX, asm); for (BaseSystem system : systems) { world.partition.systems.put(system.getClass(), system); system.setWorld(world); if (ClassReflection.isInstance(Manager.class, system)) { ((Manager) system).registerManager(); } } injector.initialize(world, injectables); initializeSystems(injector); asm.processComponentIdentity(NO_COMPONENTS, new BitVector()); invocationStrategy.setSystems(systems); invocationStrategy.initialize(); }
@Override protected void setWorld(World world) { super.setWorld(world); // making sure the first subscription matches all entities get(all()); }
@Override public void setWorld(World world) { all = world.getAspectSubscriptionManager().get(all()); } }
@Override public void setWorld(World world) { all = world.getAspectSubscriptionManager().get(all()); } }