Search in sources :

Example 1 with DynmapWorld

use of org.dynmap.DynmapWorld in project WorldPainter by Captain-Chaos.

the class DynMapRenderer method render.

/**
 * Render the tile. Note that the returned image is only valid until the
 * next invocation of this method.
 *
 * @param cache The chunk cache from which to retrieve the world data to
 *              render.
 * @param tile The tile to render.
 * @return The rendered tile. <strong>Note:</strong> only valid until the
 * next invocation of this method!
 */
BufferedImage render(MapChunkCache cache, HDMapTile tile) {
    Color rslt = new Color();
    MapIterator mapiter = cache.getIterator(0, 0, 0);
    DynmapWorld world = tile.getDynmapWorld();
    int scaled = 0;
    if ((tile.boostzoom > 0) && MarkerAPIImpl.testTileForBoostMarkers(cache.getWorld(), perspective, tile.tx * TILE_WIDTH, tile.ty * TILE_HEIGHT, TILE_WIDTH)) {
        scaled = tile.boostzoom;
    }
    int sizescale = 1 << scaled;
    /* Build shader state object for each shader */
    HDShaderState shaderstate = map.getShader().getStateInstance(map, cache, mapiter, sizescale * basemodscale);
    /* Check if nether world */
    boolean isnether = world.isNether();
    // Mark the tiles we're going to render as validated
    MapTypeState mts = world.getMapState(map);
    if (mts != null) {
        mts.validateTile(tile.tx, tile.ty);
    }
    /* Create perspective state object */
    OurPerspectiveState ps = new OurPerspectiveState(mapiter, isnether, scaled);
    ps.top = new Vector3D();
    ps.bottom = new Vector3D();
    ps.direction = new Vector3D();
    double xbase = tile.tx * TILE_WIDTH;
    double ybase = tile.ty * TILE_HEIGHT;
    boolean[] shaderdone = new boolean[1];
    double height = maxheight;
    if (height < 0) {
        /* Not set - assume world height - 1 */
        if (isnether)
            height = 127;
        else
            height = tile.getDynmapWorld().worldheight - 1;
    }
    for (int x = 0; x < TILE_WIDTH * sizescale; x++) {
        ps.px = x;
        for (int y = 0; y < TILE_HEIGHT * sizescale; y++) {
            ps.top.x = ps.bottom.x = xbase + ((double) x) / sizescale + 0.5;
            /* Start at center of pixel at Y=height+0.5, bottom at Y=-0.5 */
            ps.top.y = ps.bottom.y = ybase + ((double) y) / sizescale + 0.5;
            ps.top.z = height + 0.5;
            ps.bottom.z = minheight - 0.5;
            map_to_world.transform(ps.top);
            /* Transform to world coordinates */
            map_to_world.transform(ps.bottom);
            ps.direction.set(ps.bottom);
            ps.direction.subtract(ps.top);
            ps.py = y / sizescale;
            shaderstate.reset(ps);
            ps.raytrace(cache, shaderstate, shaderdone);
            if (!shaderdone[0]) {
                shaderstate.rayFinished(ps);
            } else {
                shaderdone[0] = false;
            }
            shaderstate.getRayColor(rslt, 0);
            int c_argb = rslt.getARGB();
            argb_buf[(TILE_HEIGHT * sizescale - y - 1) * TILE_WIDTH * sizescale + x] = c_argb;
        }
    }
    return buf_img;
}
Also used : Color(org.dynmap.Color) DynmapWorld(org.dynmap.DynmapWorld) MapTypeState(org.dynmap.MapTypeState)

Example 2 with DynmapWorld

use of org.dynmap.DynmapWorld in project dynmap by webbukkit.

the class DynmapExpCommand method saveWorlds.

private void saveWorlds() {
    File f = new File(core.getDataFolder(), "forgeworlds.yml");
    ConfigurationNode cn = new ConfigurationNode(f);
    ArrayList<HashMap<String, Object>> lst = new ArrayList<HashMap<String, Object>>();
    for (DynmapWorld fw : core.mapManager.getWorlds()) {
        HashMap<String, Object> vals = new HashMap<String, Object>();
        vals.put("name", fw.getRawName());
        vals.put("height", fw.worldheight);
        vals.put("sealevel", fw.sealevel);
        vals.put("nether", fw.isNether());
        vals.put("the_end", ((ForgeWorld) fw).isTheEnd());
        vals.put("title", fw.getTitle());
        lst.add(vals);
    }
    cn.put("worlds", lst);
    cn.put("isMCPC", isMCPC);
    cn.put("useSaveFolderAsName", useSaveFolder);
    cn.put("maxWorldHeight", ForgeWorld.getMaxWorldHeight());
    cn.save();
}
Also used : ConfigurationNode(org.dynmap.ConfigurationNode) DynIntHashMap(org.dynmap.utils.DynIntHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DynmapWorld(org.dynmap.DynmapWorld) TextComponentString(net.minecraft.util.text.TextComponentString) File(java.io.File)

Example 3 with DynmapWorld

use of org.dynmap.DynmapWorld in project dynmap by webbukkit.

the class MapStorageResourceHandler method handle.

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    String path = baseRequest.getPathInfo();
    int soff = 0, eoff;
    // We're handling this request
    baseRequest.setHandled(true);
    if (core.getLoginRequired() && request.getSession(true).getAttribute(LoginServlet.USERID_ATTRIB) == null) {
        response.sendError(HttpStatus.UNAUTHORIZED_401);
        return;
    }
    if (path.charAt(0) == '/')
        soff = 1;
    eoff = path.indexOf('/', soff);
    if (soff < 0) {
        response.sendError(HttpStatus.NOT_FOUND_404);
        return;
    }
    String world = path.substring(soff, eoff);
    String uri = path.substring(eoff + 1);
    // If faces directory, handle faces
    if (world.equals("faces")) {
        handleFace(response, uri);
        return;
    }
    // If markers directory, handle markers
    if (world.equals("_markers_")) {
        handleMarkers(response, uri);
        return;
    }
    DynmapWorld w = null;
    if (core.mapManager != null) {
        w = core.mapManager.getWorld(world);
    }
    // If world not found quit
    if (w == null) {
        response.setContentType("image/png");
        OutputStream os = response.getOutputStream();
        os.write(blankpng);
        return;
    }
    // Get storage handler
    MapStorage store = w.getMapStorage();
    // Get tile reference, based on URI and world
    MapStorageTile tile = store.getTile(w, uri);
    if (tile == null) {
        response.setContentType("image/png");
        OutputStream os = response.getOutputStream();
        os.write(blankpng);
        return;
    }
    // Read tile
    TileRead tr = null;
    if (tile.getReadLock(5000)) {
        tr = tile.read();
        tile.releaseReadLock();
    }
    response.setHeader("Cache-Control", "max-age=0,must-revalidate");
    String etag;
    if (tr == null) {
        etag = "\"" + blankpnghash + "\"";
    } else {
        etag = "\"" + tr.hashCode + "\"";
    }
    response.setHeader("ETag", etag);
    String ifnullmatch = request.getHeader("If-None-Match");
    if ((ifnullmatch != null) && ifnullmatch.equals(etag)) {
        response.sendError(HttpStatus.NOT_MODIFIED_304);
        return;
    }
    if (tr == null) {
        response.setContentType("image/png");
        response.setIntHeader("Content-Length", blankpng.length);
        OutputStream os = response.getOutputStream();
        os.write(blankpng);
        return;
    }
    // Got tile, package up for response
    response.setDateHeader("Last-Modified", tr.lastModified);
    response.setIntHeader("Content-Length", tr.image.length());
    response.setContentType(tr.format.getContentType());
    ServletOutputStream out = response.getOutputStream();
    out.write(tr.image.buffer(), 0, tr.image.length());
    out.flush();
}
Also used : MapStorageTile(org.dynmap.storage.MapStorageTile) ServletOutputStream(javax.servlet.ServletOutputStream) TileRead(org.dynmap.storage.MapStorageTile.TileRead) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) DynmapWorld(org.dynmap.DynmapWorld) MapStorage(org.dynmap.storage.MapStorage)

Example 4 with DynmapWorld

use of org.dynmap.DynmapWorld in project dynmap by webbukkit.

the class DynmapExpCommands method handlePosN.

private boolean handlePosN(DynmapCommandSender sender, String[] args, ExportContext ctx, DynmapCore core, int n) {
    if ((sender instanceof DynmapPlayer) == false) {
        // Not a player
        sender.sendMessage("Only usable by player");
        return true;
    }
    DynmapPlayer plyr = (DynmapPlayer) sender;
    DynmapLocation loc = plyr.getLocation();
    DynmapWorld world = null;
    if (loc != null) {
        world = core.getWorld(loc.world);
    }
    if (world == null) {
        sender.sendMessage("Location not found for player");
        return true;
    }
    if (n == 0) {
        ctx.xmin = (int) Math.floor(loc.x);
        ctx.ymin = (int) Math.floor(loc.y);
        ctx.zmin = (int) Math.floor(loc.z);
    } else {
        ctx.xmax = (int) Math.floor(loc.x);
        ctx.ymax = (int) Math.floor(loc.y);
        ctx.zmax = (int) Math.floor(loc.z);
    }
    ctx.world = world.getName();
    return handleInfo(sender, args, ctx, core);
}
Also used : DynmapLocation(org.dynmap.DynmapLocation) DynmapWorld(org.dynmap.DynmapWorld) DynmapPlayer(org.dynmap.common.DynmapPlayer)

Example 5 with DynmapWorld

use of org.dynmap.DynmapWorld in project dynmap by webbukkit.

the class HDMapManager method getCachedFlags.

private boolean[] getCachedFlags(HDMapTile t) {
    String w = t.getDynmapWorld().getName();
    String k = w + "/" + t.perspective.getName();
    boolean[] flags = cached_data_flags_by_world_perspective.get(k);
    if (flags != null)
        return flags;
    flags = new boolean[4];
    cached_data_flags_by_world_perspective.put(k, flags);
    DynmapWorld dw = MapManager.mapman.worldsLookup.get(w);
    if (dw == null)
        return flags;
    for (MapType map : dw.maps) {
        if (map instanceof HDMap) {
            HDMap hdmap = (HDMap) map;
            if (hdmap.getPerspective() == t.perspective) {
                HDShader sh = hdmap.getShader();
                HDLighting lt = hdmap.getLighting();
                flags[BIOMEDATAFLAG] |= sh.isBiomeDataNeeded() | lt.isBiomeDataNeeded();
                flags[HIGHESTZFLAG] |= sh.isHightestBlockYDataNeeded() | lt.isHightestBlockYDataNeeded();
                flags[RAWBIOMEFLAG] |= sh.isRawBiomeDataNeeded() | lt.isRawBiomeDataNeeded();
                flags[BLOCKTYPEFLAG] |= sh.isBlockTypeDataNeeded() | lt.isBlockTypeDataNeeded();
            }
        }
    }
    return flags;
}
Also used : DynmapWorld(org.dynmap.DynmapWorld) MapType(org.dynmap.MapType)

Aggregations

DynmapWorld (org.dynmap.DynmapWorld)20 File (java.io.File)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 ConfigurationNode (org.dynmap.ConfigurationNode)8 Long2ObjectLinkedOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap)7 DynmapLocation (org.dynmap.DynmapLocation)3 DynIntHashMap (org.dynmap.utils.DynIntHashMap)3 Date (java.util.Date)2 HttpSession (javax.servlet.http.HttpSession)2 Client (org.dynmap.Client)2 Color (org.dynmap.Color)2 MapType (org.dynmap.MapType)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 ListIterator (java.util.ListIterator)1 Matcher (java.util.regex.Matcher)1 ServletOutputStream (javax.servlet.ServletOutputStream)1