|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.brackeen.javagamebook.util.TimeSmoothie
public class TimeSmoothie
Smoothes out the jumps in time do to poor timer accuracy. This is a simple algorithm that is slightly inaccurate (the smoothed time may be slightly ahead of real time) but gives better-looking results.
| Field Summary | |
|---|---|
protected static long |
AVERAGE_PERIOD
Take the average of the last few samples during the last 100ms |
protected int |
firstIndex
|
protected static long |
FRAME_RATE_RECALC_PERIOD
How often to recalc the frame rate |
protected float |
frameRate
|
protected static long |
MAX_ELAPSED_TIME
Don't allow the elapsed time between frames to be more than 100 ms |
protected static int |
NUM_SAMPLES
|
protected static int |
NUM_SAMPLES_BITS
|
protected static int |
NUM_SAMPLES_MASK
|
protected int |
numFrames
|
protected int |
numSamples
|
protected long[] |
samples
|
protected long |
startTime
|
| Constructor Summary | |
|---|---|
TimeSmoothie()
|
|
| Method Summary | |
|---|---|
void |
addSample(long elapsedTime)
Adds a time sample. |
long |
getAverage()
Gets the average of the recorded time samples. |
float |
getFrameRate()
Gets the frame rate (number of calls to getTime() or addSample() in real time). |
long |
getTime(long elapsedTime)
Adds the specified time sample and returns the average of all the recorded time samples. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final long FRAME_RATE_RECALC_PERIOD
protected static final long MAX_ELAPSED_TIME
protected static final long AVERAGE_PERIOD
protected static final int NUM_SAMPLES_BITS
protected static final int NUM_SAMPLES
protected static final int NUM_SAMPLES_MASK
protected long[] samples
protected int numSamples
protected int firstIndex
protected int numFrames
protected long startTime
protected float frameRate
| Constructor Detail |
|---|
public TimeSmoothie()
| Method Detail |
|---|
public long getTime(long elapsedTime)
public void addSample(long elapsedTime)
public long getAverage()
public float getFrameRate()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||