Ejemplo n.º 1
0
  @Override
  public void load() throws Exception {
    File file = Game.getInstance().getRelativeFile(Game.FILE_BASE_USER_DATA, "${world}/world.dat");

    if (!file.exists()) {
      System.err.println("No level data found! " + file.getPath());
      return;
    }

    DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));

    _world.setTime(dis.readFloat());

    _spawnPoint = new Vec3f();
    IOUtilities.readVec3f(dis, _spawnPoint);

    readDataPointList(dis, _rawHeights);
    readDataPointList(dis, _heights);
    readDataPointList(dis, _humidities);
    readDataPointList(dis, _temperatures);

    /* Tree Definitions */
    {
      int size = dis.readInt();
      for (int i = 0; i < size; ++i) {
        TreeDefinition dp2d = new TreeDefinition(0, 0, 0, 0);
        dp2d.x = dis.readInt();
        dp2d.y = dis.readInt();
        dp2d.z = dis.readInt();
        dp2d.type = dis.readByte();
      }
    }

    dis.close();
  }
Ejemplo n.º 2
0
  @Override
  public void save() throws Exception {
    File file = Game.getInstance().getRelativeFile(Game.FILE_BASE_USER_DATA, "${world}/world.dat");

    DataOutputStream dos =
        new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));

    dos.writeFloat(_world.getTime());

    IOUtilities.writeVec3f(dos, _spawnPoint);

    writeDataPointList(dos, _rawHeights);
    writeDataPointList(dos, _heights);
    writeDataPointList(dos, _humidities);
    writeDataPointList(dos, _temperatures);

    /* Tree Definitions */
    {
      dos.writeInt(_trees.size());
      for (int i = 0; i < _trees.size(); ++i) {
        TreeDefinition dp2d = _trees.get(i);
        dos.writeInt(dp2d.x);
        dos.writeInt(dp2d.y);
        dos.writeInt(dp2d.z);
        dos.writeByte(dp2d.type);
      }
    }

    dos.flush();
    dos.close();
  }