コード例 #1
0
  @Override
  public boolean step() {
    EntityManager entityManager = context.get(EntityManager.class);
    WorldRenderer worldRenderer = context.get(WorldRenderer.class);

    Iterator<EntityRef> worldEntityIterator =
        entityManager.getEntitiesWith(WorldComponent.class).iterator();
    // TODO: Move the world renderer bits elsewhere
    if (worldEntityIterator.hasNext()) {
      EntityRef worldEntity = worldEntityIterator.next();
      worldRenderer.getChunkProvider().setWorldEntity(worldEntity);

      // get the world generator config from the world entity
      // replace the world generator values from the components in the world entity
      WorldGenerator worldGenerator = context.get(WorldGenerator.class);
      WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
      Map<String, Component> params = worldConfigurator.getProperties();
      for (Map.Entry<String, Component> entry : params.entrySet()) {
        Class<? extends Component> clazz = entry.getValue().getClass();
        Component comp = worldEntity.getComponent(clazz);
        if (comp != null) {
          worldConfigurator.setProperty(entry.getKey(), comp);
        }
      }
    } else {
      EntityRef worldEntity = entityManager.create();
      worldEntity.addComponent(new WorldComponent());
      worldRenderer.getChunkProvider().setWorldEntity(worldEntity);

      // transfer all world generation parameters from Config to WorldEntity
      WorldGenerator worldGenerator = context.get(WorldGenerator.class);
      SimpleUri generatorUri = worldGenerator.getUri();
      Config config = context.get(Config.class);

      // get the map of properties from the world generator.
      // Replace its values with values from the config set by the UI.
      // Also set all the components to the world entity.
      WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
      Map<String, Component> params = worldConfigurator.getProperties();
      for (Map.Entry<String, Component> entry : params.entrySet()) {
        Class<? extends Component> clazz = entry.getValue().getClass();
        Component comp = config.getModuleConfig(generatorUri, entry.getKey(), clazz);
        if (comp != null) {
          worldEntity.addComponent(comp);
          worldConfigurator.setProperty(entry.getKey(), comp);
        } else {
          worldEntity.addComponent(entry.getValue());
        }
      }
    }

    return true;
  }
コード例 #2
0
ファイル: InputSystem.java プロジェクト: ajerezg/Terasology
 private void mouseYEvent(Vector2i deltaMouse, float delta) {
   int yMovement = config.getInput().isMouseYAxisInverted() ? deltaMouse.y * -1 : deltaMouse.y;
   MouseAxisEvent event =
       new MouseYAxisEvent(yMovement * config.getInput().getMouseSensitivity(), delta);
   setupTarget(event);
   for (EntityRef entity : getInputEntities()) {
     entity.send(event);
     if (event.isConsumed()) {
       break;
     }
   }
 }
コード例 #3
0
ファイル: TerasologyEngine.java プロジェクト: nahh/Terasology
  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);
  }
コード例 #4
0
ファイル: TerasologyEngine.java プロジェクト: nahh/Terasology
  private boolean validateServerIdentity() {
    PrivateIdentityCertificate privateCert = config.getSecurity().getServerPrivateCertificate();
    PublicIdentityCertificate publicCert = config.getSecurity().getServerPublicCertificate();

    if (privateCert == null || publicCert == null) {
      return false;
    }

    // Validate the signature
    if (!publicCert.verifySelfSigned()) {
      logger.error("Server signature is not self signed! Generating new server identity.");
      return false;
    }

    return true;
  }
コード例 #5
0
 @Override
 public void initialise() {
   super.initialise();
   targetDistance = config.getRendering().getViewDistance().getChunkDistance().x * 8.0f;
   // TODO: This should come from somewhere, probably player entity
   // set the target distance to as far as the player can see. Used to get the focal distance for
   // effects such as DOF.
 }
コード例 #6
0
ファイル: InputSystem.java プロジェクト: ajerezg/Terasology
 private void mouseXEvent(Vector2i deltaMouse, float delta) {
   MouseAxisEvent event =
       new MouseXAxisEvent(deltaMouse.x * config.getInput().getMouseSensitivity(), delta);
   setupTarget(event);
   for (EntityRef entity : getInputEntities()) {
     entity.send(event);
     if (event.isConsumed()) {
       break;
     }
   }
 }
コード例 #7
0
  private boolean isSavingNecessary() {
    ChunkProvider chunkProvider = CoreRegistry.get(ChunkProvider.class);
    int unloadedChunkCount = unloadedAndUnsavedChunkMap.size();
    int loadedChunkCount = chunkProvider.getAllChunks().size();
    double totalChunkCount = unloadedChunkCount + loadedChunkCount;
    double percentageUnloaded = 100.0 * unloadedChunkCount / totalChunkCount;
    if (percentageUnloaded >= config.getSystem().getMaxUnloadedChunksPercentageTillSave()) {
      return true;
    }

    long currentTime = System.currentTimeMillis();
    if (nextAutoSave == null) {
      scheduleNextAutoSave();
      return false;
    }
    return currentTime >= nextAutoSave;
  }
コード例 #8
0
ファイル: TerasologyEngine.java プロジェクト: nahh/Terasology
  private void cleanup() {
    logger.info("Shutting down Terasology...");

    try {
      Iterator<EngineSubsystem> iter = subsystems.descendingIterator();
      while (iter.hasNext()) {
        EngineSubsystem subsystem = iter.next();
        subsystem.shutdown(config);
      }

      config.save();
      if (currentState != null) {
        currentState.dispose();
        currentState = null;
      }
    } finally {
      // Even if a graceful shutdown of the subsystems fails,
      // the thread pool has to be shut down
      stopThreads();
    }
  }
コード例 #9
0
 private void scheduleNextAutoSave() {
   long msBetweenAutoSave = config.getSystem().getMaxSecondsBetweenSaves() * 1000;
   nextAutoSave = System.currentTimeMillis() + msBetweenAutoSave;
 }
コード例 #10
0
ファイル: TerasologyEngine.java プロジェクト: nahh/Terasology
 /**
  * The Advanced Monitor is a display opening in a separate window allowing for monitoring of
  * Threads, Chunks and Performance.
  */
 private void initAdvancedMonitor() {
   if (config.getSystem().isMonitoringEnabled()) {
     new AdvancedMonitor().setVisible(true);
   }
 }