Exemplo n.º 1
0
  /**
   * 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(TimeSubsystem timeSubsystem, Collection<EngineSubsystem> subsystems) {

    this.rootContext = new ContextImpl();
    this.timeSubsystem = timeSubsystem;
    /*
     * We can't load the engine without core registry yet.
     * e.g. the statically created MaterialLoader needs the CoreRegistry to get the AssetManager.
     * And the engine loads assets while it gets created.
     */
    // TODO: Remove
    CoreRegistry.setContext(rootContext);

    this.allSubsystems = Queues.newArrayDeque();
    this.allSubsystems.add(new ConfigurationSubsystem());
    this.allSubsystems.add(timeSubsystem);
    this.allSubsystems.addAll(subsystems);
    this.allSubsystems.add(new ThreadManagerSubsystem());
    this.allSubsystems.add(new MonitoringSubsystem());
    this.allSubsystems.add(new PhysicsSubsystem());
    this.allSubsystems.add(new CommandSubsystem());
    this.allSubsystems.add(new NetworkSubsystem());
    this.allSubsystems.add(new WorldGenerationSubsystem());
    this.allSubsystems.add(new GameSubsystem());
    this.allSubsystems.add(new I18nSubsystem());
  }
Exemplo n.º 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));
  }