Search in sources :

Example 1 with RenderableComponent

use of com.gemserk.commons.artemis.components.RenderableComponent in project commons-gdx by gemserk.

the class RenderableComponentComparator method compare.

@Override
public int compare(Entity o1, Entity o2) {
    EntityComponents entity1Components = factory.get(o1);
    EntityComponents entity2Components = factory.get(o2);
    RenderableComponent c1 = entity1Components.renderableComponent;
    RenderableComponent c2 = entity2Components.renderableComponent;
    if (c1.renderable.getLayer() != c2.renderable.getLayer())
        return c1.renderable.getLayer() - c2.renderable.getLayer();
    OwnerComponent ownerComponent1 = entity1Components.ownerComponent;
    OwnerComponent ownerComponent2 = entity2Components.ownerComponent;
    int id1 = o1.getId();
    int id2 = o2.getId();
    if (ownerComponent1 != null) {
        Entity owner = ownerComponent1.getOwner();
        if (owner != null)
            id1 = owner.getId();
    }
    if (ownerComponent2 != null) {
        Entity owner = ownerComponent2.getOwner();
        if (owner != null)
            id2 = owner.getId();
    }
    if (id1 != id2)
        return id1 - id2;
    return c1.renderable.getSubLayer() - c2.renderable.getSubLayer();
}
Also used : Entity(com.artemis.Entity) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent)

Example 2 with RenderableComponent

use of com.gemserk.commons.artemis.components.RenderableComponent in project commons-gdx by gemserk.

the class RenderableSystem method enabled.

@Override
protected void enabled(Entity e) {
    RenderableComponent renderableComponent = RenderableComponent.get(e);
    OwnerComponent ownerComponent = OwnerComponent.get(e);
    Renderable renderable = renderableComponent.renderable;
    // this could be set on construction time
    renderable.setEntity(e);
    renderable.setId(e.getId());
    // if it has owner it uses the id of the owner... that was part of the original comparator
    if (ownerComponent != null && ownerComponent.getOwner() != null)
        renderable.setId(ownerComponent.getOwner().getId());
    // order the entity in the Layer, probably the same inside the layer
    for (int i = 0; i < renderLayers.size(); i++) {
        RenderLayer renderLayer = renderLayers.get(i);
        if (renderLayer.belongs(renderable)) {
            renderLayer.add(renderable);
            return;
        }
    }
}
Also used : Renderable(com.gemserk.commons.artemis.render.Renderable) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent)

Example 3 with RenderableComponent

use of com.gemserk.commons.artemis.components.RenderableComponent in project commons-gdx by gemserk.

the class OrderedByLayerEntitiesTest method shouldReturnEntityFirstIfGreaterLayerInverted.

@Test
public void shouldReturnEntityFirstIfGreaterLayerInverted() {
    World world = new World();
    Entity e1 = world.createEntity();
    Entity e2 = world.createEntity();
    e1.addComponent(new RenderableComponent(1));
    e2.addComponent(new RenderableComponent(0));
    orderedByLayerEntities.add(e1);
    orderedByLayerEntities.add(e2);
    assertSame(orderedByLayerEntities.get(0), e2);
    assertSame(orderedByLayerEntities.get(1), e1);
}
Also used : Entity(com.artemis.Entity) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent) World(com.artemis.World) Test(org.junit.Test)

Example 4 with RenderableComponent

use of com.gemserk.commons.artemis.components.RenderableComponent in project commons-gdx by gemserk.

the class OrderedByLayerEntitiesTest method shouldReturnSubEntityBeforeParentEntityIfLesserSubLayer.

@Test
public void shouldReturnSubEntityBeforeParentEntityIfLesserSubLayer() {
    World world = new World();
    Entity e1 = world.createEntity();
    Entity e3 = world.createEntity();
    e1.addComponent(new RenderableComponent(5, 0));
    e3.addComponent(new RenderableComponent(5, -1, true));
    e3.addComponent(new OwnerComponent(e1));
    orderedByLayerEntities.add(e1);
    orderedByLayerEntities.add(e3);
    assertSame(orderedByLayerEntities.get(0), e3);
    assertSame(orderedByLayerEntities.get(1), e1);
}
Also used : Entity(com.artemis.Entity) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent) World(com.artemis.World) Test(org.junit.Test)

Example 5 with RenderableComponent

use of com.gemserk.commons.artemis.components.RenderableComponent in project commons-gdx by gemserk.

the class OrderedByLayerEntitiesTest method testSubEntitiesAfterAnotherEntityIfParentIsAfter2.

@Test
public void testSubEntitiesAfterAnotherEntityIfParentIsAfter2() {
    World world = new World();
    Entity e1 = world.createEntity();
    Entity e2 = world.createEntity();
    Entity e3 = world.createEntity();
    e1.addComponent(new RenderableComponent(5));
    e2.addComponent(new RenderableComponent(5));
    e3.addComponent(new RenderableComponent(5, 2, true));
    e3.addComponent(new OwnerComponent(e1));
    orderedByLayerEntities.add(e2);
    orderedByLayerEntities.add(e1);
    orderedByLayerEntities.add(e3);
    assertSame(orderedByLayerEntities.get(0), e1);
    assertSame(orderedByLayerEntities.get(1), e3);
    assertSame(orderedByLayerEntities.get(2), e2);
}
Also used : Entity(com.artemis.Entity) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent) World(com.artemis.World) Test(org.junit.Test)

Aggregations

RenderableComponent (com.gemserk.commons.artemis.components.RenderableComponent)18 Entity (com.artemis.Entity)16 World (com.artemis.World)15 Test (org.junit.Test)15 OwnerComponent (com.gemserk.commons.artemis.components.OwnerComponent)13 Renderable (com.gemserk.commons.artemis.render.Renderable)2