summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/engine/Path.java
blob: 8ed7f8d4f56c58e1d22b27e2b939e971f7a74ed1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ch.asynk.tankontank.engine;

import java.util.ArrayList;

import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.Disposable;

public class Path implements Disposable, Pool.Poolable
{
    private static final Pool<Path> pathPool = new Pool<Path>() {
        @Override
        protected Path newObject() {
            return new Path();
        }
    };

    public static Path get(int size)
    {
        Path p = pathPool.obtain();
        p.init(size);
        return p;
    }

    public static void clearPool()
    {
        pathPool.clear();
    }

    public int cost;
    public boolean roadMarch;
    public ArrayList<Tile> tiles;

    public Path()
    {
        this.cost = -1;
        this.roadMarch = true;
        this.tiles = null;
    }

    protected void init(int size)
    {
        if (tiles == null)
            tiles = new ArrayList<Tile>(size);
        else
            tiles. ensureCapacity(size);
    }

    @Override
    public void reset()
    {
        cost = -1;
        roadMarch = true;
        tiles.clear();
    }

    @Override
    public void dispose()
    {
        tiles.clear();
        pathPool.free(this);
    }
}