Example usage for com.badlogic.gdx.utils ObjectSet add

List of usage examples for com.badlogic.gdx.utils ObjectSet add

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils ObjectSet add.

Prototype

public boolean add(T key) 

Source Link

Document

Returns true if the key was not already in the set.

Usage

From source file:com.github.antag99.retinazer.FamilyConfig.java

License:Open Source License

@SafeVarargs
public final FamilyConfig with(Class<? extends Component>... componentTypes) {
    ObjectSet<Class<? extends Component>> newComponents = new ObjectSet<>();
    newComponents.addAll(components);/* w w w  .  j  av a2  s.c o  m*/
    for (Class<? extends Component> componentType : componentTypes) {
        if (newComponents.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        if (excludedComponents.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        newComponents.add(componentType);
    }
    this.components = newComponents;
    return this;
}

From source file:com.github.antag99.retinazer.FamilyConfig.java

License:Open Source License

@SafeVarargs
public final FamilyConfig exclude(Class<? extends Component>... componentTypes) {
    ObjectSet<Class<? extends Component>> newExcludedComponents = new ObjectSet<>();
    newExcludedComponents.addAll(excludedComponents);
    for (Class<? extends Component> componentType : componentTypes) {
        if (newExcludedComponents.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        if (components.contains(componentType))
            throw new IllegalArgumentException(componentType.getName());
        newExcludedComponents.add(componentType);
    }/*from  w w  w. j  ava 2  s  .com*/
    this.excludedComponents = newExcludedComponents;
    return this;
}

From source file:com.kotcrab.vis.runtime.util.VisBagUtils.java

License:Apache License

public static <E> ObjectSet<E> toSet(ImmutableBag<E> bag) {
    ObjectSet<E> array = new ObjectSet<E>(bag.size());

    for (E element : bag)
        array.add(element);

    return array;
}

From source file:com.matthewmichelotti.collider.demos.comps.CElastic.java

License:Apache License

private boolean collideIteration(ObjectSet<Component> visitedSet) {
    visitedSet.add(this);
    boolean changed = false;
    for (Component c : overlaps) {
        if (visitedSet.contains(c))
            continue;
        changed |= elasticCollision(c);//from w  w w .j  a  v a2 s. c  om
    }
    for (Component c : overlaps) {
        if (c instanceof CElastic) {
            if (visitedSet.contains(c))
                continue;
            changed |= ((CElastic) c).collideIteration(visitedSet);
        }
    }
    return changed;
}

From source file:com.vlaaad.dice.game.actions.imp.ChainLightning.java

License:Open Source License

private IActionResult calcResult(Ability ability, Creature caster, Creature target, World world) {
    ObjectSet<Creature> affected = tmpSet;
    Array<Creature> chain = new Array<Creature>();
    chain.add(target);/*from  ww  w . j  ava2s  .c om*/
    affected.add(target);

    // i == 1 because we already have initial target
    RandomController random = world.getController(RandomController.class);

    for (int i = 1; i < targets; i++) {
        Creature last = chain.peek();
        tmpArray2.clear();
        Array<Creature> neighbours = getNeighbourCreatures(world, last.getX(), last.getY(), tmpArray2);
        Iterator<Creature> it = neighbours.iterator();
        while (it.hasNext()) {
            Creature toCheck = it.next();
            if (affected.contains(toCheck))
                it.remove();
        }
        if (neighbours.size == 0) {
            break;
        } else if (neighbours.size == 1) {
            addToChain(affected, chain, neighbours.first());
        } else {
            Array<Creature> betterTargets = tmpArray3;
            betterTargets.clear();
            for (Creature toCheck : neighbours) {
                if (toCheck.get(Attribute.defenceFor(attackType)) < attackLevel) {
                    betterTargets.add(toCheck);
                }
            }
            if (betterTargets.size > 0) {
                addToChain(affected, chain, random.random(betterTargets));
            } else {
                addToChain(affected, chain, random.random(neighbours));
            }
        }
    }

    ObjectIntMap<Creature> expResults = new ObjectIntMap<Creature>();
    Array<Creature> killed = new Array<Creature>();

    for (Creature creature : chain) {
        if (creature.get(Attribute.defenceFor(attackType)) < attackLevel) { // killed
            if (creature.player != caster.player) {
                expResults.getAndIncrement(caster, 0, ExpHelper.expForKill(caster, creature));
            }
            killed.add(creature);
        } else { // survived
            expResults.put(creature, ExpHelper.expForDefence(caster, creature));
        }
    }

    tmpSet.clear();
    tmpArray2.clear();
    tmpArray3.clear();

    return new ChainLightningResult(caster, ability, chain, killed, expResults);
}

From source file:com.vlaaad.dice.game.actions.imp.ChainLightning.java

License:Open Source License

private void addToChain(ObjectSet<Creature> affected, Array<Creature> chain, Creature toAdd) {
    if (!affected.add(toAdd))
        throw new IllegalStateException(toAdd + " should not be affected now!");
    chain.add(toAdd);//from  w w w.  j  a va2 s.  c  o  m
}

From source file:com.vlaaad.dice.game.world.controllers.ViewController.java

License:Open Source License

private void showTileBackground(ObjectSet<Grid2D.Coordinate> processed, int x, int y) {
    if (world.level.getElement(tile, x, y) != null)
        return;/*w  w w .java 2s . c  o  m*/
    Grid2D.Coordinate c = new Grid2D.Coordinate(x, y);
    if (!processed.add(c))
        return;
    String top = world.level.getElement(tile, x, y + 1);
    String bottom = world.level.getElement(tile, x, y - 1);
    String left = world.level.getElement(tile, x - 1, y);
    String right = world.level.getElement(tile, x + 1, y);

    String topLeft = world.level.getElement(tile, x - 1, y + 1);
    String topRight = world.level.getElement(tile, x + 1, y + 1);
    String bottomLeft = world.level.getElement(tile, x - 1, y - 1);
    String bottomRight = world.level.getElement(tile, x + 1, y - 1);
    if (topLeft != null && top == null && left == null) {
        //use opposite
        addBottomRightCorner(x, y, topLeft, tileBackgroundLayer);
    }
    if (topRight != null && top == null && right == null) {
        // tile is bottom right -> corner is opposite of tile
        addBottomLeftCorner(x, y, topRight, tileBackgroundLayer);
    }

    if (top != null) {
        boolean hasLeft = world.level.getElement(tile, x - 1, y + 1) != null;
        boolean hasRight = world.level.getElement(tile, x + 1, y + 1) != null;
        String type;
        if (hasLeft && hasRight) {
            type = "both";
        } else if (hasLeft) {
            type = "left";
        } else if (hasRight) {
            type = "right";
        } else {
            type = "none";
        }
        addOverHang(x, y, top, type, tileBackgroundLayer);
        addTopOutline(x, y, top, tileBackgroundLayer);
    }
    if (bottom != null) {
        addBottomOutline(x, y, bottom, tileBackgroundLayer);
    }
    if (left != null) {
        addLeftOutline(x, y, left, tileBackgroundLayer);
    }
    if (right != null) {
        addRightOutline(x, y, right, tileBackgroundLayer);
    }
    if (bottomLeft != null && bottom == null && left == null) {
        addTopRightCorner(x, y, bottomLeft, tileBackgroundLayer);
    }
    if (bottomRight != null && bottom == null && right == null) {
        addTopLeftCorner(x, y, bottomRight, tileBackgroundLayer);
    }
}

From source file:com.vlaaad.dice.game.world.util.DistanceFiller.java

License:Open Source License

private static Result recursive(World world, Creature creature, Creature.CreatureRelation relation,
        ObjectSet<Coordinate> checked, ObjectSet<Coordinate> toCheck, int depth) {
    if (toCheck.size == 0) {
        cleanUp();// w  w  w.ja  v  a2s .  co m

        return result.set(-1, -1, -1);
    }
    for (Coordinate coordinate : toCheck) {
        checked.add(coordinate);
        WorldObject object = world.get(coordinate.x, coordinate.y);
        if (object instanceof Creature) {
            Creature check = (Creature) object;
            if (creature.inRelation(relation, check)) {
                cleanUp();
                return result.set(depth, coordinate.x, coordinate.y);
            }
        }
    }
    ObjectSet<Coordinate> toFill = tmp3;
    toFill.clear();
    toFill.addAll(toCheck);
    toCheck.clear();

    for (Coordinate coordinate : toFill) {
        addNeighbours(world, coordinate.x, coordinate.y, checked, toCheck);
    }
    return recursive(world, creature, relation, checked, toCheck, depth + 1);
}

From source file:com.vlaaad.dice.game.world.util.DistanceFiller.java

License:Open Source License

private static void addNeighbour(World world, int x, int y, ObjectSet<Coordinate> checked,
        ObjectSet<Coordinate> toCheck) {
    if (!world.inBounds(x, y) || !world.level.exists(LevelElementType.tile, x, y))
        return;/* w w  w . ja  va2  s  . c o m*/
    Coordinate coordinate = Coordinate.obtain(x, y);
    if (checked.contains(coordinate)) {
        coordinate.free();
        return;
    }
    toCheck.add(coordinate);

}

From source file:com.vlaaad.dice.game.world.util.DistanceFiller.java

License:Open Source License

private static Result recursive(World world, Creature target, ObjectSet<Coordinate> checked,
        ObjectSet<Coordinate> toCheck, int depth) {
    if (toCheck.size == 0) {
        cleanUp();//w  w w . j a  va2 s .co  m

        return result.set(-1, -1, -1);
    }
    for (Coordinate coordinate : toCheck) {
        checked.add(coordinate);
        WorldObject object = world.get(coordinate.x, coordinate.y);
        if (object instanceof Creature) {
            Creature creature = (Creature) object;
            if (creature == target) {
                cleanUp();
                return result.set(depth, coordinate.x, coordinate.y);
            }
        }
    }
    ObjectSet<Coordinate> toFill = tmp3;
    toFill.clear();
    toFill.addAll(toCheck);
    toCheck.clear();

    for (Coordinate coordinate : toFill) {
        addNeighbours(world, coordinate.x, coordinate.y, checked, toCheck);
    }
    return recursive(world, target, checked, toCheck, depth + 1);
}