diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-01-11 12:16:49 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-01-11 12:16:49 +0100 |
commit | 5196c30138f4d659fb5176363421e61ba66228ba (patch) | |
tree | 89ff3c0059f4e8de85a69bec4f8211c3fe55bd51 /core/src/ch/asynk/rustanddust | |
parent | 7261b45159b79cf2c6fbd417a9e6e9b27eff13f8 (diff) | |
download | RustAndDust-5196c30138f4d659fb5176363421e61ba66228ba.zip RustAndDust-5196c30138f4d659fb5176363421e61ba66228ba.tar.gz |
use IterableStack, IterableSet and IterableQueue
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/Board.java | 13 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/PathBuilder.java | 22 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/SearchBoard.java | 14 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/Tile.java | 9 | ||||
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/TileSet.java | 12 |
5 files changed, 33 insertions, 37 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/Board.java b/core/src/ch/asynk/rustanddust/engine/Board.java index 119e850..9441dac 100644 --- a/core/src/ch/asynk/rustanddust/engine/Board.java +++ b/core/src/ch/asynk/rustanddust/engine/Board.java @@ -15,6 +15,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Matrix4; import ch.asynk.rustanddust.engine.util.IterableArray; +import ch.asynk.rustanddust.engine.util.IterableSet; 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 animationCount = 0; private final IterableArray<Animation> animations = new IterableArray<Animation>(10); private final IterableArray<Animation> nextAnimations = new IterableArray<Animation>(10); - private final IterableArray<Tile> tilesToDraw = new IterableArray<Tile>(20); + private final IterableSet<Tile> tilesToDraw = new IterableSet<Tile>(20); protected SelectedTile selectedTile; @@ -404,7 +405,7 @@ public abstract class Board implements Disposable, Animation if (tile.isObjective()) { tile.enableOverlay(o, false); tile.enableOverlay(moveable.getFaction().overlay(), true); - tilesToDraw.addUnique(tile); + tilesToDraw.add(tile); } } } @@ -415,7 +416,7 @@ public abstract class Board implements Disposable, Animation if (tile.isObjective()) { tile.enableOverlay(moveable.getFaction().overlay(), false); tile.enableOverlay(tile.belongsTo().overlay(), true); - tilesToDraw.addUnique(tile); + tilesToDraw.add(tile); } } } @@ -430,7 +431,7 @@ public abstract class Board implements Disposable, Animation public void enableOverlayOn(Tile tile, int i, boolean enable) { if (tile.enableOverlay(i, enable)) - tilesToDraw.addUnique(tile); + tilesToDraw.add(tile); else tilesToDraw.remove(tile); } @@ -438,7 +439,7 @@ public abstract class Board implements Disposable, Animation public void enableOverlayOn(Tile tile, int i, Orientation o, boolean enable) { if (tile.enableOverlay(i, enable, o.r())) - tilesToDraw.addUnique(tile); + tilesToDraw.add(tile); else tilesToDraw.remove(tile); } @@ -446,7 +447,7 @@ public abstract class Board implements Disposable, Animation private int pushPawnOnto(Pawn pawn, Tile tile) { if (!tile.isOffMap()) - tilesToDraw.addUnique(tile); + tilesToDraw.add(tile); return tile.push(pawn); } diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java index d5c79d9..ecc7634 100644 --- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java +++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java @@ -5,6 +5,8 @@ import java.util.List; import com.badlogic.gdx.utils.Disposable; import ch.asynk.rustanddust.engine.util.IterableArray; +import ch.asynk.rustanddust.engine.util.IterableStack; +import ch.asynk.rustanddust.engine.util.IterableSet; public class PathBuilder implements Disposable { @@ -15,17 +17,17 @@ public class PathBuilder implements Disposable public Tile to; public int distance; public Orientation orientation; - private List<Tile> stack; + private IterableStack<Tile> stack; private List<Tile> ctrlTiles; private List<Path> paths; private List<Path> filteredPaths; - private IterableArray<Tile> tiles; + private IterableSet<Tile> tiles; public PathBuilder(Board board, int tSize, int stSize, int ftSize, int psSize) { this.board = board; - this.tiles = new IterableArray<Tile>(tSize); - this.stack = new IterableArray<Tile>(stSize); + this.tiles = new IterableSet<Tile>(tSize); + this.stack = new IterableStack<Tile>(stSize); this.ctrlTiles = new IterableArray<Tile>(ftSize); this.paths = new IterableArray<Path>(psSize); this.filteredPaths = new IterableArray<Path>(psSize); @@ -194,7 +196,7 @@ public class PathBuilder implements Disposable clearPaths(); paths.add(path); for (Tile tile : path.tiles) - tiles.addUnique(tile); + tiles.add(tile); } private void findAllPaths(Tile from, int mvtLeft, int fitness, boolean roadMarch) @@ -217,7 +219,7 @@ public class PathBuilder implements Disposable Path path = Path.get(stack.size() + 1); for (Tile t: stack) { path.tiles.add(t); - tiles.addUnique(t); + tiles.add(t); } path.roadMarch = r; path.fitness = f; @@ -226,9 +228,9 @@ public class PathBuilder implements Disposable } if (l >= board.distance(next, to)) { - stack.add(next); + stack.push(next); findAllPaths(next, m, f, r); - stack.remove(stack.size() - 1); + stack.pop(); } } } @@ -259,11 +261,11 @@ public class PathBuilder implements Disposable filteredPaths.clear(); filteredPaths.add(path); tiles.clear(); - for (Tile tile : path.tiles) tiles.addUnique(tile); + for (Tile tile : path.tiles) tiles.add(tile); break; } else { filteredPaths.add(path); - for (Tile tile : path.tiles) tiles.addUnique(tile); + for (Tile tile : path.tiles) tiles.add(tile); } } } diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java index 7fd2ef6..583cee6 100644 --- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java +++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Collection; import ch.asynk.rustanddust.engine.util.IterableArray; +import ch.asynk.rustanddust.engine.util.IterableStack; +import ch.asynk.rustanddust.engine.util.IterableQueue; public class SearchBoard { @@ -35,9 +37,9 @@ public class SearchBoard private int searchCount; private Node nodes[]; - private IterableArray<Node> stack; - private IterableArray<Node> queue; - private IterableArray<Node> roadMarch; + private IterableStack<Node> stack; + private IterableQueue<Node> queue; + private IterableStack<Node> roadMarch; private IterableArray<Node> los; private boolean losBlocked; @@ -55,9 +57,9 @@ public class SearchBoard nodes[i + (j * cols)] = new Node((i + dx), j); } - this.queue = new IterableArray<Node>(30); - this.stack = new IterableArray<Node>(20); - this.roadMarch = new IterableArray<Node>(5); + this.queue = new IterableQueue<Node>(30); + this.stack = new IterableStack<Node>(20); + this.roadMarch = new IterableStack<Node>(5); this.los = new IterableArray<Node>(10); } diff --git a/core/src/ch/asynk/rustanddust/engine/Tile.java b/core/src/ch/asynk/rustanddust/engine/Tile.java index 20d8fd7..0fc3b10 100644 --- a/core/src/ch/asynk/rustanddust/engine/Tile.java +++ b/core/src/ch/asynk/rustanddust/engine/Tile.java @@ -8,7 +8,7 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import ch.asynk.rustanddust.engine.util.IterableArray; +import ch.asynk.rustanddust.engine.util.IterableStack; import ch.asynk.rustanddust.engine.gfx.Drawable; import ch.asynk.rustanddust.engine.gfx.StackedImages; @@ -31,7 +31,7 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn> protected float x; protected float y; private StackedImages overlays; - private IterableArray<Pawn> stack; + private IterableStack<Pawn> stack; protected Faction curFaction; protected Faction prevFaction; @@ -51,7 +51,7 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn> { this.col = col; this.row = row; - this.stack = new IterableArray<Pawn>(capacity); + this.stack = new IterableStack<Pawn>(capacity); this.curFaction = defaultFaction; this.prevFaction = defaultFaction; this.objective = Objective.NONE; @@ -117,8 +117,7 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn> protected Pawn getTopPawn() { - if (isEmpty()) return null; - return stack.get(stack.size() - 1); + return stack.getTop(); } public boolean hasUnits() diff --git a/core/src/ch/asynk/rustanddust/engine/TileSet.java b/core/src/ch/asynk/rustanddust/engine/TileSet.java index 233232e..2d8d750 100644 --- a/core/src/ch/asynk/rustanddust/engine/TileSet.java +++ b/core/src/ch/asynk/rustanddust/engine/TileSet.java @@ -1,8 +1,8 @@ package ch.asynk.rustanddust.engine; -import ch.asynk.rustanddust.engine.util.IterableArray; +import ch.asynk.rustanddust.engine.util.IterableSet; -public class TileSet extends IterableArray<Tile> +public class TileSet extends IterableSet<Tile> { private final Board board; @@ -17,12 +17,4 @@ public class TileSet extends IterableArray<Tile> for (Tile tile : this) board.enableOverlayOn(tile, i, enable); } - - @Override - public boolean add(Tile tile) - { - if (contains(tile)) return false; - super.add(tile); - return true; - } } |