|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.media.timer.CalibratingTimer
public abstract class CalibratingTimer
Calibrates timing values from a subclass' implementation of current against those returned by System.currentTimeMillis. If the subclass timer is moving 1.25 times faster or .75 times slower than currentTimeMillis, hold it to the values from currentTimeMillis.
| Field Summary | |
|---|---|
protected Interval |
_calibrateInterval
Interval that fires every five seconds to run the calibration. |
protected static RuntimeAdjust.BooleanAdjust |
_debugCalibrate
A debug hook that toggles dumping of calibration values. |
protected long |
_driftMilliStamp
currentTimeMillis() value from the last time we called calibrate. |
protected float |
_driftRatio
Ratio of currentTimeMillis to timer millis. |
protected long |
_driftTimerStamp
current() value from the last time we called calibrate. |
protected float |
_maxDriftRatio
The largest drift we've had to adjust for. |
protected long |
_microDivider
Amount by which current() should be divided to get microseconds. |
protected long |
_milliDivider
Amount by which current() should be divided to get milliseconds. |
protected long |
_priorCurrent
current() value when elapsed was called last. |
protected long |
_startStamp
current() value when the timer was started. |
protected static int |
CALIBRATE_INTERVAL
Milliseconds between calibrate calls. |
protected Logger |
log
Used to log things. |
protected static float |
MAX_ALLOWED_DRIFT_RATIO
The largest drift ratio we'll allow without correcting. |
protected static float |
MIN_ALLOWED_DRIFT_RATIO
The smallest drift ratio we'll allow without correcting. |
| Constructor Summary | |
|---|---|
CalibratingTimer()
|
|
| Method Summary | |
|---|---|
protected void |
calibrate()
Calculates the drift factor from the time elapsed from the last calibrate call. |
void |
clearMaxDriftRatio()
Clears out our remembered max drift. |
abstract long |
current()
Return the current value for this timer. |
protected long |
elapsed()
Returns the difference between _startStamp and current() |
long |
getElapsedMicros()
Returns the number of microseconds that have elapsed since the timer was created or last MediaTimer.reset(). |
long |
getElapsedMillis()
Returns the number of milliseconds that have elapsed since the timer was created or last MediaTimer.reset(). |
float |
getMaxDriftRatio()
Returns the greatest drift ratio we've had to compensate for. |
protected void |
init(long milliDivider,
long microDivider)
Initializes this timer. |
void |
reset()
Resets the timer's monotonically increasing value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected long _startStamp
protected long _priorCurrent
protected long _milliDivider
protected long _microDivider
protected long _driftMilliStamp
protected long _driftTimerStamp
protected float _driftRatio
protected float _maxDriftRatio
protected Interval _calibrateInterval
protected final Logger log
protected static final float MAX_ALLOWED_DRIFT_RATIO
protected static final float MIN_ALLOWED_DRIFT_RATIO
protected static final int CALIBRATE_INTERVAL
protected static RuntimeAdjust.BooleanAdjust _debugCalibrate
| Constructor Detail |
|---|
public CalibratingTimer()
| Method Detail |
|---|
protected void init(long milliDivider,
long microDivider)
milliDivider - - value by which current() must be divided to get millisecondsmicroDivider - - value by which current() must be divided to get microsecondspublic long getElapsedMicros()
MediaTimerMediaTimer.reset(). Note: the
accuracy of this method is highly dependent on the timer
implementation used.
getElapsedMicros in interface MediaTimerpublic long getElapsedMillis()
MediaTimerMediaTimer.reset(). Note: the
accuracy of this method is highly dependent on the timer
implementation used.
getElapsedMillis in interface MediaTimerpublic void reset()
MediaTimer
reset in interface MediaTimerpublic abstract long current()
public float getMaxDriftRatio()
public void clearMaxDriftRatio()
protected long elapsed()
protected void calibrate()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||