Exemple #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));
  }
Exemple #2
0
  @Test
  public void noComponents() {
    Entity entity = new Entity();

    assertEquals(0, entity.getComponents().size());
    assertTrue(entity.getComponentBits().isEmpty());
    assertNull(am.get(entity));
    assertNull(bm.get(entity));
    assertFalse(am.has(entity));
    assertFalse(bm.has(entity));
  }