From bb6a234d6631ad5bdf6f43b9ba101d133d3b2ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 9 Jan 2016 11:51:51 +0100 Subject: use ArrayListIt --- core/src/ch/asynk/rustanddust/engine/Board.java | 11 ++++++----- core/src/ch/asynk/rustanddust/engine/Path.java | 8 ++++---- core/src/ch/asynk/rustanddust/engine/PathBuilder.java | 7 ++++--- core/src/ch/asynk/rustanddust/engine/SearchBoard.java | 5 +++-- .../rustanddust/engine/gfx/animations/AnimationSequence.java | 11 +++++------ core/src/ch/asynk/rustanddust/game/UnitList.java | 4 ++-- core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java | 6 +++--- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/engine/Board.java b/core/src/ch/asynk/rustanddust/engine/Board.java index 6664d47..2e5a0b1 100644 --- a/core/src/ch/asynk/rustanddust/engine/Board.java +++ b/core/src/ch/asynk/rustanddust/engine/Board.java @@ -16,6 +16,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Matrix4; +import ch.asynk.rustanddust.engine.util.ArrayListIt; import ch.asynk.rustanddust.engine.gfx.Moveable; import ch.asynk.rustanddust.engine.gfx.Animation; import ch.asynk.rustanddust.engine.gfx.animations.AnimationSequence; @@ -61,7 +62,7 @@ public abstract class Board implements Disposable, Animation private int pawnCount = 0; private int animationCount = 0; private final ArrayList animations = new ArrayList(2); - private final ArrayList nextAnimations = new ArrayList(2); + private final ArrayListIt nextAnimations = new ArrayListIt(10); private final LinkedHashSet tilesToDraw = new LinkedHashSet(); protected SelectedTile selectedTile; @@ -128,8 +129,8 @@ public abstract class Board implements Disposable, Animation for (int i = 0; i < (this.cols * this.rows); i++) tiles[i].dispose(); tilesToDraw.clear(); - for (int i = 0, n = nextAnimations.size(); i < n; i++) - nextAnimations.get(i).dispose(); + for (Animation a : nextAnimations) + a.dispose(); animations.clear(); for (int i = 0, n = animations.size(); i < n; i++) animations.get(i).dispose(); @@ -263,8 +264,8 @@ public abstract class Board implements Disposable, Animation if (over && (animations.size() == 0)) animationsOver(); - for (int i = 0, n = nextAnimations.size(); i < n; i++) - animations.add(nextAnimations.get(i)); + for (Animation a : nextAnimations) + animations.add(a); nextAnimations.clear(); selectedTile.animate(delta); diff --git a/core/src/ch/asynk/rustanddust/engine/Path.java b/core/src/ch/asynk/rustanddust/engine/Path.java index 44b0a1f..6fd3c47 100644 --- a/core/src/ch/asynk/rustanddust/engine/Path.java +++ b/core/src/ch/asynk/rustanddust/engine/Path.java @@ -1,10 +1,10 @@ package ch.asynk.rustanddust.engine; -import java.util.ArrayList; - import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Disposable; +import ch.asynk.rustanddust.engine.util.ArrayListIt; + public class Path implements Disposable, Pool.Poolable { private static final Pool pathPool = new Pool() { @@ -29,7 +29,7 @@ public class Path implements Disposable, Pool.Poolable public int cost; public int fitness; public boolean roadMarch; - public ArrayList tiles; + public ArrayListIt tiles; public Path() { @@ -42,7 +42,7 @@ public class Path implements Disposable, Pool.Poolable protected void init(int size) { if (tiles == null) - tiles = new ArrayList(size); + tiles = new ArrayListIt(size); else tiles. ensureCapacity(size); cost = -1; diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java index 453583f..6a2b1a2 100644 --- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java +++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java @@ -1,6 +1,5 @@ package ch.asynk.rustanddust.engine; -import java.util.ArrayList; import java.util.List; import java.util.LinkedList; import java.util.HashSet; @@ -8,6 +7,8 @@ import java.util.LinkedHashSet; import com.badlogic.gdx.utils.Disposable; +import ch.asynk.rustanddust.engine.util.ArrayListIt; + public class PathBuilder implements Disposable { private final Board board; @@ -27,8 +28,8 @@ public class PathBuilder implements Disposable { this.board = board; this.tiles = new LinkedHashSet(tSize); - this.stack = new ArrayList(stSize); - this.ctrlTiles = new ArrayList(ftSize); + this.stack = new ArrayListIt(stSize); + this.ctrlTiles = new ArrayListIt(ftSize); this.paths = new LinkedList(); this.filteredPaths = new LinkedList(); this.to = null; diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java index f4bfd4c..19fa7a8 100644 --- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java +++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java @@ -1,12 +1,13 @@ package ch.asynk.rustanddust.engine; import java.util.List; -import java.util.ArrayList; import java.util.LinkedList; import java.util.ArrayDeque; import java.util.Iterator; import java.util.Collection; +import ch.asynk.rustanddust.engine.util.ArrayListIt; + public class SearchBoard { public class Node @@ -60,7 +61,7 @@ public class SearchBoard this.queue = new LinkedList(); this.stack = new ArrayDeque(20); this.roadMarch = new ArrayDeque(5); - this.los = new ArrayList(10); + this.los = new ArrayListIt(10); } private boolean inMap(int col, int row) diff --git a/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java b/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java index fdd1e80..d440adc 100644 --- a/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java +++ b/core/src/ch/asynk/rustanddust/engine/gfx/animations/AnimationSequence.java @@ -1,16 +1,15 @@ package ch.asynk.rustanddust.engine.gfx.animations; -import java.util.ArrayList; - import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.rustanddust.engine.gfx.Animation; +import ch.asynk.rustanddust.engine.util.ArrayListIt; public class AnimationSequence implements Animation, Pool.Poolable { - private ArrayList animations; + private ArrayListIt animations; private static final Pool animationSequencePool = new Pool() { @Override @@ -23,7 +22,7 @@ public class AnimationSequence implements Animation, Pool.Poolable { AnimationSequence seq = animationSequencePool.obtain(); if (seq.animations == null) - seq.animations = new ArrayList(capacity); + seq.animations = new ArrayListIt(capacity); else seq.animations.ensureCapacity(capacity); @@ -33,8 +32,8 @@ public class AnimationSequence implements Animation, Pool.Poolable @Override public void reset() { - for (int i = 0, n = animations.size(); i < n; i++) - animations.get(i).dispose(); + for (Animation a : animations) + a.dispose(); animations.clear(); } diff --git a/core/src/ch/asynk/rustanddust/game/UnitList.java b/core/src/ch/asynk/rustanddust/game/UnitList.java index 9637036..834dd98 100644 --- a/core/src/ch/asynk/rustanddust/game/UnitList.java +++ b/core/src/ch/asynk/rustanddust/game/UnitList.java @@ -1,11 +1,11 @@ package ch.asynk.rustanddust.game; import java.util.Collection; -import java.util.ArrayList; +import ch.asynk.rustanddust.engine.util.ArrayListIt; import ch.asynk.rustanddust.engine.Pawn; -public class UnitList extends ArrayList +public class UnitList extends ArrayListIt { public UnitList(int n) { diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java index a5c9b3d..7b7904d 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java @@ -2,7 +2,6 @@ package ch.asynk.rustanddust.game.battles; import java.util.Random; import java.util.HashMap; -import java.util.ArrayList; import ch.asynk.rustanddust.game.Army; import ch.asynk.rustanddust.game.Battle; @@ -15,6 +14,7 @@ import ch.asynk.rustanddust.game.Unit.UnitId; import ch.asynk.rustanddust.game.Factory; import ch.asynk.rustanddust.game.State.StateType; import ch.asynk.rustanddust.engine.Orientation; +import ch.asynk.rustanddust.engine.util.ArrayListIt; public abstract class BattleCommon implements Battle { @@ -28,8 +28,8 @@ public abstract class BattleCommon implements Battle protected Player currentPlayer; protected Player usPlayer; protected Player gePlayer; - protected ArrayList entryZone = new ArrayList(); - protected ArrayList exitZone = new ArrayList(); + protected ArrayListIt entryZone = new ArrayListIt(); + protected ArrayListIt exitZone = new ArrayListIt(); protected HashMap unitEntry = new HashMap(); protected HashMap unitExit = new HashMap(); -- cgit v1.1-2-g2b99