|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.co.javagear.Throttle
public final class Throttle
Provides the speed throttling functionality based on System.currentTimeMillis() and Thread.sleep(). Heavily based on code by Arnon Cardoso.
Field Summary | |
---|---|
(package private) static boolean |
autoFS
Auto frame skip. |
(package private) static float |
avgFPS
Average FPS. |
(package private) static int |
DEFAULT_TARGET_FPS
Throttle, frameskip constants. |
(package private) static int |
DEFAULT_THROTTLE_STEP
Throttle, frameskip constants. |
(package private) static long |
fps
Frames per second. |
(package private) static int |
frameDuration
Amount of ms. |
(package private) static int |
frameNumber
Framenumber relative to last recalc. |
(package private) static int |
FRAMES_UNTIL_THROTTLE_RECALC
Throttle, frameskip constants. |
(package private) static int |
fskip
Frame skip. |
(package private) static float |
MAX_FPS_DEVIATION
Throttle, frameskip constants. |
(package private) static int |
MAX_FRAME_SKIP
Throttle, frameskip constants. |
(package private) static int |
MAX_THROTTLE_STEP
Throttle, frameskip constants. |
(package private) static int |
maxFPS
Maximum FPS. |
(package private) static int |
MIN_THROTTLE_STEP
Throttle, frameskip constants. |
(package private) static int |
minFPS
Minimum FPS. |
(package private) static long |
minimumSleep
Minimum sleeptime to have effect on the JVM. |
(package private) static long |
recalcCount
Count recalc for measuring avg fps. |
(package private) static long |
sleep
Amount of sleep time in ms. |
(package private) static long |
sumFPS
Sum frames per second for measuring avg FPS. |
(package private) static long |
t
Time in ms. |
(package private) static int |
targetFPS
The FPS that needs to be throttled to. |
(package private) static long |
tempT
Time in ms. |
(package private) static java.lang.Thread |
thread
The thread to throttle. |
(package private) static boolean |
throttle
Throttle is enabled by default. |
(package private) static int |
throttleStep
How fast the throttle changes sleep time. |
(package private) static boolean |
TRY_ALT_SKIP_CALC
Throttle, frameskip constants. |
Constructor Summary | |
---|---|
private |
Throttle()
This class only provides static methods and variables. |
Method Summary | |
---|---|
static void |
enable(boolean enable)
Enable throttle. |
static void |
enableAutoFrameSkip(boolean enable)
Enable/disable automatic frame skip. |
static float |
getAverageFPS()
Get the average FPS. |
static int |
getFPS()
Get current FPS. |
static int |
getFrameSkip()
Get current amount of frames to be skipped. |
static int |
getPercentage()
|
static long |
getSleep()
Get current sleep time in ms. |
static int |
getTargetFPS()
Get the target FPS. |
static void |
init(int fps,
java.lang.Thread thread)
Initialize the throttle. |
static boolean |
isAutoFrameSkip()
Returns true if automatic frame skip is enabled, false otherwise. |
static boolean |
isEnabled()
Returns true if throttling is enabled and false otherwise. |
private static void |
recalcTiming()
Called after FRAMES_UNTIL_THROTTLE_RECALC is reached. |
static void |
setFrameSkip(int skip)
Set the amount of frames to skip. |
static boolean |
skipFrame()
Returns true if a frame needs to be skipped, false otherwise. |
static void |
throttle()
Call this method each frame. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final int MAX_THROTTLE_STEP
static final int MIN_THROTTLE_STEP
static final int DEFAULT_THROTTLE_STEP
static final int DEFAULT_TARGET_FPS
static final int FRAMES_UNTIL_THROTTLE_RECALC
static final int MAX_FRAME_SKIP
static final float MAX_FPS_DEVIATION
static final boolean TRY_ALT_SKIP_CALC
static boolean throttle
static boolean autoFS
static long fps
static long sumFPS
static float avgFPS
static long sleep
static int targetFPS
static int throttleStep
static int minFPS
static int maxFPS
static long minimumSleep
static int fskip
static int frameDuration
static long t
static long tempT
static int frameNumber
static long recalcCount
static java.lang.Thread thread
Constructor Detail |
---|
private Throttle()
Method Detail |
---|
public static void init(int fps, java.lang.Thread thread)
fps
- the target number of frames persecond.thread
- the thread to throttle.public static void throttle()
public static long getSleep()
public static boolean skipFrame()
true
if a frame needs to be skipped, false
otherwise.
true
if a frame needs to be skipped, false
otherwise.public static void enableAutoFrameSkip(boolean enable)
enable
- true
to enable automatic frame skip, false
to disable.public static boolean isAutoFrameSkip()
true
if automatic frame skip is enabled, false
otherwise.
true
if automatic frame skip is enabled, false
otherwise.public static void enable(boolean enable)
enable
- true
to enable throttle, false
to disable.public static boolean isEnabled()
true
if throttling is enabled and false
otherwise.
true
if throttling is enabled and false
otherwise.public static void setFrameSkip(int skip)
skip
- the number of frames to skip.public static int getFrameSkip()
public static int getFPS()
public static int getTargetFPS()
public static float getAverageFPS()
public static int getPercentage()
private static void recalcTiming()
FRAMES_UNTIL_THROTTLE_RECALC
is reached.
Here the sleep time and auto frame skip is re-evaluated.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |