Package puppyeyes.engine.LowerLevel

Source Code of puppyeyes.engine.LowerLevel.StepProcessor

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package puppyeyes.engine.LowerLevel;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import puppyeyes.engine.GameWindow;
import puppyeyes.engine.Level;
import puppyeyes.engine.Settings.GameSettings;

/**
*
* @author majora
*/
public class StepProcessor implements Runnable {
    ExecutorService stepPool;
    ScheduledExecutorService timer;
   

    public StepProcessor() {
        stepPool = Executors.newCachedThreadPool();
        timer = Executors.newSingleThreadScheduledExecutor();   
    }
   
    public void start(){
      timer.scheduleAtFixedRate(this, 0, 1000/GameSettings.stepsPerSecond, TimeUnit.MILLISECONDS);
    }

  @Override
  public void run(){
    // Get current level
    Level onScreen = GameWindow.getLevel();
     
    // Invoke call() on each actor
    try {
      stepPool.invokeAll(onScreen.getActorList());
    } catch (InterruptedException e1) {
      // Interrupt is the shutdown command in java, shouldn't circumvent it, the exception is here to allow cleanup
      Thread.currentThread().interrupt();
    }
  }
 
  /**
   * Called to shutdown the threads this StepProcessor started.
   */
  public void shutdown(){
    stepPool.shutdown();
    timer.shutdown();
  }

}
TOP

Related Classes of puppyeyes.engine.LowerLevel.StepProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.