Esempio n. 1
0
 /**
  * Faster removal of components from a entity.
  *
  * @param type the type of component to remove from this entity
  * @return this EntityEdit for chaining
  */
 public EntityEdit remove(ComponentType type) {
   if (componentBits.get(type.getIndex())) {
     world.getComponentManager().removeComponent(entity, type);
     componentBits.clear(type.getIndex());
   }
   return this;
 }
Esempio n. 2
0
  public <T extends Component> T create(Class<T> componentKlazz) {
    ComponentManager componentManager = world.getComponentManager();
    T component = componentManager.create(entity, componentKlazz);

    ComponentTypeFactory tf = world.getComponentManager().typeFactory;
    ComponentType componentType = tf.getTypeFor(componentKlazz);
    componentBits.set(componentType.getIndex());

    return component;
  }
Esempio n. 3
0
  /**
   * Faster adding of components into the entity.
   *
   * <p>Not necessary to use this, but in some cases you might need the extra performance.
   *
   * @param component the component to add
   * @param type the type of the component
   * @return this EntityEdit for chaining
   * @see #createComponent(Class)
   */
  public EntityEdit add(Component component, ComponentType type) {
    if (type.getTaxonomy() != Taxonomy.BASIC) {
      throw new InvalidComponentException(
          component.getClass(), "Use Entity#createComponent for adding non-basic component types");
    }
    world.getComponentManager().addComponent(entity, type, component);

    componentBits.set(type.getIndex());

    return this;
  }
Esempio n. 4
0
 /**
  * Add a component to this entity.
  *
  * @param component to add to this entity
  * @return this entity for chaining.
  */
 public Entity addComponent(Component component) {
   addComponent(component, ComponentType.getTypeFor(component.getClass()));
   return this;
 }
Esempio n. 5
0
 /**
  * Slower retrieval of components from this entity. Minimize usage of this, but is fine to use
  * e.g. when creating new entities and setting data in components.
  *
  * @param <T> the expected return component type.
  * @param type the expected return component type.
  * @return component that matches, or null if none is found.
  */
 public <T extends Component> T getComponent(Class<T> type) {
   return type.cast(getComponent(ComponentType.getTypeFor(type)));
 }
Esempio n. 6
0
 /**
  * Remove component by its type.
  *
  * @param type
  * @return this entity for chaining.
  */
 public Entity removeComponent(Class<? extends Component> type) {
   removeComponent(ComponentType.getTypeFor(type));
   return this;
 }