/** * 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); }
/** * 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); }
/** * Create a component of given type by class. * @param owner entity id * @param componentClass class of component to instance. * @return Newly created packed, pooled or basic component. */ protected <T extends Component> T create(int owner, Class<T> componentClass) { return getMapper(componentClass).create(owner); }
/** * Create new instance of component. * <p/> * if exists, replaces and retires old component! * * @param componentKlazz Class to create. * @return Newly instanced component. */ public <T extends Component> T create(Class<T> componentKlazz) { return cm.getMapper(componentKlazz).create(entityId); }
/** * Create new instance of component. * <p/> * if exists, replaces and retires old component! * * @param componentKlazz Class to create. * @return Newly instanced component. */ public <T extends Component> T create(Class<T> componentKlazz) { return cm.getMapper(componentKlazz).create(entityId); }
/** * Create a component of given type by class. * @param owner entity id * @param componentClass class of component to instance. * @return Newly created packed, pooled or basic component. */ protected <T extends Component> T create(int owner, Class<T> componentClass) { return getMapper(componentClass).create(owner); }
/** * Create a component of given type by class. * @param owner entity id * @param componentClass class of component to instance. * @return Newly created packed, pooled or basic component. */ protected <T extends Component> T create(int owner, Class<T> componentClass) { return getMapper(componentClass).create(owner); }
/** * Removal of components from a entity. * <p/> * Faster than {@link #remove(Class)}. * * @param type the type of component to remove from this entity * @return this EntityEdit for chaining */ public EntityEdit remove(ComponentType type) { cm.getMapper(type.getType()).remove(entityId); return this; }
/** * Removal of components from a entity. * <p/> * Faster than {@link #remove(Class)}. * * @param type the type of component to remove from this entity * @return this EntityEdit for chaining */ public EntityEdit remove(ComponentType type) { cm.getMapper(type.getType()).remove(entityId); return this; }
/** * Faster adding of components into the entity. * <p> * Not necessary to use this, but in some cases you might need the extra * performance. * </p> * * @param component the component to add. Does not support packed or pooled. * @param type the type of the component * @return this EntityEdit for chaining * @see #create(Class) */ public EntityEdit add(Component component, ComponentType type) { if (type.isPooled) { throw new InvalidComponentException(component.getClass(), "Use EntityEdit#create(Class<Component>) for adding non-basic component types"); } ComponentMapper mapper = cm.getMapper(type.getType()); mapper.create(entityId); mapper.components.getData()[entityId] = component; return this; }
/** * Faster adding of components into the entity. * <p> * Not necessary to use this, but in some cases you might need the extra * performance. * </p> * * @param component the component to add. Does not support packed or pooled. * @param type the type of the component * @return this EntityEdit for chaining * @see #create(Class) */ public EntityEdit add(Component component, ComponentType type) { if (type.isPooled) { throw new InvalidComponentException(component.getClass(), "Use EntityEdit#create(Class<Component>) for adding non-basic component types"); } ComponentMapper mapper = cm.getMapper(type.getType()); mapper.create(entityId); mapper.components.getData()[entityId] = component; return this; }
private Bag<ComponentMapper> getAdditions(BitVector origin) { ComponentTypeFactory tf = cm.typeFactory; Bag<ComponentMapper> types = new Bag(ComponentMapper.class); for (int i = additions.nextSetBit(0); i >= 0; i = additions.nextSetBit(i + 1)) { if (!origin.get(i)) types.add(cm.getMapper(tf.getTypeFor(i).getType())); } return types; }
private Bag<ComponentMapper> getRemovals(BitVector origin) { ComponentTypeFactory tf = cm.typeFactory; Bag<ComponentMapper> types = new Bag(ComponentMapper.class); for (int i = removals.nextSetBit(0); i >= 0; i = removals.nextSetBit(i + 1)) { if (origin.get(i)) types.add(cm.getMapper(tf.getTypeFor(i).getType())); } return types; } }
private Bag<ComponentMapper> getAdditions(BitVector origin) { ComponentTypeFactory tf = cm.typeFactory; Bag<ComponentMapper> types = new Bag(ComponentMapper.class); for (int i = additions.nextSetBit(0); i >= 0; i = additions.nextSetBit(i + 1)) { if (!origin.get(i)) types.add(cm.getMapper(tf.getTypeFor(i).getType())); } return types; }
private Bag<ComponentMapper> getRemovals(BitVector origin) { ComponentTypeFactory tf = cm.typeFactory; Bag<ComponentMapper> types = new Bag(ComponentMapper.class); for (int i = removals.nextSetBit(0); i >= 0; i = removals.nextSetBit(i + 1)) { if (origin.get(i)) types.add(cm.getMapper(tf.getTypeFor(i).getType())); } return types; } }
/** * 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 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); }
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; } }
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; } }
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; } }