protected final int[] getAttributeLocations(Renderable renderable) { final IntIntMap attributes = new IntIntMap(); final VertexAttributes attrs = renderable.meshPart.mesh.getVertexAttributes(); final int c = attrs.size(); for (int i = 0; i < c; i++) { final VertexAttribute attr = attrs.get(i); final int location = program.getAttributeLocation(attr.alias); if (location >= 0) attributes.put(attr.getKey(), location); } tempArray.clear(); final int n = attrs.size(); for (int i = 0; i < n; i++) { tempArray.add(attributes.get(attrs.get(i).getKey(), -1)); } return tempArray.items; }
private void updateTileInfluence(int x, int y) { Influence tile = map.getInfluenceAt(x, y); float shift = 0f; for (IntIntMap.Entry e : tile.getDelta()) { if (e.value != 0) { Entity empire = world.getEntity(e.key); String text = abs(e.value) > 4 ? (e.value > 0 ? "+" + e.value : Integer.toString(e.value)) : DELTA_STR[e.value + 4]; EntityFactory.createFadingTileLabel(world, text, data.get(empire).color, x, y + shift, 1f); shift += 0.2; } } tile.computeNewInfluence(); // do not forget to update the main source Entity main = tile.getMainInfluenceSource(world); if (main != null) sources.get(main).influencedTiles.add(map.getPositionAt(x, y)); }
/** Neighbors from the nicest to the worst. */ private List<Entity> getNeighboringSources(Entity entity) { IntIntMap neighbors = new IntIntMap(16); MapPosition pos = positions.get(entity); for (int i = 1; i < 10; i++) { // TODO really search for all tiles addInfluencer(neighbors, entity, pos.x + i, pos.y + i); addInfluencer(neighbors, entity, pos.x - i, pos.y + i); addInfluencer(neighbors, entity, pos.x + i, pos.y - i); addInfluencer(neighbors, entity, pos.x - i, pos.y - i); } List<Entry> entries = new ArrayList<>(); neighbors.entries().forEach(e -> entries.add(e)); entries.sort((e1, e2) -> Integer.compare(e1.value, e2.value)); List<Entity> res = new ArrayList<>(entries.size()); entries.forEach(e -> res.add(world.getEntity(e.key))); return res; }
private Influence addInfluences(MapPosition tile) { Influence influence = map.getInfluenceAt(tile); int mainSource = influence.getMainInfluenceSource(); StringBuilder sb = new StringBuilder("[BLACK]Influence: "); for (IntIntMap.Entry e : influence) { Entity source = world.getEntity(e.key); Empire empire = source.getComponent(Empire.class); sb.append("\n ").append(markup(empire.color)).append(source.getComponent(Name.class).name).append("[]: ") .append(100 * e.value / InfluenceSystem.INITIAL_POWER).append('%').append(' ') .append(number(100 * influence.getDelta(source) / InfluenceSystem.INITIAL_POWER)).append('%'); // ignore == 0 if (e.key == mainSource) sb.append(" (main)"); } selectionMenu.addColoredLabel(sb.toString()); return influence; }
public void write (Kryo kryo, Output output, IntIntMap map) { int length = map.size; output.writeVarInt(length, true); for (Iterator iter = map.iterator(); iter.hasNext();) { IntIntMap.Entry entry = (IntIntMap.Entry)iter.next(); output.writeInt(entry.key); output.writeInt(entry.value); } }
public IntIntMap read (Kryo kryo, Input input, Class<IntIntMap> type) { int length = input.readVarInt(true); IntIntMap map = new IntIntMap(length); for (int i = 0; i < length; i++) { int key = input.readInt(); int value = input.readInt(); map.put(key, value); } return map; }
public int getButtonAmount () { try { switch (Gdx.app.getType()) { case Android: Field androidButtons = ClassReflection .getDeclaredField(ClassReflection.forName("com.badlogic.gdx.controllers.android.AndroidController"), "buttons"); androidButtons.setAccessible(true); return ((IntIntMap)androidButtons.get(gamePad)).size; case Desktop: Field desktopButtons = ClassReflection.getDeclaredField( ClassReflection.forName("com.badlogic.gdx.controllers.lwjgl3.Lwjgl3Controller"), "buttonState"); desktopButtons.setAccessible(true); return ((boolean[])desktopButtons.get(gamePad)).length; case HeadlessDesktop: return 0; case WebGL: Field gwtButtons = ClassReflection .getDeclaredField(ClassReflection.forName("com.badlogic.gdx.controllers.gwt.GwtController"), "buttons"); gwtButtons.setAccessible(true); return ((IntFloatMap)gwtButtons.get(gamePad)).size; case iOS: return 0; default: break; } } catch (Exception ex) { ex.printStackTrace(); } return 0; }
public FetlarRulesEngine() { blackLegalMoves = new Array<Move>(); whiteLegalMoves = new Array<Move>(); kingLegalMoves = new Array<Move>(); boardConfigHistory = new IntArray(); configurationCounter = new IntIntMap(); random = new Random(); shuffleArray = new Move[Constants.GameConstants.MAX_NUMBER_OF_MOVES]; }
public Iterable<IntIntMap.Entry> getDelta() { return influenceDelta; }
private void addInfluencer(IntIntMap neighbors, Entity capital, int x, int y) { Influence inf = map.getInfluenceAt(x, y); if (inf != null && !inf.isMainInfluencer(capital) && inf.hasMainInfluence()) neighbors.getAndIncrement(inf.getMainInfluenceSource(), 0, 1); }
public DefaultGameModel() { super(); playerRefIdToShipRefIdMap = new IntIntMap(); }