From 3c3a452b66a7c9d5e586125bbbabc999f971896a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 2 Oct 2014 20:07:29 +0200 Subject: Board: clean up API --- core/src/ch/asynk/tankontank/engine/Board.java | 46 ++++++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 7099326..d754883 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -300,6 +300,13 @@ public abstract class Board implements Disposable debugShapes.setTransformMatrix(prevTransform); } + public void clearNodesVector(Vector points) + { + for (GridPoint2 point : points) + gridPoint2Pool.free(point); + points.clear(); + } + private void nodesToPoints(List nodes, Vector points) { // for (GridPoint2 point : points) @@ -334,19 +341,26 @@ public abstract class Board implements Disposable points.setSize(ns); } - public void possibleMovesFrom(Pawn pawn, int col, int row, Vector moves) + public void possibleMovesFrom(Pawn pawn, GridPoint2 hex, Vector moves) { - List nodes = searchBoard.possibleMovesFrom(pawn, col, row); + List nodes = searchBoard.possibleMovesFrom(pawn, hex.x, hex.y); nodesToPoints(nodes, moves); } - public void possibleTargetsFrom(Pawn pawn, int col, int row, Vector targets) + public void possibleTargetsFrom(Pawn pawn, GridPoint2 hex, Vector targets) { - List nodes = searchBoard.possibleTargetsFrom(pawn, col, row); + List nodes = searchBoard.possibleTargetsFrom(pawn, hex.x, hex.y); nodesToPoints(nodes, targets); } - public int nodesToSet(List> nodes, Set points) + public void clearNodesSet(Set points) + { + for (GridPoint2 point : points) + gridPoint2Pool.free(point); + points.clear(); + } + + private int nodesToSet(List> nodes, Set points) { // FIXME : optimize this for (GridPoint2 point : points) @@ -367,9 +381,9 @@ public abstract class Board implements Disposable return nodes.size(); } - public int possiblePaths(Pawn pawn, int col0, int row0, int col1, int row1, Set points) + public int possiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to, Set points) { - List> paths = searchBoard.possiblePaths(pawn, col0, row0, col1, row1); + List> paths = searchBoard.possiblePaths(pawn, from.x, from.y, to.x, to.y); return nodesToSet(paths, points); } @@ -379,9 +393,14 @@ public abstract class Board implements Disposable return nodesToSet(paths, points); } - public void disableOverlaysOn(int col, int row) + public boolean hasUnits(GridPoint2 hex) { - disableOverlaysOn(getTile(col, row)); + return getTile(hex.x, hex.y).hasUnits(); + } + + public boolean isOffMap(GridPoint2 hex) + { + return getTile(hex.x, hex.y).isOffMap(); } public boolean isOverlayEnabledOn(int col, int row, int i) @@ -389,6 +408,11 @@ public abstract class Board implements Disposable return getTile(col, row).isOverlayEnabled(i); } + public void disableOverlaysOn(int col, int row) + { + disableOverlaysOn(getTile(col, row)); + } + public void disableOverlaysOn(Tile tile) { if (tile.disableOverlays()) @@ -397,9 +421,9 @@ public abstract class Board implements Disposable tilesToDraw.remove(tile); } - public void enableOverlayOn(int col, int row, int i, boolean enable) + public void enableOverlayOn(GridPoint2 hex, int i, boolean enable) { - enableOverlayOn(getTile(col, row), i, enable); + enableOverlayOn(getTile(hex.x, hex.y) , i, enable); } public void enableOverlayOn(Tile tile, int i, boolean enable) -- cgit v1.1-2-g2b99