Exemplo n.º 1
0
  @Test
  public void addAndRemoveComponent() {
    Entity entity = new Entity();

    entity.add(new ComponentA());

    assertEquals(1, entity.getComponents().size());

    Bits componentBits = entity.getComponentBits();
    int componentAIndex = ComponentType.getIndexFor(ComponentA.class);

    for (int i = 0; i < componentBits.length(); ++i) {
      assertEquals(i == componentAIndex, componentBits.get(i));
    }

    assertNotNull(am.get(entity));
    assertNull(bm.get(entity));
    assertTrue(am.has(entity));
    assertFalse(bm.has(entity));

    entity.remove(ComponentA.class);

    assertEquals(0, entity.getComponents().size());

    for (int i = 0; i < componentBits.length(); ++i) {
      assertFalse(componentBits.get(i));
    }

    assertNull(am.get(entity));
    assertNull(bm.get(entity));
    assertFalse(am.has(entity));
    assertFalse(bm.has(entity));
  }
Exemplo n.º 2
0
 @Override
 protected void childRemoved(ManagedObject child) {
   if (child instanceof SceneNodeComponent) {
     SceneNodeComponent component = (SceneNodeComponent) child;
     component.scene = null;
     _components.remove(component.baseComponentType);
     _componentBits.clear(component.componentType);
   } else {
     SceneNode node = (SceneNode) child;
     node.scene = null;
     _childNodes.remove(node);
   }
 }
Exemplo n.º 3
0
 @Override
 protected final void childAdded(ManagedObject child) {
   if (child instanceof SceneNodeComponent) {
     SceneNodeComponent component = (SceneNodeComponent) child;
     int baseType = component.baseComponentType;
     if (_components.containsKey(baseType)) {
       throw new IllegalArgumentException(
           "Node already contains component: " + component.getClass().getName());
     }
     component.scene = scene;
     _components.put(baseType, component);
     _componentBits.set(component.componentType);
   } else {
     SceneNode node = (SceneNode) child;
     node.scene = scene;
     _childNodes.add(node);
   }
 }
Exemplo n.º 4
0
 /** Make entity ready for re-use. Will generate a new uuid for the entity. */
 protected void reset() {
   systemBits.clear();
   componentBits.clear();
   uuid = UUID.randomUUID();
 }