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

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

Introduction

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

Prototype

public void end() 

Source Link

Document

Releases the guarantee that the array returned by #begin() won't be modified.

Usage

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

License:Open Source License

public <T> void dispatch(EventType<T> type, T t) {
    SnapshotArray<EventListener<T>> list = getList(type, false);
    if (list == null)
        return;/*from   w w w.  j  a v a2  s .  c o m*/
    EventListener<T>[] items = list.begin();
    for (int i = 0, n = list.size; i < n; i++) {
        items[i].handle(type, t);
    }
    list.end();
}

From source file:de.longri.cachebox3.gui.views.CacheListView.java

License:Open Source License

private void setChangedFlagToAllItems() {
    if (listView == null)
        return;/*w ww  .  ja  v  a  2 s. c om*/
    SnapshotArray<ListViewItem> allItems = listView.items();
    Object[] actors = allItems.begin();
    for (int i = 0, n = allItems.size; i < n; i++) {
        CacheListItem item = (CacheListItem) actors[i];
        item.posOrBearingChanged();
    }
    allItems.end();
    Gdx.graphics.requestRendering();
}

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);/*from w  ww  .java2 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.DefaultGameView.java

License:Open Source License

@Override
public void clearLayer(Layer layer, boolean clearChildrenLayers) {
    EngineEntity layerEntity = layers.get(layer);
    SnapshotArray<Actor> childrenArray = layerEntity.getGroup().getChildren();
    Actor[] children = childrenArray.begin();
    for (int i = 0, n = childrenArray.size; i < n; i++) {
        Actor actor = children[i];/*  www  .  j  a v a2s.c om*/
        if (actor.getUserObject() instanceof EngineLayer) {
            if (clearChildrenLayers) {
                EngineLayer childrenLayer = (EngineLayer) actor.getUserObject();
                clearLayer(getLayerForEntity(childrenLayer), true);
            }
        } else if (actor.getUserObject() instanceof EngineEntity) {
            EngineEntity childEntityToRemove = (EngineEntity) actor.getUserObject();
            gameLoop.removeEntity(childEntityToRemove);
        } else {
            Gdx.app.error("GameView",
                    "GameView has a child that does not belong to an EngineEntity or its user object is not set.");
        }
    }
    childrenArray.end();

}

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());
        }//ww w.ja  v a2s. c o 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);
    }
}

From source file:net.mwplay.cocostudio.ui.widget.PageView.java

License:Apache License

public void nextView() {
    Gdx.app.debug("PageView", "Change to next view");
    SnapshotArray<Actor> children = this.getChildren();
    if (children.get(children.size - 1).getX() <= 0) {
        Gdx.app.debug("PageView", "Already last one, can't move to next.");
        return;/* w  w  w . j a va 2 s  . c o m*/
    }
    Actor[] actors = children.begin();
    float width = this.getWidth();
    for (Actor actor : actors) {
        if (actor != null) {
            actor.addAction(Actions.moveTo(actor.getX() - width, 0, 0.5f));
        }
    }
    children.end();
}

From source file:net.mwplay.cocostudio.ui.widget.PageView.java

License:Apache License

public void previousView() {
    Gdx.app.debug("PageView", "Change to previous view");
    SnapshotArray<Actor> children = this.getChildren();
    if (children.get(0).getX() >= 0) {
        Gdx.app.debug("PageView", "Already first one, can't move to previous.");
        return;// w  w  w.  ja  v  a 2 s . com
    }
    float width = this.getWidth();
    Actor[] actors = children.begin();
    for (Actor actor : actors) {
        if (actor != null) {
            actor.addAction(Actions.moveTo(actor.getX() + width, 0, 0.5f));
        }
    }
    children.end();
}