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

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

Introduction

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

Prototype

public ObjectSet() 

Source Link

Document

Creates a new set with an initial capacity of 32 and a load factor of 0.8.

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);// ww w. j  av a 2 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  a  va 2s  .c  o m*/
    this.excludedComponents = newExcludedComponents;
    return this;
}

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

License:Apache License

@Override
public void onCollide(Component other) {
    CElastic otherCE = null;//from w  w  w . ja v a 2 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.behaviours.processors.user.UserTurnProcessor.java

License:Open Source License

@Override
public IFuture<TurnResponse> process(final TurnParams params) {
    final Future<TurnResponse> future = new Future<TurnResponse>();
    final World world = params.creature.world;
    this.world = world;
    final Creature creature = params.creature;
    final UiController ui = world.getController(UiController.class);
    final ObjectSet<Grid2D.Coordinate> available = new ObjectSet<Grid2D.Coordinate>();
    available.addAll(params.availableCells);

    clickListener = new ClickListener() {
        @Override/*from w w  w  .j  a v  a2  s  .c  om*/
        public void clicked(InputEvent event, float x, float y) {
            if (event.isCancelled())
                return;
            Vector2 c = world.getController(ViewController.class)
                    .stageToWorldCoordinates(new Vector2(event.getStageX(), event.getStageY()));
            final Grid2D.Coordinate coordinate = new Grid2D.Coordinate((int) c.x, (int) c.y);
            if (available.contains(coordinate)) {
                world.stage.removeListener(this);
                final ClickListener mainListener = this;
                confirm = new Image(Config.skin, "selection/turn-confirmation");
                back = new Tile("selection/turn-confirmation-background");
                confirm.setPosition(coordinate.x() * ViewController.CELL_SIZE,
                        coordinate.y() * ViewController.CELL_SIZE);
                back.setPosition(confirm.getX(), confirm.getY());
                world.getController(ViewController.class).notificationLayer.addActor(confirm);
                world.getController(ViewController.class).selectionLayer.addActor(back);
                confirmListener = new ClickListener() {
                    @Override
                    public void clicked(InputEvent event, float x, float y) {
                        if (event.isCancelled())
                            return;
                        Vector2 cell = world.getController(ViewController.class)
                                .stageToWorldCoordinates(new Vector2(event.getStageX(), event.getStageY()));
                        confirm.remove();
                        back.remove();
                        world.stage.removeListener(this);
                        if (coordinate.x() == (int) cell.x && coordinate.y() == (int) cell.y) {
                            UserTurnProcessor.this.cancel();
                            future.happen(new TurnResponse<Grid2D.Coordinate>(TurnResponse.TurnAction.MOVE,
                                    coordinate));
                        } else {
                            world.stage.addListener(mainListener);
                            mainListener.clicked(event, x, y);
                        }
                    }
                };
                world.stage.addListener(confirmListener);
            }
        }
    };
    world.stage.addListener(clickListener);

    Array<Ability> professionAbilities = creature.description.profession
            .getAvailableAbilities(creature.getCurrentLevel());
    boolean professionTutorial = false;
    if (professionAbilities.size > 0) {
        for (Ability ability : professionAbilities) {
            ProfessionAbilityIcon icon = ui.getProfessionIcon(ability);
            icon.addListener(createListener(ability, creature, clickListener, world, future));
        }
        if (!world.viewer.tutorialProvider.isProfessionAbilitiesTutorialCompleted()) {
            professionTutorial = true;
            Tutorial.whenAllTutorialsEnded(new Runnable() {
                @Override
                public void run() {
                    Tutorial.TutorialResources resources = Tutorial.resources()
                            .with("tutorial-provider", world.viewer.tutorialProvider).with("world", world)
                            .with("stage", world.stage);
                    new Tutorial(resources, DiceTutorial.professionAbilitiesTasks()).start();
                }
            });
        }
    }
    if (!professionTutorial && !world.viewer.tutorialProvider.isPlayPotionsTutorialCompleted()
            && world.viewer.hasPotions()) {
        Tutorial.whenAllTutorialsEnded(new Runnable() {
            @Override
            public void run() {
                Tutorial.TutorialResources resources = Tutorial.resources()
                        .with("tutorial-provider", world.viewer.tutorialProvider).with("world", world)
                        .with("stage", world.stage);
                new Tutorial(resources, DiceTutorial.playPotionsTasks()).start();
            }
        });
    }
    if (ui != null) {
        ui.potionsButton.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                new PotionsPlayWindow()
                        .show(new PotionsPlayWindow.Params(creature, world, new PotionsPlayWindow.Callback() {
                            @Override
                            public void usePotion(Ability potion, Potion.ActionType action) {
                                UserTurnProcessor.this.cancel();
                                future.happen(new TurnResponse<Tuple2<Ability, Potion.ActionType>>(
                                        TurnResponse.TurnAction.POTION, Tuple2.make(potion, action)));
                            }
                        }));
            }
        });
    }

    return future;
}

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

License:Open Source License

private void showTileBackgrounds() {
    ObjectSet<Grid2D.Coordinate> processed = new ObjectSet<Grid2D.Coordinate>();
    final ArrayList<Grid2D.Coordinate> list = new ArrayList<Grid2D.Coordinate>(
            world.level.getCoordinates(tile));
    Collections.sort(list, new Comparator<Grid2D.Coordinate>() {
        @Override/*w  w  w. j  av  a 2 s.  c  o  m*/
        public int compare(Grid2D.Coordinate o1, Grid2D.Coordinate o2) {
            return o2.y() - o1.y();
        }
    });
    for (Grid2D.Coordinate coordinate : list) {
        showTileBackground(processed, coordinate.x() - 1, coordinate.y());
        showTileBackground(processed, coordinate.x() + 1, coordinate.y());
        showTileBackground(processed, coordinate.x(), coordinate.y() - 1);
        showTileBackground(processed, coordinate.x(), coordinate.y() + 1);
        showTileBackground(processed, coordinate.x() + 1, coordinate.y() + 1);
        showTileBackground(processed, coordinate.x() - 1, coordinate.y() + 1);
        showTileBackground(processed, coordinate.x() + 1, coordinate.y() - 1);
        showTileBackground(processed, coordinate.x() - 1, coordinate.y() - 1);
        showTransitions(coordinate.x(), coordinate.y());
    }
}

From source file:me.scarlet.undertailor.engine.events.EventHelper.java

License:Open Source License

/**
 * Registers a new {@link Function} as an event handler.
 * //from  ww w  .j av  a2  s . c  om
 * <p>The Object array passed to the function are the
 * parameters set upon the event, with the first
 * parameter always being whether or not the event had
 * been processed by a previous handler. The function
 * must return whether or not it has done anything in
 * response to the event.</p>
 * 
 * <p>All handlers for an event will be processed
 * regardless of what occurs. If any handler returns
 * true for processing, the system will not pass the
 * event down to the next object in the current
 * chain.</p>
 * 
 * @param eventId the id to listen for
 * @param handler the handler that responds to the event
 */
public void registerHandler(String eventId, Function<Event, Boolean> handler) {
    ObjectSet<Function<Event, Boolean>> handlerSet = this.handlers.get(eventId);

    if (handlerSet == null) {
        handlerSet = new ObjectSet<>();
        this.handlers.put(eventId, handlerSet);
    }

    handlerSet.add(handler);
}

From source file:me.scarlet.undertailor.engine.overworld.map.ObjectLayer.java

License:Open Source License

ObjectLayer() {
    this.shapes = new ObjectSet<>();
    this.points = new ObjectMap<>();
}

From source file:me.scarlet.undertailor.engine.overworld.OverworldController.java

License:Open Source License

/**
 * Sets the provided {@link WorldRoom} as this
 * {@link OverworldController}'s room.//from   w  w  w  . ja v  a  2  s  .com
 * 
 * <p>It is recommended to always play at least an exit
 * transition to hide the previous room from view,
 * otherwise the game may look as if suspended in limbo
 * during room loading.</p>
 * 
 * @param room the new room for the Overworld to use
 * @param targetEntrypoint the entrypoint to spawn the
 *        character object at, or null to spawn at 0, 0
 * @param transitions whether or not to play transitions
 */
public void setRoom(WorldRoom room, String targetEntrypoint, boolean transitions) {
    if (room.isDestroyed()) {
        log.warn(
                "attempted to submit a destroyed worldroom to overworldcontroller; cannot accept destroyed room");
        return;
    }

    Task roomTask = new Task() {

        boolean set;
        ObjectSet<WorldObject> persistent;

        {
            this.set = false;
            this.persistent = new ObjectSet<>();
        }

        public boolean process() {
            if (!set) {
                if (OverworldController.this.room != null) {
                    OverworldController.this.room.getObjects().forEach(obj -> {
                        if (obj.isPersistent()) {
                            this.persistent.add(obj);
                        }
                    });

                    OverworldController.this.room.release(OverworldController.this);
                    OverworldController.this.room = null;
                }

                room.claim(OverworldController.this);
                set = true;
            }

            if (room.poke()) {
                OverworldController.this.room = room;
                // update the camera since the room has changed
                camera.fixPosition();

                // register each object first
                this.persistent.forEach(room::registerObject);

                // did we have an entrypoint to go to?
                Entrypoint target = null;
                if (targetEntrypoint != null) {
                    target = OverworldController.this.room.getEntrypoint(targetEntrypoint);
                }

                Event evt = new Event(Event.EVT_PERSIST, room, target != null);
                if (target != null) {
                    Vector2 spawn = target.getTargetSpawnpoint();
                    if (spawn != null && OverworldController.this.character != null) {
                        OverworldController.this.character.setPosition(spawn);
                    }
                }

                this.persistent.forEach(obj -> {
                    obj.callEvent(evt);
                });

                return false;
            }

            OverworldController.this.callEvent(new Event(Event.EVT_ROOMCHANGE));
            return true;
        }
    };

    Scheduler sched = this.environment.getScheduler();
    if (transitions) {
        sched.registerTask(this.transitions.getB(), true); // exit
        sched.registerTask(roomTask, true);
        sched.registerTask(this.transitions.getA(), true); // entry
    } else {
        sched.registerTask(roomTask, true);
    }
}

From source file:me.scarlet.undertailor.engine.overworld.WorldObject.java

License:Open Source License

public WorldObject() {
    this.id = nextId++;
    this.destroyed = false;
    this.boundingQueue = new ObjectSet<>();
    this.def = new BodyDef();
    this.persistent = false;
    this.visible = true;
    this.layer = 0;

    this.def.active = true;
    this.def.awake = true;
    this.def.fixedRotation = true;
    this.def.type = BodyType.DynamicBody;

    this.groupId = -1;
    this.canCollide = true;
    this.events = new EventHelper(this);
}

From source file:me.scarlet.undertailor.engine.overworld.WorldRoom.java

License:Open Source License

public WorldRoom(Tilemap map) {
    this.destroyed = false;
    this.prepared = false;
    this.events = new EventHelper(this);
    this.bodyQueue = new ObjectSet<>();
    this.entrypointQueue = new ObjectSet<>();

    this.tilemap = map;
    this.controller = null;
    this.obj = new ObjectSet<>();
    this.entrypoints = new ObjectMap<>();
    this.opacityMapping = new IntFloatMap();
    this.collisionLayers = new ObjectMap<>();
    this.renderOrder = new Array<>(true, 16);
    this.disabledCollision = new ObjectSet<>();
}