List of usage examples for com.badlogic.gdx.utils Array set
public void set(int index, T value)
From source file:com.andgate.ikou.model.MasterSector.java
License:Open Source License
private TileSector ensureSectorColumn(Array<TileSector> sectorsRow, int columnIndex) { int columnCount = columnIndex + 1; if (columnCount > sectorsRow.size) { int distance = columnCount - sectorsRow.size; sectorsRow.ensureCapacity(distance); while (distance > 0) { sectorsRow.add(null);//from w w w. ja va 2 s.c om distance--; } } TileSector sector = sectorsRow.get(columnIndex); if (sector == null) { sector = new TileSector(); sectorsRow.set(columnIndex, sector); } return sector; }
From source file:com.bladecoder.engineeditor.ui.ActionList.java
License:Apache License
private void toggleEnabled() { Action a = list.getSelected(); // CONTROL ACTIONS CAN'T BE DISABLED if (a == null || isControlAction(a)) return;/*from w ww . j a va2 s . c om*/ int pos = list.getSelectedIndex(); Array<Action> items = list.getItems(); if (a instanceof DisableActionAction) { Action a2 = ((DisableActionAction) a).getAction(); parent.getActions().set(pos, a2); items.set(pos, a2); } else { DisableActionAction a2 = new DisableActionAction(); a2.setAction(a); parent.getActions().set(pos, a2); items.set(pos, a2); } list.setSelectedIndex(pos); Ctx.project.setModified(); }
From source file:com.bladecoder.engineeditor.ui.ActionList.java
License:Apache License
private void up() { int pos = list.getSelectedIndex(); if (pos == -1 || pos == 0) return;// ww w . j a v a 2 s. c om Array<Action> items = list.getItems(); Action e = items.get(pos); Action e2 = items.get(pos - 1); if (isControlAction(e) && isControlAction(e2)) { return; } parent.getActions().set(pos - 1, e); parent.getActions().set(pos, e2); items.set(pos - 1, e); items.set(pos, e2); list.setSelectedIndex(pos - 1); upBtn.setDisabled(list.getSelectedIndex() == 0); downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1); Ctx.project.setModified(); }
From source file:com.bladecoder.engineeditor.ui.ActionList.java
License:Apache License
private void down() { int pos = list.getSelectedIndex(); Array<Action> items = list.getItems(); if (pos == -1 || pos == items.size - 1) return;// w ww . j a v a 2 s. c om Action e = items.get(pos); Action e2 = items.get(pos + 1); if (isControlAction(e) && isControlAction(e2)) { return; } parent.getActions().set(pos + 1, e); parent.getActions().set(pos, e2); items.set(pos + 1, e); items.set(pos, e2); list.setSelectedIndex(pos + 1); upBtn.setDisabled(list.getSelectedIndex() == 0); downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1); Ctx.project.setModified(); }
From source file:com.bladecoder.engineeditor.ui.OptionList.java
License:Apache License
private void up() { int pos = list.getSelectedIndex(); if (pos == -1 || pos == 0) return;//from w w w. jav a2 s .c om Array<DialogOption> items = list.getItems(); DialogOption e = items.get(pos); DialogOption e2 = items.get(pos - 1); items.set(pos - 1, e); items.set(pos, e2); parent.getOptions().set(pos - 1, e); parent.getOptions().set(pos, e2); list.setSelectedIndex(pos - 1); upBtn.setDisabled(list.getSelectedIndex() == 0); downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1); Ctx.project.setModified(); }
From source file:com.bladecoder.engineeditor.ui.OptionList.java
License:Apache License
private void down() { int pos = list.getSelectedIndex(); Array<DialogOption> items = list.getItems(); if (pos == -1 || pos == items.size - 1) return;//from w w w . j av a 2 s.c om DialogOption e = items.get(pos); DialogOption e2 = items.get(pos + 1); parent.getOptions().set(pos + 1, e); parent.getOptions().set(pos, e2); items.set(pos + 1, e); items.set(pos, e2); list.setSelectedIndex(pos + 1); upBtn.setDisabled(list.getSelectedIndex() == 0); downBtn.setDisabled(list.getSelectedIndex() == list.getItems().size - 1); Ctx.project.setModified(); }
From source file:com.kotcrab.vis.editor.module.physicseditor.util.earclipping.bayazit.BayazitDecomposer.java
License:Apache License
public static Array<Array<Vector2>> ConvexPartition(Array<Vector2> vertices) { // We force it to CCW as it is a precondition in this algorithm. // vertices.ForceCounterClockWise(); if (!IsCounterClockWise(vertices)) { // Collections.reverse(vertices); vertices.reverse();//from w ww . ja v a 2s . co m // Array<Vector2> reversed = new Array<Vector2>(vertices.size); // for (int i = vertices.size - 1; i <= 0; i--) { // reversed.add(vertices.get(i)); // } // vertices = reversed; } Array<Array<Vector2>> list = new Array<Array<Vector2>>(); float d, lowerDist, upperDist; Vector2 p; Vector2 lowerInt = new Vector2(); Vector2 upperInt = new Vector2(); // intersection points int lowerIndex = 0, upperIndex = 0; Array<Vector2> lowerPoly, upperPoly; for (int i = 0; i < vertices.size; ++i) { if (Reflex(i, vertices)) { lowerDist = upperDist = Float.MAX_VALUE; // std::numeric_limits<qreal>::max(); for (int j = 0; j < vertices.size; ++j) { // if line intersects with an edge if (Left(At(i - 1, vertices), At(i, vertices), At(j, vertices)) && RightOn(At(i - 1, vertices), At(i, vertices), At(j - 1, vertices))) { // find the point of intersection p = LineIntersect(At(i - 1, vertices), At(i, vertices), At(j, vertices), At(j - 1, vertices)); if (Right(At(i + 1, vertices), At(i, vertices), p)) { // make sure it's inside the poly d = SquareDist(At(i, vertices), p); if (d < lowerDist) { // keep only the closest intersection lowerDist = d; lowerInt = p; lowerIndex = j; } } } if (Left(At(i + 1, vertices), At(i, vertices), At(j + 1, vertices)) && RightOn(At(i + 1, vertices), At(i, vertices), At(j, vertices))) { p = LineIntersect(At(i + 1, vertices), At(i, vertices), At(j, vertices), At(j + 1, vertices)); if (Left(At(i - 1, vertices), At(i, vertices), p)) { d = SquareDist(At(i, vertices), p); if (d < upperDist) { upperDist = d; upperIndex = j; upperInt = p; } } } } // if there are no vertices to connect to, choose a point in the // middle if (lowerIndex == (upperIndex + 1) % vertices.size) { Vector2 sp = new Vector2((lowerInt.x + upperInt.x) / 2, (lowerInt.y + upperInt.y) / 2); lowerPoly = Copy(i, upperIndex, vertices); lowerPoly.add(sp); upperPoly = Copy(lowerIndex, i, vertices); upperPoly.add(sp); } else { double highestScore = 0, bestIndex = lowerIndex; while (upperIndex < lowerIndex) upperIndex += vertices.size; for (int j = lowerIndex; j <= upperIndex; ++j) { if (CanSee(i, j, vertices)) { double score = 1 / (SquareDist(At(i, vertices), At(j, vertices)) + 1); if (Reflex(j, vertices)) { if (RightOn(At(j - 1, vertices), At(j, vertices), At(i, vertices)) && LeftOn(At(j + 1, vertices), At(j, vertices), At(i, vertices))) { score += 3; } else { score += 2; } } else { score += 1; } if (score > highestScore) { bestIndex = j; highestScore = score; } } } lowerPoly = Copy(i, (int) bestIndex, vertices); upperPoly = Copy((int) bestIndex, i, vertices); } list.addAll(ConvexPartition(lowerPoly)); list.addAll(ConvexPartition(upperPoly)); return list; } } // polygon is already convex if (vertices.size > MaxPolygonVertices) { lowerPoly = Copy(0, vertices.size / 2, vertices); upperPoly = Copy(vertices.size / 2, 0, vertices); list.addAll(ConvexPartition(lowerPoly)); list.addAll(ConvexPartition(upperPoly)); } else list.add(vertices); // The polygons are not guaranteed to be with collinear points. We // remove // them to be sure. for (int i = 0; i < list.size; i++) { list.set(i, SimplifyTools.CollinearSimplify(list.get(i), 0)); } // Remove empty vertice collections for (int i = list.size - 1; i >= 0; i--) { if (list.get(i).size == 0) list.removeIndex(i); } return list; }
From source file:com.kotcrab.vis.editor.module.physicseditor.util.trace.TextureConverter.java
License:Apache License
private static Array<Vector2> CreateSimplePolygon(PolygonCreationAssistance pca, Vector2 entrance, Vector2 last) {/*from w w w . j a v a 2 s . c om*/ boolean entranceFound = false; boolean endOfHull = false; Array<Vector2> polygon = new Array<Vector2>(); Array<Vector2> hullArea = new Array<Vector2>(); Array<Vector2> endOfHullArea = new Array<Vector2>(); Vector2 current = new Vector2(); Vector2 zeroVec = new Vector2(); // Get the entrance point. //todo: alle moglichkeiten testen if (vectorEquals(entrance, zeroVec) || !pca.InBounds(entrance)) { entranceFound = GetHullEntrance(pca, entrance); if (entranceFound) { current.set(entrance.x - 1f, entrance.y); } } else { if (pca.IsSolid(entrance)) { if (IsNearPixel(pca, entrance, last)) { current.set(last); entranceFound = true; } else { Vector2 temp = new Vector2(); if (SearchNearPixels(pca, false, entrance, temp)) { current.set(temp); entranceFound = true; } else { entranceFound = false; } } } } if (entranceFound) { polygon.add(entrance); hullArea.add(entrance); Vector2 next = entrance.cpy(); do { // Search in the pre vision list for an outstanding point. Vector2 outstanding = new Vector2(); if (SearchForOutstandingVertex(hullArea, pca.getHullTolerance(), outstanding)) { if (endOfHull) { // We have found the next pixel, but is it on the last // bit of the // hull? if (vectorListContains(endOfHullArea, outstanding) && !vectorListContains(polygon, outstanding)) { // Indeed. polygon.add(outstanding); } // That's enough, quit. break; } // Add it and remove all vertices that don't matter anymore // (all the vertices before the outstanding). polygon.add(outstanding); int index = vectorListIndexOf(hullArea, outstanding); if (index == -1) { int debug = 1; } if (index >= 0) { // hullArea = hullArea.subList(index + 1, // hullArea.size); // Array<Vector2> newArray = new Array<Vector2> // (hullArea.size - (index + 1)); int counter = 0; for (int i = index + 1; i < hullArea.size; i++) { Vector2 v = hullArea.get(index); // newArray.add(v); hullArea.set(counter, v); counter++; } // hullArea.clear(); // hullArea = newArray; for (int i = 0; i < index + 1; i++) { hullArea.pop(); } } } // Last point gets current and current gets next. Our little // spider is // moving forward on the hull ;). last.set(current); current.set(next); // Get the next point on hull. next = new Vector2(); if (GetNextHullPoint(pca, last, current, next)) { // Add the vertex to a hull pre vision list. hullArea.add(next); } else { // Quit break; } if (vectorEquals(next, entrance) && !endOfHull) { // It's the last bit of the hull, search on and exit at next // found // vertex. endOfHull = true; endOfHullArea.addAll(hullArea); } } while (true); } return polygon; }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
/******************************* GENERATE FIRST LAYER/* w w w . j a va 2 s . c o m*/ *******************************/ private void generateLayer0(int scount, boolean reset) { sectionCount = scount; if (layerManagers.size == 0) { layerManagers.add(new LayerManager(0)); } LayerManager mainLayer = layerManagers.peek(); for (int i = 0; i < sectionCount; i++) { //create first null section if (mainLayer.layerSections.size == 0) { mainLayer.layerSections.add(new NullSection(new Vector2(200 * RATIO, 100 * RATIO), sectionWidth, sectionHeight, this, nullCoord, mainLayer.depth)); gridCoords.add(nullCoord); } else { //create ajoined null sections NullSection prevSection = reset ? mainLayer.layerSections.random() : mainLayer.layerSections.peek(); boolean[] prevSides = prevSection.getAvailableSides(); int index; Vector2 secPosition; Array<Boolean> sideCheck = new Array<Boolean>(); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); boolean occupied; int count; do { index = rng.nextInt(prevSides.length); switch (index) { case 0: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() + 1); secPosition = new Vector2(0, sectionHeight); break; case 1: nullCoord = new Coordinate(prevSection.getCoord().getX() + 1, prevSection.getCoord().getY()); secPosition = new Vector2(sectionWidth, 0); break; case 2: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() - 1); secPosition = new Vector2(0, -sectionHeight); break; default: //3 nullCoord = new Coordinate(prevSection.getCoord().getX() - 1, prevSection.getCoord().getY()); secPosition = new Vector2(-sectionWidth, 0); break; } //if coord is already taken occupied = false; try { for (Coordinate coord : gridCoords) { if (coord.compareTo(nullCoord)) { sideCheck.set(index, true); occupied = true; } } } catch (IndexOutOfBoundsException ex) { ex.printStackTrace(); } //todo: fix the "spiral problem" w/ section generation //perhaps just choose random coord?? //use array[s,s,s,s] to check all four sides //if(count == 4) return; count = 0; for (Boolean s : sideCheck) { if (s) count++; } if (count >= 4) { generateLayer0(sectionCount - i, true); return; } } while (occupied); prevSection.setSide(index, false, NullSection.WallType.CONNECTED); gridCoords.add(nullCoord); //create section at specifies coord(x,y) mainLayer.layerSections.add(new NullSection(prevSection.getPos().cpy().add(secPosition), sectionWidth, sectionHeight, this, nullCoord, mainLayer.depth)); //layerDepth switch (index) { case 0: mainLayer.layerSections.peek().setSide(2, false, NullSection.WallType.CONNECTED); break; case 1: mainLayer.layerSections.peek().setSide(3, false, NullSection.WallType.CONNECTED); break; case 2: mainLayer.layerSections.peek().setSide(0, false, NullSection.WallType.CONNECTED); break; case 3: mainLayer.layerSections.peek().setSide(1, false, NullSection.WallType.CONNECTED); break; default: break; } } } }
From source file:com.mygdx.environments.EnvNull.EnvNull.java
/********************************************************************************* CREATES AN INITIAL PIT SECTION AND NEW LAYERMANAGER, based on piChance *********************************************************************************/ private int generateLayer(int layers, int scount) { //recursive termination if (layers <= 0) return 0; int depth = layerManagers.size; System.out.println("@EnvNull generate layer : depth:" + depth); LayerManager prevLayer = layerManagers.get(depth - 1); layerManagers.add(new LayerManager(depth)); LayerManager currentLayer = layerManagers.peek(); /**//from w ww . ja v a 2 s . c om * ***************************************** * * PIT SECTION GENERATION * ****************************************** */ //go through sections of prevLayer NullSection prevSection = prevLayer.layerSections.peek(); //check section for available adjecent sections boolean[] sides = prevSection.getAvailableSides(); int index; Array<Boolean> sideCheck = new Array<Boolean>(); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); sideCheck.add(false); int count; boolean occupied; do { index = rng.nextInt(sides.length); switch (index) { case 0: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() + 1); break; case 1: nullCoord = new Coordinate(prevSection.getCoord().getX() + 1, prevSection.getCoord().getY()); break; case 2: nullCoord = new Coordinate(prevSection.getCoord().getX(), prevSection.getCoord().getY() - 1); break; case 3: nullCoord = new Coordinate(prevSection.getCoord().getX() - 1, prevSection.getCoord().getY()); break; default: nullCoord = new Coordinate(prevSection.getCoord().getX() - 1, prevSection.getCoord().getY()); break; } //if coord is already taken occupied = false; try { for (Coordinate coord : gridCoords) { if (coord.compareTo(nullCoord)) { sideCheck.set(index, true); occupied = true; } } } catch (IndexOutOfBoundsException ex) { ex.printStackTrace(); } count = 0; for (Boolean s : sideCheck) { if (s) { count++; } } if (count >= 4) { layerManagers.pop(); return generateLayer(layers, scount); } } while (occupied); prevSection.setSide(index, false, NullSection.WallType.PIT_HIGHER); gridCoords.add(nullCoord); switch (index) { case 0: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(0, sectionHeight)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(2, false, NullSection.WallType.PIT_LOWER); break; case 1: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(sectionWidth, 0)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(3, false, NullSection.WallType.PIT_LOWER); break; case 2: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(0, -sectionHeight)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(0, false, NullSection.WallType.PIT_LOWER); break; case 3: currentLayer.layerSections .add(new NullSection(prevSection.getPos().cpy().add(new Vector2(-sectionWidth, 0)), sectionWidth, sectionHeight, this, nullCoord, currentLayer.depth)); currentLayer.layerSections.peek().setSide(1, false, NullSection.WallType.PIT_LOWER); break; default: break; } //set pit section child of higher pit section prevSection.childSection = currentLayer.layerSections.peek(); currentLayer.layerSections.peek().parentSection = prevSection; fillLayer(currentLayer, scount, false); return generateLayer(layers - 1, scount - 1); }