コード例 #1
0
ファイル: Entity.java プロジェクト: dreamsxin/MalletEngine
  public final void removeComponent(final Component _component) {
    _component.setParent(null); // Required by j2Objc conversion, causes memory-leak otherwise
    components.remove(_component);

    final EventController controller = _component.getComponentEventController();
    eventSystem.removeEventHandler(controller);
  }
コード例 #2
0
ファイル: Entity.java プロジェクト: dreamsxin/MalletEngine
  /**
   * Add a component to the Entity and set its parent to the Entity The Component should not be
   * owned by another Component, it could get messy!
   */
  public final void addComponent(final Component _component) {
    _component.setParent(this);
    components.add(_component);

    final EventController controller = _component.getComponentEventController();
    controller.setAddEventInterface(eventSystem);
    eventSystem.addEventHandler(controller);
  }
コード例 #3
0
ファイル: Entity.java プロジェクト: dreamsxin/MalletEngine
  /** Return all the components with the designated name */
  public final int getComponentsByName(final String _name, final ArrayList<Component> _components) {
    for (Component component : components) {
      if (component.isName(_name) == true) {
        _components.add(component);
      }
    }

    return _components.size();
  }
コード例 #4
0
ファイル: Entity.java プロジェクト: dreamsxin/MalletEngine
  /**
   * Get the Components that have the same Group name and return them in an ArrayList. NOTE: A new
   * ArrayList is created each time this function is called.
   */
  public final ArrayList<Component> getComponentByGroupID(final int _groupID) {
    final ArrayList<Component> group = new ArrayList<Component>();
    for (final Component component : components) {
      if (component.isGroupID(_groupID) == true) {
        group.add(component);
      }
    }

    return group;
  }
コード例 #5
0
ファイル: Entity.java プロジェクト: dreamsxin/MalletEngine
  /**
   * Get the Components that have the same Group name and return them in an ArrayList. NOTE: A new
   * ArrayList is created each time this function is called.
   */
  public final int getComponentByGroup(
      final String _group, final ArrayList<Component> _components) {
    for (final Component component : components) {
      if (component.isGroup(_group) == true) {
        _components.add(component);
      }
    }

    return _components.size();
  }
コード例 #6
0
ファイル: Entity.java プロジェクト: dreamsxin/MalletEngine
  /**
   * Get a Component with the designated name. If there is more than one component with that name,
   * then it will return the first one it finds.
   */
  public final Component getComponentByName(final String _name) {
    final int size = components.size();
    Component component = null;

    for (int i = 0; i < size; ++i) {
      component = components.get(i);
      if (component.isName(_name) == true) {
        return component;
      }
    }

    return null;
  }
コード例 #7
0
ファイル: Entity.java プロジェクト: dreamsxin/MalletEngine
  /**
   * Call when you wish the Entity to be decalred dead. An Entity decalred destroyed, will be
   * removed by the Entity System when appropriate.
   */
  public final void destroy() {
    final Component.ReadyCallback readyDestroy =
        new Component.ReadyCallback<Component>() {
          private final ArrayList<Component> toDestroy = new ArrayList<Component>(components);

          public void ready(final Component _component) {
            if (toDestroy.remove(_component) == true) {
              if (toDestroy.isEmpty() == true) {
                // System.out.println( "Entity destroyed." ) ;
                destroy = true;
              }
            }
          }
        };

    for (final Component component : components) {
      component.readyToDestroy(readyDestroy);
    }
  }