aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/util/Vec3Cache.java
blob: 8e7ba601f7ed338ed53270562dc14994f82b0a38 (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
/*
 * Vec3Cache.java
 * Copyright (C) 2003
 *
 * $Id: Vec3Cache.java,v 1.2 2006-08-20 21:46:40 salomo Exp $
 */
package jake2.util;

/**
 * Vec3Cache contains float[3] for temporary usage.
 * The usage can reduce the garbage at runtime.
 *
 * @author cwei
 */
public final class Vec3Cache {
    
    private static final float[][] cache = new float[64][3];
    private static int index = 0;
    private static int max = 0;
    
    public static final float[] get() {
        //max = Math.max(index, max);
        return cache[index++];
    }
    
    public static final void release() {
        index--;
    }

    public static final void release(int count) {
        index-=count;
    }
    
    public static final void debug() {
        System.err.println("Vec3Cache: max. " + (max + 1) + " vectors used.");
    }
}