summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-06 00:02:22 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-06 00:02:22 +0200
commit9e246d84e31b8097bfbb72c7f0c7337d47df9e9e (patch)
tree25de30b83a7e5d4d84f3016ae1bd21790ef73f39 /core/src/ch/asynk
parent289d5150711e8b89be5caedeacb779ef277301c3 (diff)
downloadRustAndDust-9e246d84e31b8097bfbb72c7f0c7337d47df9e9e.zip
RustAndDust-9e246d84e31b8097bfbb72c7f0c7337d47df9e9e.tar.gz
use ArrayList instead of Vector
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java32
-rw-r--r--core/src/ch/asynk/tankontank/engine/Pawn.java4
-rw-r--r--core/src/ch/asynk/tankontank/engine/SearchBoard.java37
-rw-r--r--core/src/ch/asynk/tankontank/engine/gfx/animations/AnimationSequence.java10
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java8
5 files changed, 45 insertions, 46 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 0a8a47b..886faad 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -2,7 +2,7 @@ package ch.asynk.tankontank.engine;
import java.util.Set;
import java.util.List;
-import java.util.Vector;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
@@ -72,8 +72,8 @@ public abstract class Board implements Disposable
private int tileCount = 0;
private int pawnCount = 0;
private int animationCount = 0;
- private final Vector<Animation> animations = new Vector<Animation>(2);
- private final Vector<Animation> nextAnimations = new Vector<Animation>(2);
+ private final ArrayList<Animation> animations = new ArrayList<Animation>(2);
+ private final ArrayList<Animation> nextAnimations = new ArrayList<Animation>(2);
private final LinkedHashSet<Tile> tilesToDraw = new LinkedHashSet<Tile>();
protected final LinkedHashSet<Pawn> pawnsToDraw = new LinkedHashSet<Pawn>();
@@ -241,14 +241,14 @@ public abstract class Board implements Disposable
debugShapes.setTransformMatrix(prevTransform);
}
- public void clearPointVector(Vector<GridPoint2> points)
+ public void clearPointVector(ArrayList<GridPoint2> points)
{
for (GridPoint2 point : points)
gridPoint2Pool.free(point);
points.clear();
}
- private void nodesToPoints(List<SearchBoard.Node> nodes, Vector<GridPoint2> points)
+ private void nodesToPoints(List<SearchBoard.Node> nodes, ArrayList<GridPoint2> points)
{
// for (GridPoint2 point : points)
// gridPoint2Pool.free(point);
@@ -279,16 +279,16 @@ public abstract class Board implements Disposable
}
i += 1;
}
- points.setSize(ns);
+ points.ensureCapacity(ns);
}
- public void possibleMovesFrom(Pawn pawn, GridPoint2 coords, Vector<GridPoint2> moves)
+ public void possibleMovesFrom(Pawn pawn, GridPoint2 coords, ArrayList<GridPoint2> moves)
{
List<SearchBoard.Node> nodes = searchBoard.possibleMovesFrom(pawn, coords.x, coords.y);
nodesToPoints(nodes, moves);
}
- public void possibleTargetsFrom(Pawn pawn, GridPoint2 coords, Vector<GridPoint2> targets)
+ public void possibleTargetsFrom(Pawn pawn, GridPoint2 coords, ArrayList<GridPoint2> targets)
{
List<SearchBoard.Node> nodes = searchBoard.possibleTargetsFrom(pawn, coords.x, coords.y);
nodesToPoints(nodes, targets);
@@ -301,13 +301,13 @@ public abstract class Board implements Disposable
points.clear();
}
- private int nodesToSet(List<Vector<SearchBoard.Node>> nodes, Set<GridPoint2> points)
+ private int nodesToSet(List<ArrayList<SearchBoard.Node>> nodes, Set<GridPoint2> points)
{
for (GridPoint2 point : points)
gridPoint2Pool.free(point);
points.clear();
- for (Vector<SearchBoard.Node> path : nodes) {
+ for (ArrayList<SearchBoard.Node> path : nodes) {
for (SearchBoard.Node node : path) {
GridPoint2 point = gridPoint2Pool.obtain();
point.set(node.col, node.row);
@@ -321,26 +321,26 @@ public abstract class Board implements Disposable
public int possiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to, Set<GridPoint2> points)
{
- List<Vector<SearchBoard.Node>> paths = searchBoard.possiblePaths(pawn, from.x, from.y, to.x, to.y);
+ List<ArrayList<SearchBoard.Node>> paths = searchBoard.possiblePaths(pawn, from.x, from.y, to.x, to.y);
return nodesToSet(paths, points);
}
public int possiblePathsFilterToggle(GridPoint2 coords, Set<GridPoint2> points)
{
- List<Vector<SearchBoard.Node>> paths = searchBoard.possiblePathsFilterToggle(coords.x, coords.y);
+ List<ArrayList<SearchBoard.Node>> paths = searchBoard.possiblePathsFilterToggle(coords.x, coords.y);
return nodesToSet(paths, points);
}
- public void clearCoordinateVector(Vector<Vector3> points)
+ public void clearCoordinateVector(ArrayList<Vector3> points)
{
for (Vector3 point : points)
vector3Pool.free(point);
points.clear();
}
- public int getCoordinatePath(Pawn pawn, Vector<Vector3> path, Orientation finalOrientation)
+ public int getCoordinatePath(Pawn pawn, ArrayList<Vector3> path, Orientation finalOrientation)
{
- List<Vector<SearchBoard.Node>> paths = searchBoard.possiblePaths();
+ List<ArrayList<SearchBoard.Node>> paths = searchBoard.possiblePaths();
clearCoordinateVector(path);
@@ -452,7 +452,7 @@ public abstract class Board implements Disposable
pushPawnAt(pawn, coords);
}
- public void movePawn(final Pawn pawn, Vector<Vector3> path)
+ public void movePawn(final Pawn pawn, ArrayList<Vector3> path)
{
removePawnFrom(pawn, getHexAt(pawn.getCenter()));
diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java
index 52af8ca..51ac492 100644
--- a/core/src/ch/asynk/tankontank/engine/Pawn.java
+++ b/core/src/ch/asynk/tankontank/engine/Pawn.java
@@ -1,6 +1,6 @@
package ch.asynk.tankontank.engine;
-import java.util.Vector;
+import java.util.ArrayList;
import java.util.ArrayDeque;
import com.badlogic.gdx.utils.Disposable;
@@ -139,7 +139,7 @@ public abstract class Pawn implements Drawable, Disposable
return hasOverlayEnabled();
}
- public AnimationSequence getMoveAnimation(Vector<Vector3> path)
+ public AnimationSequence getMoveAnimation(ArrayList<Vector3> path)
{
int s = path.size();
final Vector3 finalPos = path.get(s - 1);
diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
index dd6a798..e3dac5d 100644
--- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java
+++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
@@ -3,7 +3,7 @@ package ch.asynk.tankontank.engine;
import java.util.List;
import java.util.ArrayDeque;
import java.util.LinkedList;
-import java.util.Vector;
+import java.util.ArrayList;
public class SearchBoard
{
@@ -34,9 +34,9 @@ public class SearchBoard
private LinkedList<Node> queue;
private ArrayDeque<Node> roadMarch;
- private ArrayDeque<Node> path = new ArrayDeque<Node>(20);
- private List<Vector<Node>> possiblePaths = new LinkedList<Vector<Node>>();
- private List<Node> possiblePathsFilters = new Vector<Node>(5);
+ private ArrayList<Node> path = new ArrayList<Node>(20);
+ private List<ArrayList<Node>> possiblePaths = new LinkedList<ArrayList<Node>>();
+ private List<Node> possiblePathsFilters = new ArrayList<Node>(5);
private List<Node> moves;
private List<Node> targets;
@@ -68,9 +68,9 @@ public class SearchBoard
this.stack = new ArrayDeque<Node>(20);
this.roadMarch = new ArrayDeque<Node>(5);
- this.moves = new Vector<Node>(20);
- this.targets = new Vector<Node>(10);
- this.los = new Vector<Node>(10);
+ this.moves = new ArrayList<Node>(40);
+ this.targets = new ArrayList<Node>(10);
+ this.los = new ArrayList<Node>(10);
}
private boolean inMap(int col, int row)
@@ -495,13 +495,13 @@ public class SearchBoard
public void clearPossiblePaths()
{
path.clear();
- for (Vector<Node> v : possiblePaths)
+ for (ArrayList<Node> v : possiblePaths)
v.clear();
possiblePaths.clear();
possiblePathsFilters.clear();
}
- public List<Vector<Node>> possiblePathsFilterToggle(int col, int row)
+ public List<ArrayList<Node>> possiblePathsFilterToggle(int col, int row)
{
Node n = getNode(col, row);
if (possiblePathsFilters.contains(n))
@@ -511,12 +511,12 @@ public class SearchBoard
return possiblePaths();
}
- public List<Vector<Node>> possiblePaths()
+ public List<ArrayList<Node>> possiblePaths()
{
int s = possiblePathsFilters.size();
- List<Vector<Node>> paths = new LinkedList<Vector<Node>>();
- for (Vector<Node> path : possiblePaths) {
+ List<ArrayList<Node>> paths = new LinkedList<ArrayList<Node>>();
+ for (ArrayList<Node> path : possiblePaths) {
int ok = 0;
for (Node filter : possiblePathsFilters) {
if (path.contains(filter))
@@ -535,7 +535,7 @@ public class SearchBoard
return paths;
}
- public List<Vector<Node>> possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1)
+ public List<ArrayList<Node>> possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1)
{
clearPossiblePaths();
@@ -543,7 +543,7 @@ public class SearchBoard
Node to = getNode(col1, row1);
if (distance(from, to) == 1) {
- Vector<Node> temp = new Vector<Node>(2);
+ ArrayList<Node> temp = new ArrayList<Node>(2);
temp.add(to);
temp.add(from);
possiblePaths.add(temp);
@@ -572,16 +572,15 @@ public class SearchBoard
if ((distance(next, to) <= r)) {
if (next == to) {
- Vector<Node> temp = new Vector<Node>(path.size() + 1);
- temp.add(next);
+ ArrayList<Node> temp = new ArrayList<Node>(path.size() + 1);
for (Node n: path)
temp.add(n);
+ temp.add(next);
possiblePaths.add(temp);
} else {
- next.remaining = r;
- path.push(next);
+ path.add(next);
findAllPaths(pawn, next, to, (mvtLeft - cost), (roadMarch & road), roadMarchBonus);
- path.pop();
+ path.remove(path.size() - 1);
}
}
}
diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/AnimationSequence.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/AnimationSequence.java
index 79cf021..9d5495a 100644
--- a/core/src/ch/asynk/tankontank/engine/gfx/animations/AnimationSequence.java
+++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/AnimationSequence.java
@@ -1,6 +1,6 @@
package ch.asynk.tankontank.engine.gfx.animations;
-import java.util.Vector;
+import java.util.ArrayList;
import com.badlogic.gdx.utils.Pool;
@@ -9,7 +9,7 @@ import ch.asynk.tankontank.engine.gfx.Animation;
public class AnimationSequence implements Animation, Pool.Poolable
{
- private Vector<Animation> animations;
+ private ArrayList<Animation> animations;
private static final Pool<AnimationSequence> animationSequencePool = new Pool<AnimationSequence>() {
@Override
@@ -22,9 +22,9 @@ public class AnimationSequence implements Animation, Pool.Poolable
{
AnimationSequence seq = animationSequencePool.obtain();
if (seq.animations == null)
- seq.animations = new Vector<Animation>(capacity);
+ seq.animations = new ArrayList<Animation>(capacity);
else
- seq.animations.setSize(capacity);
+ seq.animations.ensureCapacity(capacity);
return seq;
}
@@ -61,7 +61,7 @@ public class AnimationSequence implements Animation, Pool.Poolable
Animation animation = animations.get(0);
if (animation.animate(delta)) {
- animations.removeElementAt(0);
+ animations.remove(0);
}
return (animations.isEmpty());
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 0627e47..c67d3d7 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -1,6 +1,6 @@
package ch.asynk.tankontank.game;
-import java.util.Vector;
+import java.util.ArrayList;
import java.util.HashSet;
import com.badlogic.gdx.graphics.Texture;
@@ -16,9 +16,9 @@ import ch.asynk.tankontank.engine.Orientation;
public abstract class Map extends Board
{
- private final Vector<Vector3> finalPath = new Vector<Vector3>(10);
- private final Vector<GridPoint2> possibleMoves = new Vector<GridPoint2>(20);
- private final Vector<GridPoint2> possibleTargets = new Vector<GridPoint2>(10);
+ private final ArrayList<Vector3> finalPath = new ArrayList<Vector3>(10);
+ private final ArrayList<GridPoint2> possibleMoves = new ArrayList<GridPoint2>(40);
+ private final ArrayList<GridPoint2> possibleTargets = new ArrayList<GridPoint2>(10);
private final HashSet<GridPoint2> possiblePaths = new HashSet<GridPoint2>(10);
protected abstract void setup();