/** * Returns a bag of all components this entity has. * <p> * You need to reset the bag yourself if you intend to fill it more than * once. * </p> * @param fillBag * the bag to put the components into * @return the fillBag containing the components */ public Bag<Component> getComponents(Bag<Component> fillBag) { return world.getComponentManager().getComponentsFor(id, fillBag); }
/** * Returns a BitVector instance containing bits of the components the entity * possesses. * @return a BitVector containing the entities component bits */ protected BitVector getComponentBits() { return world.getComponentManager().componentBits(id); }
private void removeComponents(int entityId) { Bag<ComponentMapper> mappers = componentMappers(entityId); for (int i = 0, s = mappers.size(); s > i; i++) { mappers.get(i).internalRemove(entityId); } setIdentity(entityId, 0); }
int allocateIdentity(BitVector componentBits, ComponentManager cm) { Bag<ComponentMapper> mappers = new Bag<ComponentMapper>(ComponentMapper.class, componentBits.cardinality()); ComponentTypeFactory tf = cm.getTypeFactory(); for (int i = componentBits.nextSetBit(0); i >= 0; i = componentBits.nextSetBit(i + 1)) { mappers.add(cm.getMapper(tf.getTypeFor(i).getType())); } compositionMappers.add(mappers); compositionBits.add(new BitVector(componentBits)); return compositionBits.size() - 1; } }
/** * Retrieves a ComponentMapper instance for fast retrieval of components * from entities. * * Odb automatically injects component mappers into systems, calling this * method is usually not required., * * @param <T> * class type of the component * @param type * type of component to get mapper for * @return mapper for specified component type */ public <T extends Component> ComponentMapper<T> getMapper(Class<T> type) { return cm.getMapper(type); }
@Override protected void initialize() { LinkCreateListener listener = new LinkCreateListener(this); world.getComponentManager().getTypeFactory().register(listener); }
/** * Gets the <code>composition id</code> uniquely identifying the * component composition of an entity. Each composition identity maps * to one unique <code>BitVector</code>. * * @param entityId Entity for which to get the composition id * @return composition identity of entity */ public int compositionId(int entityId) { return cm.getIdentity(entityId); }
TransmuteOperation createOperation(int entityId) { BitVector componentBits = cm.componentBits(entityId); bs.clear(); bs.or(componentBits); bs.or(additions); bs.andNot(removals); int compositionId = cm.compositionIdentity(bs); return new TransmuteOperation(compositionId, getAdditions(componentBits), getRemovals(componentBits)); }
/** * Create a new world specific instance of Archetype based on the current state. * * @param world applicable domain of the Archetype. * @return new Archetype based on current state */ public Archetype build(World world) { ComponentType[] types = resolveTypes(world); ComponentManager cm = world.getComponentManager(); ComponentMapper[] mappers = new ComponentMapper[types.length]; for (int i = 0, s = mappers.length; s > i; i++) { mappers[i] = cm.getMapper(types[i].getType()); } int compositionId = cm.compositionIdentity(bitset(types)); TransmuteOperation operation = new TransmuteOperation(compositionId, mappers, new ComponentMapper[0]); return new Archetype(operation, compositionId); }
/** * Create and return an {@link Entity} wrapping a new or reused entity instance. * Entity is automatically added to the world. * * Use {@link Entity#edit()} to set up your newly created entity. * * You can also create entities using: * - {@link com.artemis.utils.EntityBuilder} Convenient entity creation. Not useful when pooling. * - {@link com.artemis.Archetype} Fastest, low level, no parameterized components. * * @return assigned entity id */ public int create(Archetype archetype) { int entityId = em.create(); archetype.transmuter.perform(entityId); cm.setIdentity(entityId, archetype.compositionId); batchProcessor.changed.unsafeSet(entityId); return entityId; }
/** * Removes all components from deleted entities. * * @param pendingPurge * the entities to remove components from */ void clean(IntBag pendingPurge) { int[] ids = pendingPurge.getData(); for (int i = 0, s = pendingPurge.size(); s > i; i++) { removeComponents(ids[i]); } }
/** * Get all component associated with an entity. * * @param entityId * the entity to get components from * @param fillBag * a bag to be filled with components * @return the {@code fillBag}, filled with the entities components */ public Bag<Component> getComponentsFor(int entityId, Bag<Component> fillBag) { Bag<ComponentMapper> mappers = componentMappers(entityId); for (int i = 0, s = mappers.size(); s > i; i++) { fillBag.add(mappers.get(i).get(entityId)); } return fillBag; }
int allocateIdentity(BitVector componentBits, ComponentManager cm) { Bag<ComponentMapper> mappers = new Bag<ComponentMapper>(ComponentMapper.class, componentBits.cardinality()); ComponentTypeFactory tf = cm.getTypeFactory(); for (int i = componentBits.nextSetBit(0); i >= 0; i = componentBits.nextSetBit(i + 1)) { mappers.add(cm.getMapper(tf.getTypeFor(i).getType())); } compositionMappers.add(mappers); compositionBits.add(new BitVector(componentBits)); return compositionBits.size() - 1; } }
/** * Retrieves a ComponentMapper instance for fast retrieval of components * from entities. * * Odb automatically injects component mappers into systems, calling this * method is usually not required., * * @param <T> * class type of the component * @param type * type of component to get mapper for * @return mapper for specified component type */ public <T extends Component> ComponentMapper<T> getMapper(Class<T> type) { return cm.getMapper(type); }
public <T extends Component> M<T> getFor(Class<T> type) { ComponentTypeFactory tf = world.getComponentManager().getTypeFactory(); return getCreateMapper(tf.getTypeFor(type)); }
/** * Gets the <code>composition id</code> uniquely identifying the * component composition of an entity. Each composition identity maps * to one unique <code>BitVector</code>. * * @param entityId Entity for which to get the composition id * @return composition identity of entity */ public int compositionId(int entityId) { return cm.getIdentity(entityId); }
TransmuteOperation createOperation(int entityId) { BitVector componentBits = cm.componentBits(entityId); bs.clear(); bs.or(componentBits); bs.or(additions); bs.andNot(removals); int compositionId = cm.compositionIdentity(bs); return new TransmuteOperation(compositionId, getAdditions(componentBits), getRemovals(componentBits)); }
/** * Create a new world specific instance of Archetype based on the current state. * * @param world applicable domain of the Archetype. * @return new Archetype based on current state */ public Archetype build(World world) { ComponentType[] types = resolveTypes(world); ComponentManager cm = world.getComponentManager(); ComponentMapper[] mappers = new ComponentMapper[types.length]; for (int i = 0, s = mappers.length; s > i; i++) { mappers[i] = cm.getMapper(types[i].getType()); } int compositionId = cm.compositionIdentity(bitset(types)); TransmuteOperation operation = new TransmuteOperation(compositionId, mappers, new ComponentMapper[0]); return new Archetype(operation, compositionId); }
/** * Create and return an {@link Entity} wrapping a new or reused entity instance. * Entity is automatically added to the world. * * Use {@link Entity#edit()} to set up your newly created entity. * * You can also create entities using: * - {@link com.artemis.utils.EntityBuilder} Convenient entity creation. Not useful when pooling. * - {@link com.artemis.Archetype} Fastest, low level, no parameterized components. * * @return assigned entity id */ public int create(Archetype archetype) { int entityId = em.create(); archetype.transmuter.perform(entityId); cm.setIdentity(entityId, archetype.compositionId); batchProcessor.changed.unsafeSet(entityId); return entityId; }
/** * Removes all components from deleted entities. * * @param pendingPurge * the entities to remove components from */ void clean(IntBag pendingPurge) { int[] ids = pendingPurge.getData(); for (int i = 0, s = pendingPurge.size(); s > i; i++) { removeComponents(ids[i]); } }