Пример #1
0
  public void update(float delta) {
    /* GUI */
    updateUserInterface();

    for (UpdateSubscriberSystem updater : _componentSystemManager.iterateUpdateSubscribers()) {
      PerformanceMonitor.startActivity(updater.getClass().getSimpleName());
      updater.update(delta);
    }

    if (_worldRenderer != null && shouldUpdateWorld()) _worldRenderer.update(delta);

    if (!screenHasFocus()) _localPlayerSys.updateInput();

    if (screenHasFocus() || !shouldUpdateWorld()) {
      if (Mouse.isGrabbed()) {
        Mouse.setGrabbed(false);
        Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2);
      }
    } else {
      if (!Mouse.isGrabbed()) Mouse.setGrabbed(true);
    }

    // TODO: This seems a little off - plus is more of a UI than single player game state concern.
    // Move somewhere
    // more appropriate?
    boolean dead = true;
    for (EntityRef entity : _entityManager.iteratorEntities(LocalPlayerComponent.class)) {
      dead = entity.getComponent(LocalPlayerComponent.class).isDead;
    }
    if (dead) {
      _statusScreen.setVisible(true);
      _statusScreen.updateStatus("Sorry! Seems like you have died. :-(");
    } else {
      _statusScreen.setVisible(false);
    }
  }
Пример #2
0
  /** Init. a new random world. */
  public void initWorld(String title, String seed) {
    final FastRandom random = new FastRandom();

    // Get rid of the old world
    if (_worldRenderer != null) {
      _worldRenderer.dispose();
      _worldRenderer = null;
    }

    if (seed == null) {
      seed = random.randomCharacterString(16);
    } else if (seed.isEmpty()) {
      seed = random.randomCharacterString(16);
    }

    Terasology.getInstance()
        .getLogger()
        .log(Level.INFO, "Creating new World with seed \"{0}\"", seed);

    // Init. a new world
    _worldRenderer = new WorldRenderer(title, seed, _entityManager, _localPlayerSys);

    File entityDataFile =
        new File(Terasology.getInstance().getWorldSavePath(title), ENTITY_DATA_FILE);
    _entityManager.clear();
    if (entityDataFile.exists()) {
      try {
        _entityManager.load(entityDataFile, EntityManager.SaveFormat.Binary);
      } catch (IOException e) {
        _logger.log(Level.SEVERE, "Failed to load entity data", e);
      }
    }

    LocalPlayer localPlayer = null;
    Iterator<EntityRef> iterator =
        _entityManager.iteratorEntities(LocalPlayerComponent.class).iterator();
    if (iterator.hasNext()) {
      localPlayer = new LocalPlayer(iterator.next());
    } else {
      PlayerFactory playerFactory = new PlayerFactory(_entityManager);
      localPlayer =
          new LocalPlayer(
              playerFactory.newInstance(
                  new Vector3f(_worldRenderer.getWorldProvider().nextSpawningPoint())));
    }
    _worldRenderer.setPlayer(localPlayer);

    // Create the first Portal if it doesn't exist yet
    _worldRenderer.initPortal();

    fastForwardWorld();
    CoreRegistry.put(WorldRenderer.class, _worldRenderer);
    CoreRegistry.put(IWorldProvider.class, _worldRenderer.getWorldProvider());
    CoreRegistry.put(LocalPlayer.class, _worldRenderer.getPlayer());
    CoreRegistry.put(Camera.class, _worldRenderer.getActiveCamera());
    CoreRegistry.put(BulletPhysicsRenderer.class, _worldRenderer.getBulletRenderer());

    for (ComponentSystem system : _componentSystemManager.iterateAll()) {
      system.initialise();
    }
  }