com.badlogic.gdx.utils.ObjectSet Java Examples
The following examples show how to use
com.badlogic.gdx.utils.ObjectSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CElastic.java From collider with Apache License 2.0 | 6 votes |
@Override public void onCollide(Component other) { CElastic otherCE = null; 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"); }
Example #2
Source File: GameServicesMultiplayer.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public void loadInvitations(InvitationBuffer invitations) { ObjectSet<String> tmp = Pools.obtain(ObjectSet.class); tmp.addAll(invites); 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); } }); }
Example #3
Source File: LocalSession.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public LocalSession(final LocalMultiplayer multiplayer, final String otherPlayerId) { this.multiplayer = multiplayer; this.otherPlayerId = otherPlayerId; setVariant(Config.pvpModes.get("global-2").variant); me = new IParticipant() { @Override public String getDisplayedName() { return multiplayer.participantId; } @Override public String getImageUrl() { return "https://pp.vk.me/c307401/v307401067/e8db/rg1r1GJ-dME.jpg"; } @Override public String getId() { return multiplayer.participantId; } @Override public String toString() { return getId(); } }; other = new IParticipant() { @Override public String getDisplayedName() { return otherPlayerId; } @Override public String getImageUrl() { return "https://pp.vk.me/c620127/v620127169/11996/5TkNN6HNbPE.jpg"; } @Override public String getId() { return otherPlayerId; } @Override public String toString() { return getId(); } }; others = ObjectSet.with(other); all.put(me.getId(), me); all.put(other.getId(), other); disconnectFuture().addListener(new IFutureListener() { @Override public void onHappened(Object o) { multiplayer.sendToServer(ClientServerMessage.Type.endSession); } }); }
Example #4
Source File: ViewController.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
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 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()); } }
Example #5
Source File: Tutorial.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public static void killAll() { if (runningTutorials.size == 0) return; ObjectSet<Tutorial> tuts = new ObjectSet<Tutorial>(runningTutorials); for (Tutorial tutorial : tuts) { try { tutorial.cancel(); } catch (UnsupportedOperationException e) { Logger.debug("failed to cancel tutorial", e); } } }
Example #6
Source File: KeyMapper.java From riiablo with Apache License 2.0 | 5 votes |
public Set<MappedKey> get(@MappedKey.Keycode int keycode) { ObjectSet<MappedKey> keys = KEYS.get(keycode); if (keys == null) { return Collections.emptySet(); } return ImmutableSet.copyOf(keys); }
Example #7
Source File: RoomController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void onRoomConnected(final int statusCode, final Room room) { Logger.log("room connected, status ok: " + (statusCode == GamesStatusCodes.STATUS_OK)); if (statusCode != GamesStatusCodes.STATUS_OK) { die(false, Config.thesaurus.localize("disconnect-game-services-error")); return; } RoomController.this.room = room; session.setVariant(room.getVariant()); String playerId = room.getParticipantId(Games.Players.getCurrentPlayerId(multiplayer.client)); for (Participant participant : room.getParticipants()) { if (participant.getStatus() != Participant.STATUS_JOINED) continue; if (participant.getParticipantId().equals(playerId)) { me = new MultiplayerParticipant(participant); } else { others.add(new MultiplayerParticipant(participant)); } } all.put(me.getId(), me); for (MultiplayerParticipant p : others) { all.put(p.getId(), p); } publicOthers = new ObjectSet<IParticipant>(others); publicAll = new ObjectMap<String, IParticipant>(all); multiplayer.updateInvites(); Logger.log(" - room: " + RoomController.this.toString(room)); }
Example #8
Source File: PackingProcessor.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
public boolean remove(FileHandle fileHandle) { boolean removed = false; ObjectSet.ObjectSetIterator<ImageEntry> iterator = imageSet.iterator(); while (iterator.hasNext) { ImageEntry imageEntry = iterator.next(); if (imageEntry.fileHandle.equals(fileHandle)) { iterator.remove(); removed = true; } } return removed; }
Example #9
Source File: GdxKeyMapper.java From riiablo with Apache License 2.0 | 5 votes |
@Override public boolean keyDown(int keycode) { ObjectSet<MappedKey> keys = lookup(keycode); if (keys != null) { for (MappedKey key : keys) { setPressed(key, keycode, true); } } return false; }
Example #10
Source File: GdxKeyMapper.java From riiablo with Apache License 2.0 | 5 votes |
@Override public boolean keyUp(int keycode) { ObjectSet<MappedKey> keys = lookup(keycode); if (keys != null) { for (MappedKey key : keys) { setPressed(key, keycode, false); } } return false; }
Example #11
Source File: TXT.java From riiablo with Apache License 2.0 | 5 votes |
public static TXT loadFromStream(InputStream in) { BufferedReader reader = null; try { reader = IOUtils.buffer(new InputStreamReader(in, "US-ASCII")); ObjectIntMap<String> columns = new ObjectIntMap<>(); String[] columnNames = StringUtils.splitPreserveAllTokens(reader.readLine(), '\t'); for (int i = 0; i < columnNames.length; i++) { String key = columnNames[i].toLowerCase(); if (!columns.containsKey(key)) columns.put(key, i); } if (DEBUG_COLS) { ObjectSet<String> duplicates = new ObjectSet<>(); String[] colNames = new String[columns.size]; for (int i = 0, j = 0; i < columnNames.length; i++) { String columnName = columnNames[i]; if (!duplicates.add(columnName)) continue; colNames[j++] = columnName; } Gdx.app.debug(TAG, "cols=" + Arrays.toString(colNames)); } Array<String[]> data = new Array<>(String[].class); for (String line; (line = reader.readLine()) != null;) { String[] tmp = split(columnNames.length, line, '\t'); if (tmp.length != columnNames.length) { if (DEBUG_ROWS) Gdx.app.debug(TAG, "Skipping row " + Arrays.toString(tmp)); continue; } data.add(tmp); if (DEBUG_ROWS) Gdx.app.debug(TAG, data.size - 1 + ": " + Arrays.toString(tmp)); } return new TXT(columns, data); } catch (Throwable t) { throw new GdxRuntimeException("Couldn't read TXT", t); } finally { IOUtils.closeQuietly(reader); } }
Example #12
Source File: KeyMapper.java From riiablo with Apache License 2.0 | 5 votes |
private boolean unassign(MappedKey key, @MappedKey.Keycode int keycode) { Validate.isTrue(key != null, "key cannot be null"); ObjectSet<MappedKey> keys = KEYS.get(keycode); if (keys == null) return false; boolean removed = keys.remove(key); if (keys.size == 0) { KEYS.remove(keycode); } return removed; }
Example #13
Source File: KeyMapper.java From riiablo with Apache License 2.0 | 5 votes |
private void assign(MappedKey key, @MappedKey.Assignment int assignment, @MappedKey.Keycode int keycode) { Validate.isTrue(key != null, "key cannot be null"); ObjectSet<MappedKey> keys = KEYS.get(keycode); if (keys == null) { keys = new ObjectSet<>(); KEYS.put(keycode, keys); } keys.add(key); }
Example #14
Source File: KeyMapper.java From riiablo with Apache License 2.0 | 5 votes |
private boolean containsAnyAssignmentOf(MappedKey key) { for (@MappedKey.Keycode int keycode : key.assignments) { ObjectSet<MappedKey> keys = KEYS.get(keycode); if (keys != null && keys.contains(key)) { return true; } } return false; }
Example #15
Source File: Excel.java From riiablo with Apache License 2.0 | 5 votes |
public static <T extends Excel> T load(Class<T> excelClass, FileHandle txt, FileHandle bin, ObjectSet<String> ignore) { try { if (ignore == null) ignore = emptySet(); Class<Entry> entryClass = getEntryClass(excelClass); if (entryClass == null) throw new AssertionError(excelClass + " does not implement " + Entry.class); long start = System.currentTimeMillis(); T excel; FileHandle file; if (!FORCE_TXT && isBinned(excelClass) && bin != null && bin.exists()) { if (DEBUG_TYPE) Gdx.app.debug(TAG, "Loading bin " + bin); excel = loadBin(bin, excelClass, entryClass); if (DEBUG_TIME) file = bin; } else { if (DEBUG_TYPE) Gdx.app.debug(TAG, "Loading txt " + txt); excel = loadTxt(txt, excelClass, entryClass, ignore); if (DEBUG_TIME) file = txt; } long end = System.currentTimeMillis(); if (DEBUG_TIME) Gdx.app.debug(TAG, "Loaded " + file + " in " + (end - start) + "ms"); excel.init(); return excel; } catch (Throwable t) { throw new GdxRuntimeException("Couldn't load excel " + excelClass, t); } }
Example #16
Source File: Excel.java From riiablo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static <T extends Excel> T loadTxt(FileHandle handle, Class<T> excelClass, Class<Entry> entryClass, ObjectSet<String> ignore) throws Exception { TxtParser in = null; try { in = TxtParser.loadFromFile(handle); return loadTxt(in, excelClass, entryClass, ignore); } catch (Throwable t) { throw new GdxRuntimeException("Couldn't load excel: " + handle, t); } finally { IOUtils.closeQuietly(in); } }
Example #17
Source File: KeyMapper.java From riiablo with Apache License 2.0 | 5 votes |
@Override @NonNull public Iterator<MappedKey> iterator() { IntMap.Values<ObjectSet<MappedKey>> entries = KEYS.values(); ObjectSet<MappedKey> uniqueEntries = new ObjectSet<>(); for (ObjectSet<MappedKey> entry : entries) { uniqueEntries.addAll(entry); } return uniqueEntries.iterator(); }
Example #18
Source File: Achievement.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public Achievement(String name, String id, ObjectSet<EventType> eventTypes, AchievementCondition condition, int order) { this.name = name; this.id = id; this.eventTypes = eventTypes; this.condition = condition; this.order = order; }
Example #19
Source File: ModuleWrapperGroup.java From talos with Apache License 2.0 | 5 votes |
public void removeWrappers(ObjectSet<ModuleWrapper> wrappersToRemove) { for(ModuleWrapper wrapper: wrappersToRemove) { if(wrappers.contains(wrapper)) { wrappers.remove(wrapper); } } if(wrappers.size == 0) { TalosMain.Instance().NodeStage().moduleBoardWidget.removeGroup(this); } }
Example #20
Source File: ModuleWrapperGroup.java From talos with Apache License 2.0 | 5 votes |
@Override public void read(Json json, JsonValue jsonData) { init(VisUI.getSkin()); Color color = json.readValue(Color.class, jsonData.get("color")); String text = jsonData.getString("text"); wrappers = json.readValue(ObjectSet.class, jsonData.get("modules")); setText(text); setColor(color); }
Example #21
Source File: SpawnController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private void autoPlace() { if (placed.size > 0) { ObjectSet<Creature> tmp = Pools.obtain(ObjectSet.class); tmp.addAll(placed); 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); }
Example #22
Source File: DistanceFiller.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public static int getDistanceToNearCreatureOfRelation(World world, int x, int y, Creature creature, Creature.CreatureRelation relation) { if (!world.inBounds(x, y)) return -1; ObjectSet<Coordinate> checked = tmp; ObjectSet<Coordinate> toCheck = tmp2; addNeighbours(world, x, y, checked, toCheck); return recursive(world, creature, relation, checked, toCheck, 1).distance; }
Example #23
Source File: DistanceFiller.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public static Result getInfoOfNearCreatureOfRelation(World world, int x, int y, Creature creature, Creature.CreatureRelation relation) { if (!world.inBounds(x, y)) return null; ObjectSet<Coordinate> checked = tmp; ObjectSet<Coordinate> toCheck = tmp2; addNeighbours(world, x, y, checked, toCheck); recursive(world, creature, relation, checked, toCheck, 1); return result; }
Example #24
Source File: DistanceFiller.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public static Coordinate getCoordinateOfNearCreatureOfRelation(World world, int x, int y, Creature creature, Creature.CreatureRelation relation) { if (!world.inBounds(x, y)) return null; ObjectSet<Coordinate> checked = tmp; ObjectSet<Coordinate> toCheck = tmp2; addNeighbours(world, x, y, checked, toCheck); recursive(world, creature, relation, checked, toCheck, 1); return result.distance == -1 ? null : Coordinate.obtain(result.position.x, result.position.y); }
Example #25
Source File: DistanceFiller.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
public static int getDistance(Creature from, Creature to) { int x = from.getX(); int y = from.getY(); World world = from.world; if (!world.inBounds(x, y)) return -1; ObjectSet<Coordinate> checked = tmp; ObjectSet<Coordinate> toCheck = tmp2; addNeighbours(world, x, y, checked, toCheck); return recursive(world, to, checked, toCheck, 1).distance; }
Example #26
Source File: DistanceFiller.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
private static void addNeighbours(World world, int x, int y, ObjectSet<Coordinate> checked, ObjectSet<Coordinate> toCheck) { addNeighbour(world, x - 1, y - 1, checked, toCheck); addNeighbour(world, x - 1, y, checked, toCheck); addNeighbour(world, x - 1, y + 1, checked, toCheck); addNeighbour(world, x, y - 1, checked, toCheck); addNeighbour(world, x, y + 1, checked, toCheck); addNeighbour(world, x + 1, y - 1, checked, toCheck); addNeighbour(world, x + 1, y, checked, toCheck); addNeighbour(world, x + 1, y + 1, checked, toCheck); }
Example #27
Source File: DistanceFiller.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
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; Coordinate coordinate = Coordinate.obtain(x, y); if (checked.contains(coordinate)) { coordinate.free(); return; } toCheck.add(coordinate); }
Example #28
Source File: Files.java From riiablo with Apache License 2.0 | 4 votes |
private <T extends Excel> T load(Class<T> clazz, ObjectSet<String> ignore) { return load(clazz, clazz.getSimpleName(), ignore); }
Example #29
Source File: FilteredSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
/** * @return The index of the first selected item. The top item has an index of 0. * Nothing selected has an index of -1. */ public int getSelectedIndex() { ObjectSet<T> selected = selection.items(); return selected.size == 0 ? -1 : items.indexOf(selected.first(), false); }
Example #30
Source File: Files.java From riiablo with Apache License 2.0 | 4 votes |
private <T extends Excel> T load(Class<T> clazz, String tableName, ObjectSet<String> ignore) { FileHandle txt = Riiablo.mpqs.resolve(EXCEL_PATH + tableName + ".txt"); FileHandle bin = Gdx.files.internal(EXCEL_PATH + tableName + ".bin"); return Excel.load(clazz, txt, bin, ignore); }