Beispiel #1
0
 /**
  * Un invokes a {@link Tick} from the {@link TickService}.
  *
  * @param tick The <b>tick</b> to un invoke.
  */
 public void unInvoke(Tick tick) {
   synchronized (TICK_SERVICE) {
     if (!TICK_SERVICE.getTicks().contains(tick))
       try {
         throw new IllegalAccessException(
             "The tick service must contain the specified tick in order to un invoke it.");
       } catch (IllegalAccessException e) {
         e.printStackTrace();
       }
     tick.destroyLater();
   }
 }
Beispiel #2
0
 /**
  * (non-Javadoc)
  *
  * @see java.lang.Runnable#run()
  */
 @Override
 public void run() {
   while (state != null && state.equals(WorkerState.LIVE)) {
     long startCycleTime = System.currentTimeMillis();
     TICK_SERVICE.performCycle();
     // calculates the amount of time it took to complete this game cycle
     elapsedCycleTime = (System.currentTimeMillis() - startCycleTime);
     cycleCount++;
     avg += elapsedCycleTime;
     // System.out.println("Cycle: " + cycleCount + ", Time: " + elapsedCycleTime + "ms, Average: "
     // + (avg/cycleCount) + "ms, Ticks: " + TICK_SERVICE.getTicks().size());
     if (GameClock.CYCLE_RATE > elapsedCycleTime) {
       try {
         Thread.sleep(GameClock.CYCLE_RATE - elapsedCycleTime);
       } catch (Exception e) {
         logger.error("Caught Engine Exception on Cycle: " + cycleCount, e);
       }
     } else {
       logger.warn("Skipped game cycle: " + cycleCount);
     }
   }
 }
Beispiel #3
0
 /**
  * Invokes a new {@link Tick} to the {@link TickService}.
  *
  * @param tick The <b>tick</b> to invoke.
  */
 public void invoke(Tick tick) {
   synchronized (TICK_SERVICE) {
     TICK_SERVICE.getTicks().add(tick);
   }
 }