Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created April 27, 2013 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmwaffles/5473932 to your computer and use it in GitHub Desktop.
Save warmwaffles/5473932 to your computer and use it in GitHub Desktop.
public class SomeUtilityClass {
private static final ThreadPoolExecutor threads = new ThreadPoolExecutor(
Runtime.getRuntime().availableProcessors(), 10,
10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100, true));
public static void scheduleTask(Runnable runnable) {
threads.execute(runnable);
}
}
//inputsystem
@Override
protected void processEntities(ImmutableBag<Entity> entities) {
if (useThreads) GDXGame.getInstance().scheduleTask(new InputTask(entities));
else new InputTask(entities).run();
}
public class InputTask implements Runnable {
private final ImmutableBag<Entity> entities;
public InputTask(ImmutableBag<Entity> entities) {
this.entities = entities;
}
@Override
public void run() {
for (int i = 0; i < entities.size(); i++) update(entities.get(i));
}
private void update(Entity e) {
InputC input = inputMapper.get(e);
if (input.controlling == Controlling.NotControlled) return;
if (input.controlling == Controlling.Controlling) {
input.keys = gdx.game.logic.Input.keys;
input.camDir = CameraHelper.getDirection();
}
input.process(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment