public class Scheduler extends Object
Job renderJob = system.getScheduler().createJob("rendering", renderTasks); ExecutorService service = system.getScheduler().runEvery(1.0 / 60.0, renderJob); // ... perform game logic, and wait for exit request service.shutdown();
Constructor and Description |
---|
Scheduler(EntitySystem system)
Create a new Scheduler for the given EntitySystem.
|
Modifier and Type | Method and Description |
---|---|
Job |
createJob(String name,
Task... tasks)
Create a new job with the given name, that will execute the provided
tasks in order.
|
EntitySystem |
getEntitySystem() |
ExecutorService |
runContinuously(Job job)
Create an ExecutorService that is configured to execute the given job back to back
as fast as the job executes.
|
ExecutorService |
runEvery(double dt,
Job job)
Create an ExecutorService that is configured to execute the given job every
dt seconds.
|
void |
runOnCurrentThread(Job job)
Execute the given job on the current thread.
|
void |
runOnSeparateThread(Job job)
Execute the given job once on a new thread.
|
public Scheduler(EntitySystem system)
system
- The EntitySystem accessed by jobs created by this schedulerNullPointerException
- if system is nullEntitySystem.getScheduler()
public EntitySystem getEntitySystem()
public Job createJob(String name, Task... tasks)
name
- The name of the new jobtasks
- The tasks of the jobNullPointerException
- if name is null, tasks is null or contains null
elementspublic void runOnCurrentThread(Job job)
Job.run()
, and exists primarily to
parallel the other runX(Job) methods.job
- The job to runNullPointerException
- if job is nullIllegalArgumentException
- if job was not created by this schedulerpublic void runOnSeparateThread(Job job)
job
- The job to runNullPointerException
- if job is nullIllegalArgumentException
- if job was not created by this schedulerpublic ExecutorService runEvery(double dt, Job job)
runEvery(1.0 /
60.0, renderJob)
.
The returned ExecutorService should have its shutdown()
method called when the job no longer needs to be invoked. Scheduling
timing is undefined if new Runnables or Callables are submitted to the returned
service.dt
- The amount of time between the start of each job executionjob
- The job to be repeatedly executedNullPointerException
- if job is nullIllegalArgumentException
- if job was not created by this scheduler, or if dt
is negativepublic ExecutorService runContinuously(Job job)
while (true) { job.run(); }The returned ExecutorService should have its
shutdown()
method called when the job no longer needs to be invoked. Scheduling
timing is undefined if new Runnables or Callables are submitted to the returned
service.job
- The job to be repeatedly executedNullPointerException
- if job is nullIllegalArgumentException
- if job was not created by this schedulerCopyright © 2013. All Rights Reserved.