Search in sources :

Example 11 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("miny", fw.minY);
        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("useSaveFolderAsName", useSaveFolder);
    cn.put("maxWorldHeight", ForgeWorld.getMaxWorldHeight());
    cn.save();
}
Also used : ConfigurationNode(org.dynmap.ConfigurationNode) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DynmapWorld(org.dynmap.DynmapWorld) File(java.io.File)

Example 12 with DynmapWorld

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

the class IsoHDPerspective method render.

@Override
public boolean render(MapChunkCache cache, HDMapTile tile, String mapname) {
    final long startTimestamp = System.currentTimeMillis();
    Color rslt = new Color();
    MapIterator mapiter = cache.getIterator(0, 0, 0);
    DynmapWorld world = tile.getDynmapWorld();
    int tileSize = tile.getTileSize();
    int scaled = 0;
    if ((tile.boostzoom > 0) && MarkerAPIImpl.testTileForBoostMarkers(cache.getWorld(), this, tile.tx * tileSize, tile.ty * tileSize, tileSize)) {
        scaled = tile.boostzoom;
    }
    int sizescale = 1 << scaled;
    /* Build shader state object for each shader */
    HDShaderState[] shaderstate = MapManager.mapman.hdmapman.getShaderStateForTile(tile, cache, mapiter, mapname, sizescale * this.basemodscale);
    int numshaders = shaderstate.length;
    if (numshaders == 0)
        return false;
    /* Check if nether world */
    boolean isnether = world.isNether();
    /* Create buffered image for each */
    DynmapBufferedImage[] im = new DynmapBufferedImage[numshaders];
    DynmapBufferedImage[] dayim = new DynmapBufferedImage[numshaders];
    int[][] argb_buf = new int[numshaders][];
    int[][] day_argb_buf = new int[numshaders][];
    boolean[] isOpaque = new boolean[numshaders];
    int[] bgday = new int[numshaders];
    int[] bgnight = new int[numshaders];
    for (int i = 0; i < numshaders; i++) {
        HDLighting lighting = shaderstate[i].getLighting();
        im[i] = DynmapBufferedImage.allocateBufferedImage(tileSize * sizescale, tileSize * sizescale);
        argb_buf[i] = im[i].argb_buf;
        if (lighting.isNightAndDayEnabled()) {
            dayim[i] = DynmapBufferedImage.allocateBufferedImage(tileSize * sizescale, tileSize * sizescale);
            day_argb_buf[i] = dayim[i].argb_buf;
        }
        isOpaque[i] = !shaderstate[i].getMap().getImageFormat().getEncoding().hasAlpha;
        bgday[i] = shaderstate[i].getMap().getBackgroundARGBDay();
        bgnight[i] = shaderstate[i].getMap().getBackgroundARGBNight();
    }
    // Mark the tiles we're going to render as validated
    for (int i = 0; i < numshaders; i++) {
        MapTypeState mts = world.getMapState(shaderstate[i].getMap());
        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 * tileSize;
    double ybase = tile.ty * tileSize;
    boolean[] shaderdone = new boolean[numshaders];
    boolean[] rendered = new boolean[numshaders];
    double height = maxheight;
    if (height == Integer.MIN_VALUE) {
        /* Not set - assume world height - 1 */
        if (isnether)
            height = 127;
        else
            height = tile.getDynmapWorld().worldheight - 1;
    }
    double miny = minheight;
    if (miny == Integer.MIN_VALUE) {
        /* Not set - assume world height - 1 */
        miny = tile.getDynmapWorld().minY;
    }
    for (int x = 0; x < tileSize * sizescale; x++) {
        ps.px = x;
        for (int y = 0; y < tileSize * sizescale; y++) {
            ps.top.x = ps.bottom.x = xbase + (x + 0.5) / sizescale;
            /* Start at center of pixel at Y=height+0.5, bottom at Y=-0.5 */
            ps.top.y = ps.bottom.y = ybase + (y + 0.5) / sizescale;
            ps.top.z = height + 0.5;
            ps.bottom.z = miny - 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;
            for (int i = 0; i < numshaders; i++) {
                shaderstate[i].reset(ps);
            }
            try {
                ps.raytrace(cache, shaderstate, shaderdone);
            } catch (Exception ex) {
                Log.severe("Error while raytracing tile: perspective=" + this.name + ", coord=" + mapiter.getX() + "," + mapiter.getY() + "," + mapiter.getZ() + ", blockid=" + mapiter.getBlockType() + ", lighting=" + mapiter.getBlockSkyLight() + ":" + mapiter.getBlockEmittedLight() + ", biome=" + mapiter.getBiome().toString(), ex);
                ex.printStackTrace();
            }
            for (int i = 0; i < numshaders; i++) {
                if (shaderdone[i] == false) {
                    shaderstate[i].rayFinished(ps);
                } else {
                    shaderdone[i] = false;
                    rendered[i] = true;
                }
                shaderstate[i].getRayColor(rslt, 0);
                int c_argb = rslt.getARGB();
                if (c_argb != 0)
                    rendered[i] = true;
                if (isOpaque[i] && (c_argb == 0)) {
                    argb_buf[i][(tileSize * sizescale - y - 1) * tileSize * sizescale + x] = bgnight[i];
                } else {
                    argb_buf[i][(tileSize * sizescale - y - 1) * tileSize * sizescale + x] = c_argb;
                }
                if (day_argb_buf[i] != null) {
                    shaderstate[i].getRayColor(rslt, 1);
                    c_argb = rslt.getARGB();
                    if (isOpaque[i] && (c_argb == 0)) {
                        day_argb_buf[i][(tileSize * sizescale - y - 1) * tileSize * sizescale + x] = bgday[i];
                    } else {
                        day_argb_buf[i][(tileSize * sizescale - y - 1) * tileSize * sizescale + x] = c_argb;
                    }
                }
            }
        }
    }
    boolean renderone = false;
    /* Test to see if we're unchanged from older tile */
    MapStorage storage = world.getMapStorage();
    for (int i = 0; i < numshaders; i++) {
        long crc = MapStorage.calculateImageHashCode(argb_buf[i], 0, argb_buf[i].length);
        boolean tile_update = false;
        String prefix = shaderstate[i].getMap().getPrefix();
        MapStorageTile mtile = storage.getTile(world, shaderstate[i].getMap(), tile.tx, tile.ty, 0, MapType.ImageVariant.STANDARD);
        mtile.getWriteLock();
        try {
            if (mtile.matchesHashCode(crc) == false) {
                /* Wrap buffer as buffered image */
                if (rendered[i]) {
                    mtile.write(crc, im[i].buf_img, startTimestamp);
                } else {
                    mtile.delete();
                }
                MapManager.mapman.pushUpdate(tile.getDynmapWorld(), new Client.Tile(mtile.getURI()));
                tile_update = true;
                renderone = true;
            } else {
                if (!rendered[i]) {
                    mtile.delete();
                }
            }
        } finally {
            mtile.releaseWriteLock();
            DynmapBufferedImage.freeBufferedImage(im[i]);
        }
        MapManager.mapman.updateStatistics(tile, prefix, true, tile_update, !rendered[i]);
        /* Handle day image, if needed */
        if (dayim[i] != null) {
            crc = MapStorage.calculateImageHashCode(day_argb_buf[i], 0, day_argb_buf[i].length);
            mtile = storage.getTile(world, shaderstate[i].getMap(), tile.tx, tile.ty, 0, MapType.ImageVariant.DAY);
            mtile.getWriteLock();
            tile_update = false;
            try {
                if (mtile.matchesHashCode(crc) == false) {
                    /* Wrap buffer as buffered image */
                    if (rendered[i]) {
                        mtile.write(crc, dayim[i].buf_img, startTimestamp);
                    } else {
                        mtile.delete();
                    }
                    MapManager.mapman.pushUpdate(tile.getDynmapWorld(), new Client.Tile(mtile.getURI()));
                    tile_update = true;
                    renderone = true;
                } else {
                    if (!rendered[i]) {
                        mtile.delete();
                    }
                }
            } finally {
                mtile.releaseWriteLock();
                DynmapBufferedImage.freeBufferedImage(dayim[i]);
            }
            MapManager.mapman.updateStatistics(tile, prefix + "_day", true, tile_update, !rendered[i]);
        }
    }
    return renderone;
}
Also used : MapStorageTile(org.dynmap.storage.MapStorageTile) Color(org.dynmap.Color) MapIterator(org.dynmap.utils.MapIterator) MapTypeState(org.dynmap.MapTypeState) MapStorage(org.dynmap.storage.MapStorage) DynmapBufferedImage(org.dynmap.utils.DynmapBufferedImage) Vector3D(org.dynmap.utils.Vector3D) DynmapWorld(org.dynmap.DynmapWorld) Client(org.dynmap.Client)

Example 13 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("miny", fw.minY);
        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("useSaveFolderAsName", useSaveFolder);
    cn.put("maxWorldHeight", ForgeWorld.getMaxWorldHeight());
    cn.save();
}
Also used : ConfigurationNode(org.dynmap.ConfigurationNode) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DynmapWorld(org.dynmap.DynmapWorld) File(java.io.File)

Example 14 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("useSaveFolderAsName", useSaveFolder);
    cn.put("maxWorldHeight", ForgeWorld.getMaxWorldHeight());
    cn.save();
}
Also used : ConfigurationNode(org.dynmap.ConfigurationNode) DynIntHashMap(org.dynmap.utils.DynIntHashMap) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DynmapWorld(org.dynmap.DynmapWorld) File(java.io.File)

Example 15 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("useSaveFolderAsName", useSaveFolder);
    cn.put("maxWorldHeight", ForgeWorld.getMaxWorldHeight());
    cn.save();
}
Also used : ConfigurationNode(org.dynmap.ConfigurationNode) DynIntHashMap(org.dynmap.utils.DynIntHashMap) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DynmapWorld(org.dynmap.DynmapWorld) File(java.io.File)

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