FrameTimer .java

net.minecraft.util.FrameTimer (class): members: getLagometerValue, getLastIndex, parseIndex, getFrames, lastIndex, addFrame, frames, counter, getIndex.

net.minecraft.utilclass89 linescommon1.8 KB

API Surface (6)

void addFrame(long runningTime)
int getLagometerValue(long time, int multiplier)
int getLastIndex()
int getIndex()
int parseIndex(int rawIndex)
long[] getFrames()

Fields & Constants (4)

frames
lastIndex
counter
index

Full Source

FrameTimer.java89 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
public class FrameTimer
4
{
5
    /** An array with the last 240 frames */
6
    private final long[] frames = new long[240];
7
8
    /** The last index used when 240 frames have been set */
9
    private int lastIndex;
10
11
    /** A counter */
12
    private int counter;
13
14
    /** The next index to use in the array */
15
    private int index;
16
17
    /**
18
     * Add a frame at the next index in the array frames
19
     *  
20
     * @param runningTime The game's uptime in nanoseconds
21
     */
22
    public void addFrame(long runningTime)
23
    {
24
        this.frames[this.index] = runningTime;
25
        ++this.index;
26
27
        if (this.index == 240)
28
        {
29
            this.index = 0;
30
        }
31
32
        if (this.counter < 240)
33
        {
34
            this.lastIndex = 0;
35
            ++this.counter;
36
        }
37
        else
38
        {
39
            this.lastIndex = this.parseIndex(this.index + 1);
40
        }
41
    }
42
43
    /**
44
     * Return a value from time and multiplier to display the lagometer
45
     *  
46
     * @param time The time corresponding to the frame
47
     * @param multiplier Use to multiply
48
     */
49
    public int getLagometerValue(long time, int multiplier)
50
    {
51
        double d0 = (double)time / 1.6666666E7D;
52
        return (int)(d0 * (double)multiplier);
53
    }
54
55
    /**
56
     * Return the last index used when 240 frames have been set
57
     */
58
    public int getLastIndex()
59
    {
60
        return this.lastIndex;
61
    }
62
63
    /**
64
     * Return the index of the next frame in the array
65
     */
66
    public int getIndex()
67
    {
68
        return this.index;
69
    }
70
71
    /**
72
     * Change 240 to 0
73
     *  
74
     * @param rawIndex The index to parse
75
     */
76
    public int parseIndex(int rawIndex)
77
    {
78
        return rawIndex % 240;
79
    }
80
81
    /**
82
     * Return the array of frames
83
     */
84
    public long[] getFrames()
85
    {
86
        return this.frames;
87
    }
88
}
89

Deobfuscated MCP 1.8.9 source of FrameTimer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/FrameTimer.java), stored verbatim.