From 2cccffb7a8c8629f6e1f68447de42122a29e2356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 15 Oct 2014 11:28:50 +0200 Subject: Board: remove pawnsToDraw, directly draw Animations --- core/src/ch/asynk/tankontank/engine/Board.java | 41 ++++++++------------------ 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 0111d40..7fc9d8d 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -78,7 +78,6 @@ public abstract class Board implements Disposable private final ArrayList animations = new ArrayList(2); private final ArrayList nextAnimations = new ArrayList(2); private final LinkedHashSet tilesToDraw = new LinkedHashSet(); - private final LinkedHashSet pawnsToDraw = new LinkedHashSet(); protected Board(int cols, int rows) { @@ -94,7 +93,6 @@ public abstract class Board implements Disposable for (int i = 0; i < (cfg.cols * cfg.rows); i++) tiles[i].dispose(); tilesToDraw.clear(); - pawnsToDraw.clear(); for (int i = 0, n = nextAnimations.size(); i < n; i++) nextAnimations.get(i).dispose(); animations.clear(); @@ -197,12 +195,6 @@ public abstract class Board implements Disposable neighbours[5].set((coords.x - 1), (coords.y - 1)); } - private void addPawnAnimation(Pawn pawn, AnimationSequence seq) - { - pawnsToDraw.add(pawn); - nextAnimations.add(seq); - } - private void stats() { boolean print = false; @@ -212,11 +204,6 @@ public abstract class Board implements Disposable print = true; } - if (pawnCount != pawnsToDraw.size()) { - pawnCount = pawnsToDraw.size(); - print = true; - } - if (animationCount != animations.size()) { animationCount = animations.size(); print = true; @@ -232,11 +219,8 @@ public abstract class Board implements Disposable Iterator iter = animations.iterator(); while (iter.hasNext()) { Animation a = iter.next(); - Pawn p = a.getPawn(); - if (a.animate(delta)) { + if (a.animate(delta)) iter.remove(); - pawnsToDraw.remove(p); - } } for (int i = 0, n = nextAnimations.size(); i < n; i++) @@ -254,14 +238,12 @@ public abstract class Board implements Disposable } Iterator tileIter = tilesToDraw.iterator(); - while (tileIter.hasNext()) { + while (tileIter.hasNext()) tileIter.next().draw(batch); - } - Iterator pawnIter = pawnsToDraw.iterator(); - while (pawnIter.hasNext()) { - pawnIter.next().draw(batch); - } + Iterator animationIter = animations.iterator(); + while (animationIter.hasNext()) + animationIter.next().draw(batch); if (transform) batch.setTransformMatrix(prevTransform); @@ -276,9 +258,12 @@ public abstract class Board implements Disposable } Iterator iter = tilesToDraw.iterator(); - while (iter.hasNext()) { + while (iter.hasNext()) iter.next().drawDebug(debugShapes); - } + + Iterator animationIter = animations.iterator(); + while (animationIter.hasNext()) + animationIter.next().drawDebug(debugShapes); if (transform) debugShapes.setTransformMatrix(prevTransform); @@ -574,7 +559,7 @@ public abstract class Board implements Disposable } })); seq.addAnimation(whenDone); - addPawnAnimation(pawn, seq); + nextAnimations.add(seq); pawn.move(cost); } @@ -585,7 +570,7 @@ public abstract class Board implements Disposable v.set(p.x, p.y, o.r()); AnimationSequence seq = pawn.getRotateAnimation(v); seq.addAnimation(whenDone); - addPawnAnimation(pawn, seq); + nextAnimations.add(seq); vector3Pool.free(v); pawn.rotate(o); } @@ -602,7 +587,7 @@ public abstract class Board implements Disposable } })); seq.addAnimation(whenDone); - addPawnAnimation(pawn, seq); + nextAnimations.add(seq); pawn.revertLastMove(); } -- cgit v1.1-2-g2b99