Created
April 27, 2013 17:47
-
-
Save warmwaffles/5473932 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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