Example usage for com.badlogic.gdx.utils SnapshotArray removeValue

List of usage examples for com.badlogic.gdx.utils SnapshotArray removeValue

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils SnapshotArray removeValue.

Prototype

public boolean removeValue(T value, boolean identity) 

Source Link

Usage

From source file:com.vlaaad.dice.game.world.events.EventDispatcher.java

License:Open Source License

public <T> void remove(EventType<T> type, EventListener<T> listener) {
    SnapshotArray<EventListener<T>> list = getList(type, false);
    if (list == null)
        return;/* w w w  .j ava2s.  c om*/
    list.removeValue(listener, true);
}

From source file:es.eucm.ead.engine.collision.BoundingAreaBuilder.java

License:Open Source License

private static Polygon getBoundingPolygon(EngineEntity entity, Group sceneContentGroup, Group group) {
    SnapshotArray<Vector2> allPoints = new SnapshotArray<Vector2>();

    for (Polygon polygon : getColliders(entity)) {
        for (int i = 0; i < polygon.getVertices().length; i += 2) {
            Vector2 tmp = Pools.obtain(Vector2.class);
            tmp.set(polygon.getVertices()[i], polygon.getVertices()[i + 1]);
            group.localToAscendantCoordinates(sceneContentGroup, tmp);
            allPoints.add(tmp);//  w  w  w  . j  a va  2 s .c o  m
        }
    }

    if (allPoints.size == 0) {
        return null;
    }

    // Remove duplicates, if any. Algorithm works better this way
    Object[] pointsToIterate = allPoints.begin();
    int size = allPoints.size;
    for (int i = 0; i < size; i++) {
        Vector2 pointA = (Vector2) pointsToIterate[i];
        for (int j = 0; j < size; j++) {
            Vector2 pointB = (Vector2) pointsToIterate[j];
            if (j != i && pointA.equals(pointB)) {
                allPoints.removeValue(pointB, true);
            }
        }
    }
    allPoints.end();

    // To array
    float[] points = toSimpleArray(allPoints);
    FloatArray floatArray = convexHull.computePolygon(points, false);
    // Remove the last point, since its the first one (duplicate)
    floatArray.removeRange(floatArray.size - 2, floatArray.size - 1);
    Polygon polygon = new Polygon();
    polygon.setVertices(floatArray.toArray());
    return polygon;
}

From source file:es.eucm.ead.engine.systems.behaviors.TimersSystem.java

License:Open Source License

@Override
public void doProcessEntity(Entity entity, float delta) {
    TimersComponent timers = entity.getComponent(TimersComponent.class);

    SnapshotArray<RuntimeTimer> timerList = timers.getBehaviors();
    Object[] timerArray = timerList.begin();
    for (int j = 0, n = timerList.size; j < n; j++) {
        RuntimeTimer timer = (RuntimeTimer) timerArray[j];
        if (!evaluateCondition(timer.getCondition()))
            continue;

        int count = timer.update(delta);
        for (int i = 0; i < count; i++) {
            addEffects(entity, timer.getEffects());
        }// w ww  .ja v a2 s  .  co  m
        if (timer.isDone()) {
            timerList.removeValue(timer, true);
        }
    }
    timerList.end();

    // If no timers remaining, remove the component
    if (timers.getBehaviors().size == 0) {
        entity.remove(TimersComponent.class);
    }
}