Beispiel #1
0
 public void setFullscreen(boolean state) {
   if (renderingConfig.isFullscreen() != state) {
     renderingConfig.setFullscreen(state);
     DisplayDevice display = CoreRegistry.get(DisplayDevice.class);
     display.setFullscreen(state);
   }
 }
Beispiel #2
0
 @Override
 public boolean hasFocus() {
   DisplayDevice display = CoreRegistry.get(DisplayDevice.class);
   return gameFocused && display.isActive();
 }
Beispiel #3
0
  /**
   * The main loop runs until the EngineState is set back to INITIALIZED by shutdown() or until the
   * OS requests the application's window to be closed. Engine cleanup and disposal occur
   * afterwards.
   */
  private void mainLoop() {
    NetworkSystem networkSystem = CoreRegistry.get(NetworkSystem.class);

    DisplayDevice display = CoreRegistry.get(DisplayDevice.class);

    PerformanceMonitor.startActivity("Other");
    // MAIN GAME LOOP
    while (engineState == EngineState.RUNNING && !display.isCloseRequested()) {

      long totalDelta;
      float updateDelta;
      float subsystemsDelta;

      // Only process rendering and updating once a second
      if (!display.isActive() && isHibernationAllowed()) {
        time.setPaused(true);
        Iterator<Float> updateCycles = time.tick();
        while (updateCycles.hasNext()) {
          updateCycles.next();
        }
        try {
          Thread.sleep(100);
        } catch (InterruptedException e) {
          logger.warn("Display inactivity sleep interrupted", e);
        }

        display.processMessages();
        time.setPaused(false);
        continue;
      }

      processPendingState();

      if (currentState == null) {
        shutdown();
        break;
      }

      Iterator<Float> updateCycles = time.tick();

      try (Activity ignored = PerformanceMonitor.startActivity("Network Update")) {
        networkSystem.update();
      }

      totalDelta = 0;
      while (updateCycles.hasNext()) {
        updateDelta = updateCycles.next(); // gameTime gets updated here!
        totalDelta += time.getDeltaInMs();
        try (Activity ignored = PerformanceMonitor.startActivity("Main Update")) {
          currentState.update(updateDelta);
        }
      }

      subsystemsDelta = totalDelta / 1000f;

      for (EngineSubsystem subsystem : getSubsystems()) {
        try (Activity ignored =
            PerformanceMonitor.startActivity(subsystem.getClass().getSimpleName())) {
          subsystem.preUpdate(currentState, subsystemsDelta);
        }
      }

      // Waiting processes are set by modules via GameThread.a/synch() methods.
      GameThread.processWaitingProcesses();

      for (EngineSubsystem subsystem : getSubsystems()) {
        try (Activity ignored =
            PerformanceMonitor.startActivity(subsystem.getClass().getSimpleName())) {
          subsystem.postUpdate(currentState, subsystemsDelta);
        }
      }

      PerformanceMonitor.rollCycle();
      PerformanceMonitor.startActivity("Other");
    }
    PerformanceMonitor.endActivity();

    // This becomes important only if display.isCloseRequested() is true.
    // In all other circumstances the EngineState is already set to
    // INITIALIZED by the time the flow gets here.
    engineState = EngineState.INITIALIZED;
  }