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

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

Introduction

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

Prototype

public void clear() 

Source Link

Usage

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

License:Apache License

@Override
public void onCollide(Component other) {
    CElastic otherCE = null;//from   www.java2  s.  c  o m
    if (other instanceof CElastic)
        otherCE = (CElastic) other;
    if (otherCE != null && getId() > otherCE.getId())
        return;
    boolean success = elasticCollision(other);
    overlaps.add(other);
    if (otherCE != null)
        otherCE.overlaps.add(this);
    if (!success)
        return;
    if (overlaps.size == 1 && (otherCE == null || otherCE.overlaps.size == 1))
        return;
    ObjectSet<Component> visitedSet = new ObjectSet<Component>();
    for (int i = 0; i < 100; i++) {
        if (!collideIteration(visitedSet)) {
            if (i >= 15) {
                System.out.println("WARNING: chained elastic collision took " + (i + 1) + " iterations");
            }
            return;
        }
        visitedSet.clear();
    }
    throw new RuntimeException("chained elastic collision not converging");
}

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

License:Open Source License

@SuppressWarnings("unchecked")
private void autoPlace() {
    if (placed.size > 0) {
        ObjectSet<Creature> tmp = Pools.obtain(ObjectSet.class);
        tmp.addAll(placed);/*from w w  w  .j  av a 2s  .co m*/
        for (Creature c : tmp) {
            removeFromPlaced(c);
        }
        tmp.clear();
        Pools.free(tmp);
    }
    Array<Grid2D.Coordinate> coordinates = Pools.obtain(Array.class);
    Set<Map.Entry<Grid2D.Coordinate, Fraction>> spawns = world.level.getElements(LevelElementType.spawn);
    for (Map.Entry<Grid2D.Coordinate, Fraction> e : spawns) {
        if (e.getValue() == world.viewer.fraction) {
            coordinates.add(e.getKey());
        }
    }
    coordinates.shuffle();
    int usedCount = Math.min(creatures.size, coordinates.size);
    Array<Creature> toPlace = Pools.obtain(Array.class);
    toPlace.addAll(creatures);
    toPlace.shuffle();
    toPlace.truncate(usedCount);
    for (Creature creature : toPlace) {
        Grid2D.Coordinate coordinate = coordinates.pop();
        place(creature, coordinate.x(), coordinate.y());
    }
    toPlace.clear();
    coordinates.clear();
    Pools.free(toPlace);
    Pools.free(coordinates);
}

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();//from ww  w.  j  a  v a2  s  .  com

        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 Result recursive(World world, Creature target, ObjectSet<Coordinate> checked,
        ObjectSet<Coordinate> toCheck, int depth) {
    if (toCheck.size == 0) {
        cleanUp();/*from   w w  w  .  ja va  2 s . c o 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);
}

From source file:com.vlaaad.dice.services.GameServicesMultiplayer.java

License:Open Source License

@SuppressWarnings("unchecked")
public void loadInvitations(InvitationBuffer invitations) {
    ObjectSet<String> tmp = Pools.obtain(ObjectSet.class);
    tmp.addAll(invites);//from   w  w  w  .j a v a2  s .com
    invites.clear();
    for (Invitation invitation : invitations) {
        invites.add(invitation.getInvitationId());
        if (!tmp.contains(invitation.getInvitationId())) {
            showInvitation(invitation);
        }
    }
    tmp.clear();
    Pools.free(tmp);
    Gdx.app.postRunnable(new Runnable() {
        @Override
        public void run() {
            invitesDispatcher.setState(invites.size);
        }
    });
}

From source file:com.vlaaad.dice.ui.windows.DieSettingsWindow.java

License:Open Source License

@Override
protected void doShow(final Params params) {
    Table content = new Table(Config.skin);
    content.setBackground("ui-store-window-background");
    content.defaults().pad(4);//from  w  w w . ja  v  a 2 s  .  c  o  m
    content.setTouchable(Touchable.enabled);

    final LocLabel infoLabel = new LocLabel(
            "ui-renames-left", Thesaurus.params().with("count", String.valueOf(params.die.renames))
                    .with("free-renames", "free-renames." + Thesaurus.Util.countForm(params.die.renames)),
            StoreWindow.INACTIVE);
    infoLabel.setWrap(true);
    infoLabel.setAlignment(Align.center);

    final StringSpin nameSpin = new StringSpin(4, 10, Config.thesaurus.localize(params.die.nameLocKey()));
    Container inner = new Container(nameSpin);
    inner.padTop(3);
    final Container nameContainer = new Container(inner);
    nameContainer.setBackground(Config.skin.getDrawable("ui/button/name-change-background"));
    final Button changeNameButton = new Button(Config.skin);
    final Thesaurus thesaurus = Config.assetManager.get("names.yml", Thesaurus.class);
    final Array<ThesaurusData> values = thesaurus.values();
    final Item coin = Config.items.get("coin");
    updateChangeNameButton(changeNameButton, params);
    changeNameButton.addListener(new ChangeListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            ObjectSet<ThesaurusData> existingNames = Pools.obtain(ObjectSet.class);
            for (Die die : params.userData.dice()) {
                existingNames.add(thesaurus.getData(die.name.toLowerCase()));
            }
            ThesaurusData newName = values.random();
            while (existingNames.contains(newName)) {
                newName = values.random();
            }
            existingNames.clear();
            Pools.free(existingNames);
            final ThesaurusData chosenName = newName;
            changeNameButton.setDisabled(true);
            nameSpin.setText(Config.thesaurus.localize(newName.key), new Runnable() {
                @Override
                public void run() {
                    params.die.name = chosenName.key;
                    if (params.die.renames > 0) {
                        params.die.renames -= 1;
                        infoLabel.setParams(Thesaurus.params().with("count", String.valueOf(params.die.renames))
                                .with("free-renames",
                                        "free-renames." + Thesaurus.Util.countForm(params.die.renames)));
                    } else {
                        params.userData.incrementItemCount(coin, -1);
                    }
                    updateChangeNameButton(changeNameButton, params);
                    fire(RefreshEvent.INSTANCE);
                }
            });
        }
    });

    content.add(new LocLabel("ui-select-die-name")).row();
    content.add(new Tile("ui-creature-info-line")).width(80).padTop(0).row();
    content.add(nameContainer).size(70, 21).row();
    content.add(changeNameButton).size(100, 21).padBottom(0).row();
    content.add(infoLabel).width(110).row();

    table.add(content);
}