Canned support for FPS display by the frame manager; it just can't manage
the dirty regions effectively. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2500 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: FrameManager.java,v 1.37 2003/04/26 17:56:25 mdb Exp $
|
// $Id: FrameManager.java,v 1.38 2003/04/29 18:14:37 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
@@ -99,15 +99,6 @@ import com.threerings.media.timer.SystemMediaTimer;
|
|||||||
*/
|
*/
|
||||||
public abstract class FrameManager
|
public abstract class FrameManager
|
||||||
{
|
{
|
||||||
/** {@link FrameParticipant}s can implement this interface and be
|
|
||||||
* added to the performance display. */
|
|
||||||
public static interface PerformanceProvider
|
|
||||||
{
|
|
||||||
/** Returns a string that will be appended to the debug
|
|
||||||
* performance display drawn on top of the frame. */
|
|
||||||
public void getPerformanceStatus (StringBuffer buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a frame manager that will use a {@link SystemMediaTimer} to
|
* Creates a frame manager that will use a {@link SystemMediaTimer} to
|
||||||
* obtain timing information, which is available on every platform,
|
* obtain timing information, which is available on every platform,
|
||||||
@@ -162,10 +153,6 @@ public abstract class FrameManager
|
|||||||
// handle repaints
|
// handle repaints
|
||||||
_remgr.setDoubleBufferingEnabled(false);
|
_remgr.setDoubleBufferingEnabled(false);
|
||||||
|
|
||||||
// register a debug hook to toggle the frame rate display
|
|
||||||
DebugChords.registerHook(
|
|
||||||
FPS_DISPLAY_MODMASK, FPS_DISPLAY_KEYCODE, FPS_DISPLAY_HOOK);
|
|
||||||
|
|
||||||
if (DEBUG_EVENTS) {
|
if (DEBUG_EVENTS) {
|
||||||
addTestListeners();
|
addTestListeners();
|
||||||
}
|
}
|
||||||
@@ -335,6 +322,22 @@ public abstract class FrameManager
|
|||||||
return (_ticker != null);
|
return (_ticker != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of ticks executed in the last second.
|
||||||
|
*/
|
||||||
|
public int getPerfTicks ()
|
||||||
|
{
|
||||||
|
return Math.round(_fps[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of ticks requested in the last second.
|
||||||
|
*/
|
||||||
|
public int getPerfTries ()
|
||||||
|
{
|
||||||
|
return Math.round(_fps[0]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to perform the frame processing and rendering.
|
* Called to perform the frame processing and rendering.
|
||||||
*/
|
*/
|
||||||
@@ -371,17 +374,9 @@ public abstract class FrameManager
|
|||||||
Log.logStackTrace(t);
|
Log.logStackTrace(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_displayPerf) {
|
|
||||||
startPerformanceStatusTick();
|
|
||||||
}
|
|
||||||
|
|
||||||
// tick all of our frame participants
|
// tick all of our frame participants
|
||||||
_participantTickOp.setTickStamp(tickStamp);
|
_participantTickOp.setTickStamp(tickStamp);
|
||||||
_participants.apply(_participantTickOp);
|
_participants.apply(_participantTickOp);
|
||||||
|
|
||||||
if (_displayPerf) {
|
|
||||||
finishPerformanceStatusTick();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -409,14 +404,6 @@ public abstract class FrameManager
|
|||||||
// repainted since the last tick
|
// repainted since the last tick
|
||||||
boolean pcomp = _remgr.paintComponents(gfx, this);
|
boolean pcomp = _remgr.paintComponents(gfx, this);
|
||||||
|
|
||||||
if (ppart || pcomp) {
|
|
||||||
if (_displayPerf && _perfLabel != null) {
|
|
||||||
// render the current performance status
|
|
||||||
gfx.setClip(null);
|
|
||||||
_perfLabel.render(gfx, FPS_X, FPS_Y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// let the caller know if anybody painted anything
|
// let the caller know if anybody painted anything
|
||||||
return (ppart || pcomp);
|
return (ppart || pcomp);
|
||||||
}
|
}
|
||||||
@@ -427,54 +414,6 @@ public abstract class FrameManager
|
|||||||
*/
|
*/
|
||||||
protected abstract void restoreFromBack (Rectangle dirty);
|
protected abstract void restoreFromBack (Rectangle dirty);
|
||||||
|
|
||||||
/**
|
|
||||||
* If frame rate display is enabled, builds beginning of performance
|
|
||||||
* status display.
|
|
||||||
*/
|
|
||||||
protected void startPerformanceStatusTick ()
|
|
||||||
{
|
|
||||||
if (_perfTicks++ % 100 == 0) {
|
|
||||||
_perfStatus = new StringBuffer();
|
|
||||||
_perfStatus.append("[FPS: ");
|
|
||||||
_perfStatus.append(Math.round(_fps[1])).append("/");
|
|
||||||
_perfStatus.append(Math.round(_fps[0]));
|
|
||||||
|
|
||||||
if (_perfLabel == null) {
|
|
||||||
_perfLabel = new Label(
|
|
||||||
"", Label.OUTLINE, Color.white, Color.black,
|
|
||||||
new Font("Arial", Font.PLAIN, 10));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If frame rate display is enabled, prepares to render new
|
|
||||||
* performance status if it has changed.
|
|
||||||
*/
|
|
||||||
protected void finishPerformanceStatusTick ()
|
|
||||||
{
|
|
||||||
if (_perfStatus == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_perfStatus.append("]");
|
|
||||||
_perfLabel.setText(_perfStatus.toString());
|
|
||||||
_perfStatus = null;
|
|
||||||
|
|
||||||
// dirty our previous bounds
|
|
||||||
JComponent comp = (JComponent)_frame.getRootPane();
|
|
||||||
Dimension lsize = _perfLabel.getSize();
|
|
||||||
_remgr.addDirtyRegion(comp, FPS_X, FPS_Y, lsize.width, lsize.height);
|
|
||||||
|
|
||||||
// re-layout our status label
|
|
||||||
Graphics2D gfx = (Graphics2D)_frame.getGraphics();
|
|
||||||
_perfLabel.layout(gfx);
|
|
||||||
gfx.dispose();
|
|
||||||
|
|
||||||
// dirty our new bounds
|
|
||||||
lsize = _perfLabel.getSize();
|
|
||||||
_remgr.addDirtyRegion(comp, FPS_X, FPS_Y, lsize.width, lsize.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders all components in all {@link JLayeredPane} layers that
|
* Renders all components in all {@link JLayeredPane} layers that
|
||||||
* intersect the supplied bounds.
|
* intersect the supplied bounds.
|
||||||
@@ -583,15 +522,6 @@ public abstract class FrameManager
|
|||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this frame participant is a performance provider,
|
|
||||||
// let the add their business to the performance status
|
|
||||||
if ((_perfStatus != null) &&
|
|
||||||
(observer instanceof PerformanceProvider)) {
|
|
||||||
_perfStatus.append(", ");
|
|
||||||
((PerformanceProvider)
|
|
||||||
observer).getPerformanceStatus(_perfStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
((FrameParticipant)observer).tick(_tickStamp);
|
((FrameParticipant)observer).tick(_tickStamp);
|
||||||
|
|
||||||
if (HANG_DEBUG) {
|
if (HANG_DEBUG) {
|
||||||
@@ -806,18 +736,6 @@ public abstract class FrameManager
|
|||||||
* "layered" components. */
|
* "layered" components. */
|
||||||
protected boolean[] _clipped = new boolean[1];
|
protected boolean[] _clipped = new boolean[1];
|
||||||
|
|
||||||
/** The label used to render peformance status. */
|
|
||||||
protected Label _perfLabel;
|
|
||||||
|
|
||||||
/** Used to build the performance status text. */
|
|
||||||
protected StringBuffer _perfStatus;
|
|
||||||
|
|
||||||
/** Used when reporting performance status. */
|
|
||||||
protected int _perfTicks;
|
|
||||||
|
|
||||||
/** Whether the performance status display is enabled. */
|
|
||||||
protected boolean _displayPerf;
|
|
||||||
|
|
||||||
/** The entites that are ticked each frame. */
|
/** The entites that are ticked each frame. */
|
||||||
protected ObserverList _participants =
|
protected ObserverList _participants =
|
||||||
new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
|
new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
|
||||||
@@ -840,12 +758,6 @@ public abstract class FrameManager
|
|||||||
* long. */
|
* long. */
|
||||||
protected static final boolean HANG_DEBUG = false;
|
protected static final boolean HANG_DEBUG = false;
|
||||||
|
|
||||||
/** The x-coordinate at which the frames per second is rendered. */
|
|
||||||
protected static final int FPS_X = 5;
|
|
||||||
|
|
||||||
/** The y-coordinate at which the frames per second is rendered. */
|
|
||||||
protected static final int FPS_Y = 27;
|
|
||||||
|
|
||||||
/** A debug hook that toggles debug rendering of sprite paths. */
|
/** A debug hook that toggles debug rendering of sprite paths. */
|
||||||
protected static RuntimeAdjust.BooleanAdjust _useFlip =
|
protected static RuntimeAdjust.BooleanAdjust _useFlip =
|
||||||
new RuntimeAdjust.BooleanAdjust(
|
new RuntimeAdjust.BooleanAdjust(
|
||||||
@@ -854,22 +766,6 @@ public abstract class FrameManager
|
|||||||
"[requires restart]", "narya.media.frame",
|
"[requires restart]", "narya.media.frame",
|
||||||
MediaPrefs.config, false);
|
MediaPrefs.config, false);
|
||||||
|
|
||||||
/** A debug hook that allows toggling the frame rate display. */
|
|
||||||
protected DebugChords.Hook FPS_DISPLAY_HOOK = new DebugChords.Hook() {
|
|
||||||
public void invoke () {
|
|
||||||
_displayPerf = !_displayPerf;
|
|
||||||
Log.info((_displayPerf ? "Enabling" : "Disabling") +
|
|
||||||
" performance status display.");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** The modifiers for our frame rate display debug hook (Alt+Shift). */
|
|
||||||
protected static int FPS_DISPLAY_MODMASK =
|
|
||||||
KeyEvent.ALT_DOWN_MASK|KeyEvent.SHIFT_DOWN_MASK;
|
|
||||||
|
|
||||||
/** The key code for our frame rate display debug hook (f). */
|
|
||||||
protected static int FPS_DISPLAY_KEYCODE = KeyEvent.VK_F;
|
|
||||||
|
|
||||||
/** Whether to enable AWT event debugging for the frame. */
|
/** Whether to enable AWT event debugging for the frame. */
|
||||||
protected static final boolean DEBUG_EVENTS = false;
|
protected static final boolean DEBUG_EVENTS = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user