示例#1
0
 /** Called when the game loop has exited. */
 protected void end() {
   synchronized (lifecycleListeners) {
     for (LifecycleListener listener : lifecycleListeners) {
       listener.pause();
       listener.dispose();
     }
   }
   listener.pause();
   listener.dispose();
   glfwTerminate();
   if (forceExit) System.exit(-1);
 }
示例#2
0
  /** Handles posted runnables, input, and rendering for each frame. */
  protected void frame() {
    if (!running) return;

    synchronized (runnables) {
      executedRunnables.clear();
      executedRunnables.addAll(runnables);
      runnables.clear();
    }
    if (executedRunnables.size > 0) {
      for (int i = 0; i < executedRunnables.size; i++) executedRunnables.get(i).run();
      if (!running) return;
      graphics.requestRendering();
    }

    input.update();

    long frameStartTime = System.nanoTime();
    int targetFPS =
        (graphics.isHidden() || graphics.isMinimized())
            ? hiddenFPS
            : //
            (graphics.isForeground() ? foregroundFPS : backgroundFPS);

    if (targetFPS == -1) { // Rendering is paused.
      if (!isPaused) listener.pause();
      isPaused = true;
    } else {
      if (isPaused) listener.resume();
      isPaused = false;
      if (graphics.shouldRender()) render(frameStartTime);
    }

    if (targetFPS != 0)
      sleep(
          targetFPS == -1
              ? 100
              : (int) (1000f / targetFPS - (System.nanoTime() - frameStartTime) / 1000000f));
  }
示例#3
0
 /**
  * Called when an uncaught exception happens in the game loop. Default implementation prints the
  * exception and calls System.exit(0).
  */
 protected void exception(Throwable ex) {
   ex.printStackTrace();
   System.exit(0);
 }