コード例 #1
0
ファイル: TerasologyEngine.java プロジェクト: nahh/Terasology
  /**
   * This constructor initializes the engine by initializing its systems, subsystems and managers.
   * It also verifies that some required systems are up and running after they have been
   * initialized.
   *
   * @param subsystems Typical subsystems lists contain graphics, timer, audio and input subsystems.
   */
  public TerasologyEngine(Collection<EngineSubsystem> subsystems) {

    Stopwatch totalInitTime = Stopwatch.createStarted();

    this.subsystems = Queues.newArrayDeque(subsystems);

    try {
      logger.info("Initializing Terasology...");
      logEnvironmentInfo();

      SplashScreen.getInstance().post("Loading config file ...");

      initConfig();

      SplashScreen.getInstance().post("Pre-initialize subsystems ...");

      preInitSubsystems();

      // time must be set here as it is required by some of the managers.
      verifyRequiredSystemIsRegistered(Time.class);
      time = (EngineTime) CoreRegistry.get(Time.class);

      GameThread.setToCurrentThread();

      initManagers();

      SplashScreen.getInstance().post("Post-initialize subsystems ...");

      postInitSubsystems();

      verifyRequiredSystemIsRegistered(DisplayDevice.class);
      verifyRequiredSystemIsRegistered(RenderingSubsystemFactory.class);
      verifyRequiredSystemIsRegistered(InputSystem.class);

      SplashScreen.getInstance().post("Initialize assets ...");

      initAssets();

      // TODO: Review - The advanced monitor shouldn't be hooked-in this way (see issue #692)
      initAdvancedMonitor();

      engineState = EngineState.INITIALIZED;

    } catch (RuntimeException e) {
      logger.error("Failed to initialise Terasology", e);
      cleanup();
      throw e;
    }

    double seconds = 0.001 * totalInitTime.elapsed(TimeUnit.MILLISECONDS);
    logger.info("Initialization completed in {}sec.", String.format("%.2f", seconds));
  }
コード例 #2
0
  private void initialize() {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    Stopwatch totalInitTime = Stopwatch.createStarted();
    try {
      logger.info("Initializing Terasology...");
      logEnvironmentInfo();

      // TODO: Need to get everything thread safe and get rid of the concept of "GameThread" as much
      // as possible.
      GameThread.setToCurrentThread();

      preInitSubsystems();

      initManagers();

      initSubsystems();

      changeStatus(TerasologyEngineStatus.INITIALIZING_ASSET_MANAGEMENT);
      initAssets();

      EnvironmentSwitchHandler environmentSwitcher = new EnvironmentSwitchHandler();
      rootContext.put(EnvironmentSwitchHandler.class, environmentSwitcher);

      environmentSwitcher.handleSwitchToGameEnvironment(rootContext);

      postInitSubsystems();

      verifyInitialisation();

      /**
       * Prevent objects being put in engine context after init phase. Engine states should
       * use/create a child context.
       */
      CoreRegistry.setContext(null);
    } catch (RuntimeException e) {
      logger.error("Failed to initialise Terasology", e);
      cleanup();
      throw e;
    }

    double seconds = 0.001 * totalInitTime.elapsed(TimeUnit.MILLISECONDS);
    logger.info("Initialization completed in {}sec.", String.format("%.2f", seconds));
  }