示例#1
0
文件: Region.java 项目: zuppers/mopar
 /**
  * @param x
  * @param y
  * @param plane
  * @return
  */
 public boolean isChunkUpdated(int x, int y, int plane) {
   if (blocks[plane][x][y] == null) {
     return false;
   }
   Block block = blocks[plane][x][y];
   return block.isUpdated();
 }
示例#2
0
文件: Region.java 项目: zuppers/mopar
  /** Resets the region. */
  public void reset() {
    for (Block block : updatedBlocks) {
      block.reset();
    }

    updatedBlocks.clear();
    updated = false;
  }
示例#3
0
文件: Region.java 项目: zuppers/mopar
  /**
   * @param is
   * @throws IOException
   */
  public void parse(InputStream is) throws IOException {
    DataInputStream dis = new DataInputStream(is);

    if (dis.readInt() != 0x4d52474e) {
      throw new IOException("Invalid file magic");
    }

    int format = dis.readByte();
    if (format > 1 || format < 1) {
      throw new IOException("Unsupported format");
    }

    int locHash = dis.readUnsignedShort();
    int regionX = locHash >> 8;
    int regionY = locHash & 0xff;
    if (x != regionX || y != regionY) {
      throw new IOException("Location mismatch");
    }

    int chk;
    while ((chk = dis.readUnsignedByte()) != chk_EOF) {
      switch (chk) {
        case chk_LOCALE:
          {
            int config = dis.readUnsignedShort();

            int loc = dis.readUnsignedShort();
            int x = loc >> 6 & 0x3f;
            int y = loc & 0x3f;
            int plane = loc >> 12;

            int ori = dis.readUnsignedByte();
            int type = ori >> 2;
            int orientation = ori & 0x3;

            int group = GameObjectGroup.getGroupForType(type);

            int chunkX = x >> 3, chunkY = y >> 3;
            int localX = x & 0x7, localY = y & 0x7;

            Block block = getBlock(plane, chunkX, chunkY);
            BlockTile tile = block.getTile(localX, localY);

            GameObject gameObject = new GameObject(config, type, orientation, true);
            tile.setLocale(group, gameObject);
          }
          break;

        case chk_CLIP:
          {
            int lhash;
            while ((lhash = dis.readUnsignedShort()) != clip_EOD) {
              int x = lhash >> 8 & 0x3f;
              int y = lhash >> 2 & 0x3f;
              int p = lhash & 0x3;

              int first = dis.readUnsignedByte();
              int value = first & 0x3f;

              int length = first >> 6 & 0x3;
              if (length >= 2) {
                value |= dis.readUnsignedByte() << 6;
              }

              if (length >= 3) {
                value |= dis.readUnsignedByte() << 14;
              }

              TraversalMap traversalMap = traversalMaps[p];
              traversalMap.set(x, y, value);
            }
          }
          break;

        case chk_NPC:
          {
            int type = dis.readUnsignedShort();

            int loc = dis.readUnsignedByte();
            int x = loc >> 6 & 0x3f;
            int y = loc & 0x3f;
            int plane = loc >> 12;
          }
          break;

        default:
          throw new IOException("Bad config code");
      }
    }
  }