Have CalibratingTimer remember the largest drift it's seen, and let us get at that
via our FrameManager. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@439 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -22,34 +22,21 @@
|
||||
package com.threerings.media;
|
||||
|
||||
import java.applet.Applet;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.KeyEventDispatcher;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.RepaintManager;
|
||||
import javax.swing.JRootPane;
|
||||
import javax.swing.event.AncestorEvent;
|
||||
import javax.swing.event.AncestorListener;
|
||||
import javax.swing.RepaintManager;
|
||||
|
||||
import com.samskivert.swing.RuntimeAdjust;
|
||||
import com.samskivert.util.ListUtil;
|
||||
import com.samskivert.util.RunAnywhere;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.media.timer.CalibratingTimer;
|
||||
import com.threerings.media.timer.MediaTimer;
|
||||
import com.threerings.media.timer.MillisTimer;
|
||||
import com.threerings.media.util.TrailingAverage;
|
||||
@@ -216,6 +203,19 @@ public abstract class FrameManager
|
||||
{
|
||||
return _timer.getElapsedMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highest drift ratio our timer has seen. 1.0 means no drift (and is what we return
|
||||
* if we're not using a CalibratingTimer)
|
||||
*/
|
||||
public double getMaxTimerDriftRatio ()
|
||||
{
|
||||
if (_timer instanceof CalibratingTimer) {
|
||||
return ((CalibratingTimer)_timer).getMaxDriftRatio();
|
||||
} else {
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an overlay that can be used to render sprites and animations on top of the entire
|
||||
|
||||
@@ -73,6 +73,14 @@ public abstract class CalibratingTimer
|
||||
_driftMilliStamp = System.currentTimeMillis();
|
||||
_driftTimerStamp = current();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the greatest drift ratio we've had to compensate for.
|
||||
*/
|
||||
public double getMaxDriftRatio ()
|
||||
{
|
||||
return _maxDriftRatio;
|
||||
}
|
||||
|
||||
/** Returns the difference between _startStamp and current() */
|
||||
protected long elapsed ()
|
||||
@@ -101,6 +109,9 @@ public abstract class CalibratingTimer
|
||||
if (drift > 1.25 || drift < 0.75) {
|
||||
Log.warning("Calibrating [drift=" + drift + "]");
|
||||
_driftRatio = drift;
|
||||
if (Math.abs(drift - 1.0) > Math.abs(_maxDriftRatio - 1.0)) {
|
||||
_maxDriftRatio = drift;
|
||||
}
|
||||
} else if (_driftRatio != 1.0) {
|
||||
// If we're within bounds now but we weren't before, reset _driftFactor and log it
|
||||
_driftRatio = 1.0;
|
||||
@@ -133,6 +144,9 @@ public abstract class CalibratingTimer
|
||||
|
||||
/** Ratio of currentTimeMillis to timer millis. */
|
||||
protected double _driftRatio = 1.0;
|
||||
|
||||
/** The largest drift we've had to adjust for. */
|
||||
protected double _maxDriftRatio = 1.0;
|
||||
|
||||
/** A debug hook that toggles dumping of calibration values. */
|
||||
protected static RuntimeAdjust.BooleanAdjust _debugCalibrate = new RuntimeAdjust.BooleanAdjust(
|
||||
|
||||
Reference in New Issue
Block a user