示例#1
0
  /**
   * Runs the engine, including its main loop. This method is called only once per application
   * startup, which is the reason the GameState provided is the -initial- state rather than a
   * generic game state.
   *
   * @param initialState In at least one context (the PC facade) the GameState implementation
   *     provided as input may vary, depending if the application has or hasn't been started
   *     headless.
   */
  @Override
  public void run(GameState initialState) {
    try {
      CoreRegistry.putPermanently(GameEngine.class, this);
      changeState(initialState);
      engineState = EngineState.RUNNING;
      Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

      mainLoop(); // -THE- MAIN LOOP. Most of the application time and resources are spent here.
      cleanup();

    } catch (RuntimeException e) {
      logger.error("Uncaught exception, attempting clean game shutdown", e);
      try {
        cleanup();
      } catch (Throwable t) {
        logger.error("Clean game shutdown after an uncaught exception failed", t);
        logger.error("Rethrowing original exception");
      }
      throw e;
    } catch (Throwable t) {
      logger.error("Uncaught throwable", t);
      throw t;
    }
  }
示例#2
0
  private void initConfig() {
    if (Files.isRegularFile(Config.getConfigFile())) {
      try {
        config = Config.load(Config.getConfigFile());
      } catch (IOException e) {
        logger.error("Failed to load config", e);
        config = new Config();
      }
    } else {
      config = new Config();
    }
    if (!config.getDefaultModSelection().hasModule(TerasologyConstants.CORE_GAMEPLAY_MODULE)) {
      config.getDefaultModSelection().addModule(TerasologyConstants.CORE_GAMEPLAY_MODULE);
    }

    if (!validateServerIdentity()) {
      CertificateGenerator generator = new CertificateGenerator();
      CertificatePair serverIdentity = generator.generateSelfSigned();
      config
          .getSecurity()
          .setServerCredentials(serverIdentity.getPublicCert(), serverIdentity.getPrivateCert());
      config.save();
    }

    renderingConfig = config.getRendering();
    logger.info("Video Settings: " + renderingConfig.toString());
    CoreRegistry.putPermanently(Config.class, config);
  }
示例#3
0
  private void initManagers() {

    SplashScreen.getInstance().post("Loading modules ...");
    ModuleManager moduleManager =
        CoreRegistry.putPermanently(ModuleManager.class, new ModuleManagerImpl());

    SplashScreen.getInstance().post("Loading reflections ...");
    ReflectFactory reflectFactory =
        CoreRegistry.putPermanently(ReflectFactory.class, new ReflectionReflectFactory());
    CopyStrategyLibrary copyStrategyLibrary =
        CoreRegistry.putPermanently(
            CopyStrategyLibrary.class, new CopyStrategyLibrary(reflectFactory));

    CoreRegistry.putPermanently(
        TypeSerializationLibrary.class,
        new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary));

    SplashScreen.getInstance().post("Loading assets ...");
    AssetManager assetManager =
        CoreRegistry.putPermanently(
            AssetManager.class, new AssetManagerImpl(moduleManager.getEnvironment()));
    assetManager.setEnvironment(moduleManager.getEnvironment());
    CoreRegistry.putPermanently(CollisionGroupManager.class, new CollisionGroupManager());
    CoreRegistry.putPermanently(WorldGeneratorManager.class, new WorldGeneratorManager());
    CoreRegistry.putPermanently(ComponentSystemManager.class, new ComponentSystemManager());
    CoreRegistry.putPermanently(
        ParameterAdapterManager.class, ParameterAdapterManager.createCore());
    CoreRegistry.putPermanently(NetworkSystem.class, new NetworkSystemImpl(time));
    CoreRegistry.putPermanently(Game.class, new Game(this, time));
    assetManager.setEnvironment(moduleManager.getEnvironment());

    AssetType.registerAssetTypes(assetManager);
    ApplyModulesUtil.applyModules();
  }