|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.kolls.railworld.GameLoop
public abstract class GameLoop
Represents a time stepping update loop. The loop performs given behavior as often as possible
whilst still being consistent. To that end, the system maintains a count of the time required
to perform the operation and narrows its wait to be close to that time.
The wait time is automatically adjusted as the program progresses; thus, it is essential
that the behavior pays attention to the CLOCK_WAIT value to determine "how much"
of behavior or movement it should do at each step.
Note that if the user provides a clock wait through options, this will override
the adjusting algorithm and be fixed.
| Field Summary | |
|---|---|
static int |
CLOCK_WAIT
Time between each run of the behavior, in milliseconds. |
boolean |
paused
Set to true to suspend behavior but retain painting. |
| Constructor Summary | |
|---|---|
GameLoop(RailCanvas rc)
Constructs a gameloop. |
|
| Method Summary | |
|---|---|
static double |
feetPerStepSpeed(double vel)
Given a velocity in MPH, how many feet should we move per clock step? This is a convenience method. |
int |
fps()
Calculate the current target frames per second |
void |
gameLoop()
Begin the loop. |
protected abstract void |
prePaint()
Behavior to perform before painting occurs. |
protected abstract void |
run()
Behavior to perform after painting occurs. |
void |
runInLoop(java.lang.Runnable r)
Run some commands inside the game loop. |
void |
stop()
Stop the game loop. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public boolean paused
true to suspend behavior but retain painting.
Note that the loop continues to run and update the display, so display
events (scrolling, etc) are still possible.
public static int CLOCK_WAIT
| Constructor Detail |
|---|
public GameLoop(RailCanvas rc)
rc - A RailCanvas this loop should paint.| Method Detail |
|---|
public static double feetPerStepSpeed(double vel)
vel - The velocity in MPH, not to exceed Train.MAX_SPEED_MPH.
double indicating how many feet to move this clock step.public int fps()
public void gameLoop()
public void stop()
public void runInLoop(java.lang.Runnable r)
r - The commands to run.protected abstract void prePaint()
protected abstract void run()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||