Add support for limiting visible areas on each world, selective fill

of hidden areas (air, stone, ocean)
This commit is contained in:
Mike Primm 2011-06-16 23:37:28 -05:00
parent 81dbb8483f
commit ffc08173b4
6 changed files with 336 additions and 100 deletions

View File

@ -73,9 +73,9 @@ renderinterval: 1
enabletilehash: true
render-triggers:
# - chunkloaded
# - playermove
# - playerjoin
#- chunkloaded
#- playermove
#- playerjoin
- blockplaced
- blockbreak
- snowform
@ -124,8 +124,8 @@ templates:
# Template for normal world
normal:
enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
# # If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
center:
x: 0
y: 64
@ -136,19 +136,19 @@ templates:
title: "Flat"
prefix: flat
colorscheme: default
# To render a world as a "night view", set shadowstrength and ambientlight
# shadowstrength: 1.0
# ambientlight: 4
# To render both night and day versions of tiles (when ambientlight is set), set true
# night-and-day: true
# Option to turn on transparency support (off by default) - slows render
# transparency: true
# Background color for map during the day
# backgroundday: "#153E7E"
# Background color for map during the night
# backgroundnight: "#000000"
# Backgrounc color for map (independent of night/day)
# background: "#000000"
# # To render a world as a "night view", set shadowstrength and ambientlight
# shadowstrength: 1.0
# ambientlight: 4
# # To render both night and day versions of tiles (when ambientlight is set), set true
# night-and-day: true
# # Option to turn on transparency support (off by default) - slows render
# transparency: true
# # Background color for map during the day
# backgroundday: "#153E7E"
# # Background color for map during the night
# backgroundnight: "#000000"
# # Background color for map (independent of night/day)
# background: "#000000"
- class: org.dynmap.kzedmap.KzedMap
renderers:
- class: org.dynmap.kzedmap.DefaultTileRenderer
@ -157,30 +157,31 @@ templates:
prefix: t
maximumheight: 127
colorscheme: default
# Add shadows to world (based on top-down shadows from chunk data)
# shadowstrength: 1.0
# To render a world as a "night view", set shadowstrength and ambientlight
# ambientlight: 4
# To render both night and day versions of tiles (when ambientlight is set), set true
# night-and-day: true
# Option to turn off transparency support (on by default) - speeds render
# transparency: false
# Background color for map during the day
# backgroundday: "#153E7E"
# Background color for map during the night
# backgroundnight: "#000000"
# Backgrounc color for map (independent of night/day)
# background: "#000000"
# Sets the icon to 'images/block_custom.png'
# icon: custom
#- class: org.dynmap.kzedmap.HighlightTileRenderer
# prefix: ht
# maximumheight: 127
# colorscheme: default
# highlight: # For highlighting multiple block-types.
# - 56 # Highlight diamond-ore
# - 66 # Highlight minecart track
# highlight: 56 # For highlighting a single block-type.
# # Add shadows to world (based on top-down shadows from chunk data)
# shadowstrength: 1.0
# # To render a world as a "night view", set shadowstrength and ambientlight
# ambientlight: 4
# # To render both night and day versions of tiles (when ambientlight is set), set true
# night-and-day: true
# # Option to turn off transparency support (on by default) - speeds render
# transparency: false
# # Background color for map during the day
# backgroundday: "#153E7E"
# # Background color for map during the night
# backgroundnight: "#000000"
# # Background color for map (independent of night/day)
# background: "#000000"
# # Sets the icon to 'images/block_custom.png'
# icon: custom
# - class: org.dynmap.kzedmap.HighlightTileRenderer
# prefix: ht
# maximumheight: 127
# colorscheme: default
# highlight: # For highlighting multiple block-types.
# - 56 # Highlight diamond-ore
# - 66 # Highlight minecart track
# highlight: 56 # For highlighting a single block-type.
- class: org.dynmap.kzedmap.CaveTileRenderer
name: cave
title: "Cave"
@ -189,8 +190,8 @@ templates:
# Nether world template
nether:
enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
# # If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
center:
x: 0
y: 64
@ -216,8 +217,8 @@ templates:
# Skylands world template
skylands:
enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
# # If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true
center:
x: 0
y: 64
@ -269,6 +270,18 @@ worlds:
# - x: -15000
# y: 64
# z: -5000
# # Use visbilitylimits to restrict which areas of maps on your world to render (zero or more rectangles can be defined)
# visibilitylimits:
# - x0: -1000
# z0: -1000
# x1: 1000
# z1: 1000
# - x0: -2000
# z0: -1000
# x1: -1000
# z1: -500
# # Use hidestyle to control how hidden-but-existing chunks are to be rendered (air=empty air (same as ungenerated), stone=a flat stone plain, ocean=a flat ocean)
# hidestyle: stone
# Use 'template: mycustomtemplate' to use the properties specified in the template 'mycustomtemplate' to this world. Default it is set to the environment-name (normal or nether).
# template: mycustomtemplate
# Rest of comes from template - uncomment to tailor for world specifically
@ -277,7 +290,7 @@ worlds:
# y: 64
# z: 0
# # If bigworld set to true, use alternate directory layout better suited to large worlds
# # bigworld: true
# bigworld: true
# maps:
# - class: org.dynmap.flat.FlatMap
# name: flat
@ -285,18 +298,18 @@ worlds:
# prefix: flat
# colorscheme: default
# # To render a world as a "night view", set shadowstrength and ambientlight
# # shadowstrength: 1.0
# # ambientlight: 4
# shadowstrength: 1.0
# ambientlight: 4
# # To render both night and day versions of tiles (when ambientlight is set), set true
# # night-and-day: true
# night-and-day: true
# # Option to turn on transparency support (off by default) - slows render
# # transparency: true
# transparency: true
# # Background color for map during the day
# # backgroundday: "#153E7E"
# backgroundday: "#153E7E"
# # Background color for map during the night
# # backgroundnight: "#000000"
# backgroundnight: "#000000"
# # Backgrounc color for map (independent of night/day)
# # background: "#000000"
# background: "#000000"
# - class: org.dynmap.kzedmap.KzedMap
# renderers:
# - class: org.dynmap.kzedmap.DefaultTileRenderer
@ -306,29 +319,29 @@ worlds:
# maximumheight: 127
# colorscheme: default
# # Add shadows to world (based on top-down shadows from chunk data)
# # shadowstrength: 1.0
# shadowstrength: 1.0
# # To render a world as a "night view", set shadowstrength and ambientlight
# # ambientlight: 4
# ambientlight: 4
# # To render both night and day versions of tiles (when ambientlight is set), set true
# # night-and-day: true
# night-and-day: true
# # Option to turn off transparency support (on by default) - speeds render
# # transparency: false
# transparency: false
# # Background color for map during the day
# # backgroundday: "#153E7E"
# backgroundday: "#153E7E"
# # Background color for map during the night
# # backgroundnight: "#000000"
# backgroundnight: "#000000"
# # Backgrounc color for map (independent of night/day)
# # background: "#000000"
# background: "#000000"
# # Sets the icon to 'images/block_custom.png'
# # icon: custom
# #- class: org.dynmap.kzedmap.HighlightTileRenderer
# # prefix: ht
# # maximumheight: 127
# # colorscheme: default
# # highlight: # For highlighting multiple block-types.
# # - 56 # Highlight diamond-ore
# # - 66 # Highlight minecart track
# # highlight: 56 # For highlighting a single block-type.
# icon: custom
# - class: org.dynmap.kzedmap.HighlightTileRenderer
# prefix: ht
# maximumheight: 127
# colorscheme: default
# highlight: # For highlighting multiple block-types.
# - 56 # Highlight diamond-ore
# - 66 # Highlight minecart track
# highlight: 56 # For highlighting a single block-type.
# - class: org.dynmap.kzedmap.CaveTileRenderer
# name: cave
# title: "Cave"

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.World;
import org.bukkit.Location;
import org.dynmap.utils.MapChunkCache;
public class DynmapWorld {
public World world;
@ -12,6 +13,8 @@ public class DynmapWorld {
public UpdateQueue updates = new UpdateQueue();
public ConfigurationNode configuration;
public List<Location> seedloc;
public List<MapChunkCache.VisibilityLimit> visibility_limits;
public MapChunkCache.HiddenChunkStyle hiddenchunkstyle;
public int servertime;
public boolean sendposition;
public boolean sendhealth;

View File

@ -164,7 +164,7 @@ public class MapManager {
World w = world.world;
/* Fetch chunk cache from server thread */
DynmapChunk[] requiredChunks = tile.getMap().getRequiredChunks(tile);
MapChunkCache cache = createMapChunkCache(w, requiredChunks);
MapChunkCache cache = createMapChunkCache(world, requiredChunks);
if(cache == null) {
cleanup();
return; /* Cancelled/aborted */
@ -309,6 +309,29 @@ public class MapManager {
dynmapWorld.seedloc.add(lx);
}
}
/* Load visibility limits, if any are defined */
List<ConfigurationNode> vislimits = worldConfiguration.getNodes("visibilitylimits");
if(vislimits != null) {
dynmapWorld.visibility_limits = new ArrayList<MapChunkCache.VisibilityLimit>();
for(ConfigurationNode vis : vislimits) {
MapChunkCache.VisibilityLimit lim = new MapChunkCache.VisibilityLimit();
lim.x0 = vis.getInteger("x0", 0);
lim.x1 = vis.getInteger("x1", 0);
lim.z0 = vis.getInteger("z0", 0);
lim.z1 = vis.getInteger("z1", 0);
dynmapWorld.visibility_limits.add(lim);
/* Also, add a seed location for the middle of each visible area */
dynmapWorld.seedloc.add(new Location(w, (lim.x0+lim.x1)/2, 64, (lim.z0+lim.z1)/2));
}
}
String hiddenchunkstyle = worldConfiguration.getString("hidestyle", "stone");
if(hiddenchunkstyle.equals("air"))
dynmapWorld.hiddenchunkstyle = MapChunkCache.HiddenChunkStyle.FILL_AIR;
else if(hiddenchunkstyle.equals("ocean"))
dynmapWorld.hiddenchunkstyle = MapChunkCache.HiddenChunkStyle.FILL_OCEAN;
else
dynmapWorld.hiddenchunkstyle = MapChunkCache.HiddenChunkStyle.FILL_STONE_PLAIN;
// TODO: Make this less... weird...
// Insert the world on the same spot as in the configuration.
@ -416,7 +439,7 @@ public class MapManager {
/**
* Render processor helper - used by code running on render threads to request chunk snapshot cache from server/sync thread
*/
public MapChunkCache createMapChunkCache(final World w, final DynmapChunk[] chunks) {
public MapChunkCache createMapChunkCache(final DynmapWorld w, final DynmapChunk[] chunks) {
Callable<MapChunkCache> job = new Callable<MapChunkCache>() {
public MapChunkCache call() {
MapChunkCache c = null;
@ -428,7 +451,13 @@ public class MapManager {
}
if(c == null)
c = new LegacyMapChunkCache();
c.loadChunks(w, chunks);
if(w.visibility_limits != null) {
for(MapChunkCache.VisibilityLimit limit: w.visibility_limits) {
c.setVisibleRange(limit);
}
c.setHiddenFillStyle(w.hiddenchunkstyle);
}
c.loadChunks(w.world, chunks);
return c;
}
};

View File

@ -1,19 +1,20 @@
package org.dynmap.utils;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.lang.reflect.Field;
import java.util.LinkedList;
import org.bukkit.World;
import org.bukkit.Chunk;
import org.bukkit.entity.Entity;
import org.dynmap.DynmapChunk;
import org.dynmap.Log;
import java.util.List;
/**
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/
public class LegacyMapChunkCache implements MapChunkCache {
private World w;
private static Method getchunkdata = null;
private static Method gethandle = null;
private static Method poppreservedchunk = null;
@ -22,6 +23,8 @@ public class LegacyMapChunkCache implements MapChunkCache {
private int x_min, x_max, z_min, z_max;
private int x_dim;
private HiddenChunkStyle hidestyle = HiddenChunkStyle.FILL_AIR;
private List<VisibilityLimit> visible_limits = null;
private LegacyChunkSnapshot[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
@ -115,7 +118,7 @@ public class LegacyMapChunkCache implements MapChunkCache {
}
/**
* Chunk cache for representing unloaded chunk
* Chunk cache for representing unloaded chunk (or air chunk)
*/
private static class EmptyChunk implements LegacyChunkSnapshot {
public final int getBlockTypeId(int x, int y, int z) {
@ -131,11 +134,42 @@ public class LegacyMapChunkCache implements MapChunkCache {
return 0;
}
public final int getHighestBlockYAt(int x, int z) {
return 1;
return 0;
}
}
/**
* Chunk cache for representing hidden chunk as stone
*/
private static class PlainChunk implements LegacyChunkSnapshot {
private int fillid;
PlainChunk(int fillid) { this.fillid = fillid; }
public final int getBlockTypeId(int x, int y, int z) {
if(y < 64)
return fillid;
return 0;
}
public final int getBlockData(int x, int y, int z) {
return 0;
}
public final int getBlockSkyLight(int x, int y, int z) {
if(y < 64)
return 0;
return 15;
}
public final int getBlockEmittedLight(int x, int y, int z) {
return 0;
}
public final int getHighestBlockYAt(int x, int z) {
return 64;
}
}
private static final EmptyChunk EMPTY = new EmptyChunk();
private static final PlainChunk STONE = new PlainChunk(1);
private static final PlainChunk OCEAN = new PlainChunk(9);
/**
* Construct empty cache
@ -175,7 +209,6 @@ public class LegacyMapChunkCache implements MapChunkCache {
}
x_dim = x_max - x_min + 1;
}
this.w = w;
if(!initialized) {
try {
@ -208,22 +241,43 @@ public class LegacyMapChunkCache implements MapChunkCache {
if(gethandle != null) {
// Load the required chunks.
for (DynmapChunk chunk : chunks) {
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;
}
}
}
boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
boolean didload = w.loadChunk(chunk.x, chunk.z, false);
/* If it did load, make cache of it */
if(didload) {
Chunk c = w.getChunkAt(chunk.x, chunk.z);
try {
Object cc = gethandle.invoke(c);
byte[] buf = new byte[32768 + 16384 + 16384 + 16384]; /* Get big enough buffer for whole chunk */
getchunkdata.invoke(cc, buf, 0, 0, 0, 16, 128, 16, 0);
byte[] h = (byte[])heightmap.get(cc);
byte[] hmap = new byte[256];
System.arraycopy(h, 0, hmap, 0, 256);
CraftChunkSnapshot ss = new CraftChunkSnapshot(chunk.x, chunk.z, buf, hmap);
snaparray[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = ss;
} catch (Exception x) {
LegacyChunkSnapshot ss = null;
if(!vis) {
if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN)
ss = STONE;
else if(hidestyle == HiddenChunkStyle.FILL_OCEAN)
ss = OCEAN;
else
ss = EMPTY;
}
else {
Chunk c = w.getChunkAt(chunk.x, chunk.z);
try {
Object cc = gethandle.invoke(c);
byte[] buf = new byte[32768 + 16384 + 16384 + 16384]; /* Get big enough buffer for whole chunk */
getchunkdata.invoke(cc, buf, 0, 0, 0, 16, 128, 16, 0);
byte[] h = (byte[])heightmap.get(cc);
byte[] hmap = new byte[256];
System.arraycopy(h, 0, hmap, 0, 256);
ss = new CraftChunkSnapshot(chunk.x, chunk.z, buf, hmap);
} catch (Exception x) {
}
}
snaparray[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = ss;
}
if ((!wasLoaded) && didload) {
/* It looks like bukkit "leaks" entities - they don't get removed from the world-level table
@ -305,4 +359,33 @@ public class LegacyMapChunkCache implements MapChunkCache {
public MapIterator getIterator(int x, int y, int z) {
return new OurMapIterator(x, y, z);
}
/**
* Set hidden chunk style (default is FILL_AIR)
*/
public void setHiddenFillStyle(HiddenChunkStyle style) {
this.hidestyle = style;
}
/**
* Add visible area limit - can be called more than once
* Needs to be set before chunks are loaded
* Coordinates are block coordinates
*/
public void setVisibleRange(VisibilityLimit lim) {
VisibilityLimit limit = new VisibilityLimit();
if(lim.x0 > lim.x1) {
limit.x0 = (lim.x1 >> 4); limit.x1 = ((lim.x0+15) >> 4);
}
else {
limit.x0 = (lim.x0 >> 4); limit.x1 = ((lim.x1+15) >> 4);
}
if(lim.z0 > lim.z1) {
limit.z0 = (lim.z1 >> 4); limit.z1 = ((lim.z0+15) >> 4);
}
else {
limit.z0 = (lim.z0 >> 4); limit.z1 = ((lim.z1+15) >> 4);
}
if(visible_limits == null)
visible_limits = new ArrayList<VisibilityLimit>();
visible_limits.add(limit);
}
}

View File

@ -3,6 +3,14 @@ import org.bukkit.World;
import org.dynmap.DynmapChunk;
public interface MapChunkCache {
public enum HiddenChunkStyle {
FILL_AIR,
FILL_STONE_PLAIN,
FILL_OCEAN
};
public static class VisibilityLimit {
public int x0, x1, z0, z1;
}
/**
* Load chunks into cache
* @param w - world
@ -37,4 +45,14 @@ public interface MapChunkCache {
* Get cache iterator
*/
public MapIterator getIterator(int x, int y, int z);
/**
* Set hidden chunk style (default is FILL_AIR)
*/
public void setHiddenFillStyle(HiddenChunkStyle style);
/**
* Add visible area limit - can be called more than once
* Needs to be set before chunks are loaded
* Coordinates are block coordinates
*/
public void setVisibleRange(VisibilityLimit limit);
}

View File

@ -1,7 +1,9 @@
package org.dynmap.utils;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.World;
import org.bukkit.Chunk;
import org.bukkit.block.Biome;
@ -14,13 +16,13 @@ import org.dynmap.Log;
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/
public class NewMapChunkCache implements MapChunkCache {
private World w;
private static Method poppreservedchunk = null;
private int x_min, x_max, z_min, z_max;
private int x_dim;
private HiddenChunkStyle hidestyle = HiddenChunkStyle.FILL_AIR;
private List<VisibilityLimit> visible_limits = null;
private ChunkSnapshot[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
/**
@ -113,7 +115,7 @@ public class NewMapChunkCache implements MapChunkCache {
}
/**
* Chunk cache for representing unloaded chunk
* Chunk cache for representing unloaded chunk (or air)
*/
private static class EmptyChunk implements ChunkSnapshot {
/* Need these for interface, but not used */
@ -138,11 +140,49 @@ public class NewMapChunkCache implements MapChunkCache {
return 0;
}
public final int getHighestBlockYAt(int x, int z) {
return 1;
return 0;
}
}
/**
* Chunk cache for representing generic stone chunk
*/
private static class PlainChunk implements ChunkSnapshot {
private int fillid;
PlainChunk(int fillid) { this.fillid = fillid; }
/* Need these for interface, but not used */
public int getX() { return 0; }
public int getZ() { return 0; }
public String getWorldName() { return ""; }
public Biome getBiome(int x, int z) { return null; }
public double getRawBiomeTemperature(int x, int z) { return 0.0; }
public double getRawBiomeRainfall(int x, int z) { return 0.0; }
public long getCaptureFullTime() { return 0; }
public final int getBlockTypeId(int x, int y, int z) {
if(y < 64) return fillid;
return 0;
}
public final int getBlockData(int x, int y, int z) {
return 0;
}
public final int getBlockSkyLight(int x, int y, int z) {
if(y < 64)
return 0;
return 15;
}
public final int getBlockEmittedLight(int x, int y, int z) {
return 0;
}
public final int getHighestBlockYAt(int x, int z) {
return 64;
}
}
private static final EmptyChunk EMPTY = new EmptyChunk();
private static final PlainChunk STONE = new PlainChunk(1);
private static final PlainChunk OCEAN = new PlainChunk(9);
/**
* Construct empty cache
@ -191,17 +231,38 @@ public class NewMapChunkCache implements MapChunkCache {
}
x_dim = x_max - x_min + 1;
}
this.w = w;
snaparray = new ChunkSnapshot[x_dim * (z_max-z_min+1)];
// Load the required chunks.
for (DynmapChunk chunk : chunks) {
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;
}
}
}
boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
boolean didload = w.loadChunk(chunk.x, chunk.z, false);
/* If it did load, make cache of it */
if(didload) {
Chunk c = w.getChunkAt(chunk.x, chunk.z);
snaparray[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = c.getChunkSnapshot();
ChunkSnapshot ss = null;
if(!vis) {
if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN)
ss = STONE;
else if(hidestyle == HiddenChunkStyle.FILL_OCEAN)
ss = OCEAN;
else
ss = EMPTY;
}
else {
Chunk c = w.getChunkAt(chunk.x, chunk.z);
ss = c.getChunkSnapshot();
}
snaparray[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = ss;
}
if ((!wasLoaded) && didload) {
/* It looks like bukkit "leaks" entities - they don't get removed from the world-level table
@ -282,4 +343,33 @@ public class NewMapChunkCache implements MapChunkCache {
public MapIterator getIterator(int x, int y, int z) {
return new OurMapIterator(x, y, z);
}
/**
* Set hidden chunk style (default is FILL_AIR)
*/
public void setHiddenFillStyle(HiddenChunkStyle style) {
this.hidestyle = style;
}
/**
* Add visible area limit - can be called more than once
* Needs to be set before chunks are loaded
* Coordinates are block coordinates
*/
public void setVisibleRange(VisibilityLimit lim) {
VisibilityLimit limit = new VisibilityLimit();
if(lim.x0 > lim.x1) {
limit.x0 = (lim.x1 >> 4); limit.x1 = ((lim.x0+15) >> 4);
}
else {
limit.x0 = (lim.x0 >> 4); limit.x1 = ((lim.x1+15) >> 4);
}
if(lim.z0 > lim.z1) {
limit.z0 = (lim.z1 >> 4); limit.z1 = ((lim.z0+15) >> 4);
}
else {
limit.z0 = (lim.z0 >> 4); limit.z1 = ((lim.z1+15) >> 4);
}
if(visible_limits == null)
visible_limits = new ArrayList<VisibilityLimit>();
visible_limits.add(limit);
}
}