public class UpdateLoop extends java.lang.Thread implements java.lang.AutoCloseable, ILoop
Modifier | Constructor and Description |
---|---|
protected |
UpdateLoop(java.lang.String name,
int tickRate) |
Modifier and Type | Method and Description |
---|---|
void |
attach(IUpdateable updatable)
Attaches the update method of the specified IUpdatable instance to be called
every tick.
|
void |
close() |
protected double |
delay()
This method determines how long the current tick should be delayed to match the expected delta time for the specified tick rate.
|
void |
detach(IUpdateable updatable)
Detaches the specified instance from the game loop.
|
long |
getDeltaTime()
Gets the total time in milliseconds that passed since the last tick.
|
protected long |
getExpectedDelta() |
double |
getProcessTime()
Gets the actual process time in milliseconds that was required during the last tick.
|
int |
getTickRate()
Gets the rate at which this loop performs its updates.
|
long |
getTicks()
Gets the total amount of ticks performed by this loop since it was started.
|
protected java.util.Set<IUpdateable> |
getUpdatables() |
protected void |
process()
Performs the actual workload of a tick.
|
void |
run()
The loop implementation, executing the
process() method which does the actual work. |
protected void |
setTickRate(int tickRate) |
void |
terminate()
Terminates the operation of this instance.
|
protected void |
update()
Calls the
update() procedure on all registered instances. |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
start
public void run()
process()
method which does the actual work.
It also tracks the processing time and the total number of performed ticks while making sure that the expected
tick rate is met by delaying the loop accordingly.run
in interface java.lang.Runnable
run
in class java.lang.Thread
process()
,
delay()
,
getDeltaTime()
,
getProcessTime()
public void terminate()
ILaunchable
terminate
in interface ILaunchable
public void close()
close
in interface java.lang.AutoCloseable
public void attach(IUpdateable updatable)
ILoop
public void detach(IUpdateable updatable)
ILoop
public long getTicks()
ILoop
getTicks
in interface ILoop
ILaunchable.start()
public int getTickRate()
ILoop
getTickRate
in interface ILoop
public long getDeltaTime()
ILoop
getDeltaTime
in interface ILoop
ILoop.getProcessTime()
public double getProcessTime()
ILoop
getProcessTime
in interface ILoop
ILoop.getDeltaTime()
protected java.util.Set<IUpdateable> getUpdatables()
protected void process()
protected long getExpectedDelta()
protected void update()
update()
procedure on all registered instances.IUpdateable.update()
protected double delay()
protected void setTickRate(int tickRate)