Ejemplo n.º 1
0
 public void deactivate() {
   try {
     _entityManager.save(
         new File(
             Terasology.getInstance().getWorldSavePath(getActiveWorldProvider().getTitle()),
             ENTITY_DATA_FILE),
         EntityManager.SaveFormat.Binary);
   } catch (IOException e) {
     _logger.log(Level.SEVERE, "Failed to save entities", e);
   }
   dispose();
   _entityManager.clear();
 }
Ejemplo n.º 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();
    }
  }