コード例 #1
0
ファイル: DynmapPlugin.java プロジェクト: zybey/dynmap
 private static DynmapLocation toLoc(Location l) {
   return new DynmapLocation(
       DynmapWorld.normalizeWorldName(l.getWorld().getName()),
       l.getBlockX(),
       l.getBlockY(),
       l.getBlockZ());
 }
コード例 #2
0
ファイル: NewMapChunkCache.java プロジェクト: Kademlia/dynmap
 /** Test if done loading */
 public boolean isDoneLoading() {
   if (dw.isLoaded() == false) {
     isempty = true;
     unloadChunks();
     return true;
   }
   if (iterator != null) return !iterator.hasNext();
   return false;
 }
コード例 #3
0
 @Override
 public void buildClientConfiguration(JSONObject worldObject, DynmapWorld world, KzedMap map) {
   JSONObject o = new JSONObject();
   s(o, "type", "KzedMapType");
   s(o, "name", name);
   s(o, "title", title);
   s(o, "icon", icon);
   s(o, "prefix", prefix);
   s(o, "background", bg_cfg);
   s(o, "nightandday", night_and_day);
   s(o, "backgroundday", bg_day_cfg);
   s(o, "backgroundnight", bg_night_cfg);
   s(o, "bigmap", map.isBigWorldMap(world));
   s(o, "mapzoomin", mapzoomin);
   s(o, "protected", is_protected);
   s(o, "mapzoomout", world.getExtraZoomOutLevels() + 1);
   if (MapManager.mapman.getCompassMode() != CompassMode.PRE19)
     s(o, "compassview", "NE"); /* Always from northeast */
   else s(o, "compassview", "SE"); /* Always from southeast */
   s(o, "image-format", ImageFormat.FORMAT_PNG.getFileExt());
   a(worldObject, "maps", o);
 }
コード例 #4
0
  public boolean render(MapChunkCache cache, KzedMapTile tile, File outputFile) {
    DynmapWorld world = tile.getDynmapWorld();
    boolean isnether = world.isNether();
    DynmapBufferedImage im =
        DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
    DynmapBufferedImage zim =
        DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth / 2, KzedMap.tileHeight / 2);

    DynmapBufferedImage im_day = null;
    DynmapBufferedImage zim_day = null;
    if (night_and_day) {
      im_day = DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth, KzedMap.tileHeight);
      zim_day =
          DynmapBufferedImage.allocateBufferedImage(KzedMap.tileWidth / 2, KzedMap.tileHeight / 2);
    }

    if (cache.getWorld().worldheight > 128) {
      if (maximumHeight == 127) maximumHeight = cache.getWorld().worldheight - 1;
    }
    int ix = tile.px / 2 + tile.py / 2 - ((127 - maximumHeight) / 2);
    int iy = maximumHeight;
    int iz = tile.px / 2 - tile.py / 2 + ((127 - maximumHeight) / 2);

    /* Don't mess with existing height-clipped renders */
    if (maximumHeight < 127) isnether = false;

    int jx, jz;

    int x, y;

    MapIterator mapiter = cache.getIterator(ix, iy, iz);

    Color c1 = new Color();
    Color c2 = new Color();
    int[] argb = im.argb_buf;
    int[] zargb = zim.argb_buf;
    Color c1_day = null;
    Color c2_day = null;
    int[] argb_day = null;
    int[] zargb_day = null;
    if (night_and_day) {
      c1_day = new Color();
      c2_day = new Color();
      argb_day = im_day.argb_buf;
      zargb_day = zim_day.argb_buf;
    }
    int rowoff = 0;
    /* draw the map */
    for (y = 0; y < KzedMap.tileHeight; ) {
      jx = ix;
      jz = iz;

      for (x = KzedMap.tileWidth - 1; x >= 0; x -= 2) {
        mapiter.initialize(jx, iy, jz);
        scan(world, 0, isnether, c1, c1_day, mapiter);
        mapiter.initialize(jx, iy, jz);
        scan(world, 2, isnether, c2, c2_day, mapiter);

        argb[rowoff + x] = c1.getARGB();
        argb[rowoff + x - 1] = c2.getARGB();

        if (night_and_day) {
          argb_day[rowoff + x] = c1_day.getARGB();
          argb_day[rowoff + x - 1] = c2_day.getARGB();
        }

        jx++;
        jz++;
      }

      y++;
      rowoff += KzedMap.tileWidth;

      jx = ix;
      jz = iz - 1;

      for (x = KzedMap.tileWidth - 1; x >= 0; x -= 2) {
        mapiter.initialize(jx, iy, jz);
        scan(world, 2, isnether, c1, c1_day, mapiter);
        jx++;
        jz++;
        mapiter.initialize(jx, iy, jz);
        scan(world, 0, isnether, c2, c2_day, mapiter);

        argb[rowoff + x] = c1.getARGB();
        argb[rowoff + x - 1] = c2.getARGB();

        if (night_and_day) {
          argb_day[rowoff + x] = c1_day.getARGB();
          argb_day[rowoff + x - 1] = c2_day.getARGB();
        }
      }
      y++;
      rowoff += KzedMap.tileWidth;

      ix++;
      iz--;
    }
    /* Now, compute zoomed tile - bilinear filter 2x2 -> 1x1 */
    doScaleWithBilinear(argb, zargb, KzedMap.tileWidth, KzedMap.tileHeight);
    if (night_and_day) {
      doScaleWithBilinear(argb_day, zargb_day, KzedMap.tileWidth, KzedMap.tileHeight);
    }

    /* Hand encoding and writing file off to MapManager */
    KzedZoomedMapTile zmtile = new KzedZoomedMapTile(tile.getDynmapWorld(), tile);
    File zoomFile = MapManager.mapman.getTileFile(zmtile);

    return doFileWrites(outputFile, tile, im, im_day, zmtile, zoomFile, zim, zim_day);
  }
コード例 #5
0
ファイル: NewMapChunkCache.java プロジェクト: Kademlia/dynmap
  public int loadChunks(int max_to_load) {
    if (dw.isLoaded() == false) return 0;
    long t0 = System.nanoTime();
    Object queue = helper.getUnloadQueue(helper.getNMSWorld(w));

    int cnt = 0;
    if (iterator == null) iterator = chunks.listIterator();

    DynmapCore.setIgnoreChunkLoads(true);
    // boolean isnormral = w.getEnvironment() == Environment.NORMAL;
    // Load the required chunks.
    while ((cnt < max_to_load) && iterator.hasNext()) {
      DynmapChunk chunk = iterator.next();
      boolean vis = true;
      if (visible_limits != null) {
        vis = false;
        for (VisibilityLimit limit : visible_limits) {
          if ((chunk.x >= limit.x0)
              && (chunk.x <= limit.x1)
              && (chunk.z >= limit.z0)
              && (chunk.z <= limit.z1)) {
            vis = true;
            break;
          }
        }
      }
      if (vis && (hidden_limits != null)) {
        for (VisibilityLimit limit : hidden_limits) {
          if ((chunk.x >= limit.x0)
              && (chunk.x <= limit.x1)
              && (chunk.z >= limit.z0)
              && (chunk.z <= limit.z1)) {
            vis = false;
            break;
          }
        }
      }
      /* Check if cached chunk snapshot found */
      ChunkSnapshot ss = null;
      DynIntHashMap tileData = null;
      SnapshotRec ssr =
          DynmapPlugin.plugin.sscache.getSnapshot(
              dw.getName(), chunk.x, chunk.z, blockdata, biome, biomeraw, highesty);
      if (ssr != null) {
        ss = ssr.ss;
        if (!vis) {
          if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) ss = STONE;
          else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) ss = OCEAN;
          else ss = EMPTY;
        }
        int idx = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
        snaparray[idx] = ss;
        snaptile[idx] = ssr.tileData;

        continue;
      }
      chunks_attempted++;
      boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
      boolean didload = false;
      boolean isunloadpending = false;
      if (queue != null) {
        isunloadpending = helper.isInUnloadQueue(queue, chunk.x, chunk.z);
      }
      if (isunloadpending) {
          /* Workaround: can't be pending if not loaded */
        wasLoaded = true;
      }
      try {
        if (!wasLoaded) {
          didload = w.loadChunk(chunk.x, chunk.z, false);
        } else {
            /* If already was loaded, no need to load */
          didload = true;
        }
      } catch (Throwable t) {
          /* Catch chunk error from Bukkit */
        Log.warning("Bukkit error loading chunk " + chunk.x + "," + chunk.z + " on " + w.getName());
        if (!wasLoaded) {
            /* If wasn't loaded, we loaded it if it now is */
          didload = w.isChunkLoaded(chunk.x, chunk.z);
        }
      }
      boolean didgenerate = false;
      /* If we didn't load, and we're supposed to generate, do it */
      if ((!didload) && do_generate && vis)
        didgenerate = didload = w.loadChunk(chunk.x, chunk.z, true);
      /* If it did load, make cache of it */
      if (didload) {
        tileData = new DynIntHashMap();

        Chunk c = w.getChunkAt(chunk.x, chunk.z); /* Get the chunk */
        /* Test if chunk isn't populated */
        boolean populated = true;
        // TODO: figure out why this doesn't appear to be reliable in Bukkit
        // if((nmschunk != null) && (doneflag != null)) {
        //    try {
        //        populated = doneflag.getBoolean(nmschunk);
        //    } catch (IllegalArgumentException e) {
        //    } catch (IllegalAccessException e) {
        //    }
        // }
        if (!vis) {
          if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) ss = STONE;
          else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) ss = OCEAN;
          else ss = EMPTY;
        } else if (!populated) {
            /* If not populated, treat as empty */
          ss = EMPTY;
        } else {
          if (blockdata || highesty) {
            ss = c.getChunkSnapshot(highesty, biome, biomeraw);
            if (use_spout) {
              ss = checkSpoutData(c, ss);
            }
            /* Get tile entity data */
            List<Object> vals = new ArrayList<Object>();
            Map tileents = helper.getTileEntitiesForChunk(c);
            for (Object t : tileents.values()) {
              int te_x = helper.getTileEntityX(t);
              int te_y = helper.getTileEntityY(t);
              int te_z = helper.getTileEntityZ(t);
              int cx = te_x & 0xF;
              int cz = te_z & 0xF;
              int blkid = ss.getBlockTypeId(cx, te_y, cz);
              int blkdat = ss.getBlockData(cx, te_y, cz);
              String[] te_fields = HDBlockModels.getTileEntityFieldsNeeded(blkid, blkdat);
              if (te_fields != null) {
                Object nbtcompound = helper.readTileEntityNBT(t);

                vals.clear();
                for (String id : te_fields) {
                  Object val = helper.getFieldValue(nbtcompound, id);
                  if (val != null) {
                    vals.add(id);
                    vals.add(val);
                  }
                }
                if (vals.size() > 0) {
                  Object[] vlist = vals.toArray(new Object[vals.size()]);
                  tileData.put(getIndexInChunk(cx, te_y, cz), vlist);
                }
              }
            }
          } else ss = w.getEmptyChunkSnapshot(chunk.x, chunk.z, biome, biomeraw);
          if (ss != null) {
            ssr = new SnapshotRec();
            ssr.ss = ss;
            ssr.tileData = tileData;
            DynmapPlugin.plugin.sscache.putSnapshot(
                dw.getName(), chunk.x, chunk.z, ssr, blockdata, biome, biomeraw, highesty);
          }
        }
        snaparray[(chunk.x - x_min) + (chunk.z - z_min) * x_dim] = ss;
        snaptile[(chunk.x - x_min) + (chunk.z - z_min) * x_dim] = tileData;

        /* If wasn't loaded before, we need to do unload */
        if (!wasLoaded) {
          chunks_read++;
          /* It looks like bukkit "leaks" entities - they don't get removed from the world-level table
           * when chunks are unloaded but not saved - removing them seems to do the trick */
          if (!(didgenerate && do_save)) {
            helper.removeEntitiesFromChunk(c);
          }
          /* Since we only remember ones we loaded, and we're synchronous, no player has
           * moved, so it must be safe (also prevent chunk leak, which appears to happen
           * because isChunkInUse defined "in use" as being within 256 blocks of a player,
           * while the actual in-use chunk area for a player where the chunks are managed
           * by the MC base server is 21x21 (or about a 160 block radius).
           * Also, if we did generate it, need to save it */
          w.unloadChunk(chunk.x, chunk.z, didgenerate && do_save, false);
        } else if (isunloadpending) {
            /* Else, if loaded and unload is pending */
          w.unloadChunkRequest(chunk.x, chunk.z); /* Request new unload */
        }
      }
      cnt++;
    }
    DynmapCore.setIgnoreChunkLoads(false);

    if (iterator.hasNext() == false) {
        /* If we're done */
      isempty = true;
      /* Fill missing chunks with empty dummy chunk */
      for (int i = 0; i < snaparray.length; i++) {
        if (snaparray[i] == null) snaparray[i] = EMPTY;
        else if (snaparray[i] != EMPTY) isempty = false;
      }
    }
    total_loadtime += System.nanoTime() - t0;

    return cnt;
  }