Merge pull request #219 from mikeprimm/master

Support defining visibility limits on each world, and selectiong methods for how to present hidden areas
This commit is contained in:
mikeprimm 2011-06-16 21:45:22 -07:00
commit fa34aafabe
6 changed files with 336 additions and 100 deletions

View File

@ -73,9 +73,9 @@ renderinterval: 1
enabletilehash: true enabletilehash: true
render-triggers: render-triggers:
# - chunkloaded #- chunkloaded
# - playermove #- playermove
# - playerjoin #- playerjoin
- blockplaced - blockplaced
- blockbreak - blockbreak
- snowform - snowform
@ -124,8 +124,8 @@ templates:
# Template for normal world # Template for normal world
normal: normal:
enabled: true enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds # # If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true # bigworld: true
center: center:
x: 0 x: 0
y: 64 y: 64
@ -136,19 +136,19 @@ templates:
title: "Flat" title: "Flat"
prefix: flat prefix: flat
colorscheme: default colorscheme: default
# To render a world as a "night view", set shadowstrength and ambientlight # # To render a world as a "night view", set shadowstrength and ambientlight
# shadowstrength: 1.0 # shadowstrength: 1.0
# ambientlight: 4 # ambientlight: 4
# To render both night and day versions of tiles (when ambientlight is set), set true # # 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 # # Option to turn on transparency support (off by default) - slows render
# transparency: true # transparency: true
# Background color for map during the day # # Background color for map during the day
# backgroundday: "#153E7E" # backgroundday: "#153E7E"
# Background color for map during the night # # Background color for map during the night
# backgroundnight: "#000000" # backgroundnight: "#000000"
# Backgrounc color for map (independent of night/day) # # Background color for map (independent of night/day)
# background: "#000000" # background: "#000000"
- class: org.dynmap.kzedmap.KzedMap - class: org.dynmap.kzedmap.KzedMap
renderers: renderers:
- class: org.dynmap.kzedmap.DefaultTileRenderer - class: org.dynmap.kzedmap.DefaultTileRenderer
@ -157,30 +157,31 @@ templates:
prefix: t prefix: t
maximumheight: 127 maximumheight: 127
colorscheme: default colorscheme: default
# Add shadows to world (based on top-down shadows from chunk data) # # 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 # # 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 # # 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 # # Option to turn off transparency support (on by default) - speeds render
# transparency: false # transparency: false
# Background color for map during the day # # Background color for map during the day
# backgroundday: "#153E7E" # backgroundday: "#153E7E"
# Background color for map during the night # # Background color for map during the night
# backgroundnight: "#000000" # backgroundnight: "#000000"
# Backgrounc color for map (independent of night/day) # # Background color for map (independent of night/day)
# background: "#000000" # background: "#000000"
# Sets the icon to 'images/block_custom.png' # # Sets the icon to 'images/block_custom.png'
# icon: custom # icon: custom
#- class: org.dynmap.kzedmap.HighlightTileRenderer
# prefix: ht # - class: org.dynmap.kzedmap.HighlightTileRenderer
# maximumheight: 127 # prefix: ht
# colorscheme: default # maximumheight: 127
# highlight: # For highlighting multiple block-types. # colorscheme: default
# - 56 # Highlight diamond-ore # highlight: # For highlighting multiple block-types.
# - 66 # Highlight minecart track # - 56 # Highlight diamond-ore
# highlight: 56 # For highlighting a single block-type. # - 66 # Highlight minecart track
# highlight: 56 # For highlighting a single block-type.
- class: org.dynmap.kzedmap.CaveTileRenderer - class: org.dynmap.kzedmap.CaveTileRenderer
name: cave name: cave
title: "Cave" title: "Cave"
@ -189,8 +190,8 @@ templates:
# Nether world template # Nether world template
nether: nether:
enabled: true enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds # # If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true # bigworld: true
center: center:
x: 0 x: 0
y: 64 y: 64
@ -216,8 +217,8 @@ templates:
# Skylands world template # Skylands world template
skylands: skylands:
enabled: true enabled: true
# If bigworld set to true, use alternate directory layout better suited to large worlds # # If bigworld set to true, use alternate directory layout better suited to large worlds
# bigworld: true # bigworld: true
center: center:
x: 0 x: 0
y: 64 y: 64
@ -269,6 +270,18 @@ worlds:
# - x: -15000 # - x: -15000
# y: 64 # y: 64
# z: -5000 # 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). # 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 # template: mycustomtemplate
# Rest of comes from template - uncomment to tailor for world specifically # Rest of comes from template - uncomment to tailor for world specifically
@ -277,7 +290,7 @@ worlds:
# y: 64 # y: 64
# z: 0 # z: 0
# # If bigworld set to true, use alternate directory layout better suited to large worlds # # If bigworld set to true, use alternate directory layout better suited to large worlds
# # bigworld: true # bigworld: true
# maps: # maps:
# - class: org.dynmap.flat.FlatMap # - class: org.dynmap.flat.FlatMap
# name: flat # name: flat
@ -285,18 +298,18 @@ worlds:
# prefix: flat # prefix: flat
# colorscheme: default # colorscheme: default
# # To render a world as a "night view", set shadowstrength and ambientlight # # To render a world as a "night view", set shadowstrength and ambientlight
# # shadowstrength: 1.0 # shadowstrength: 1.0
# # ambientlight: 4 # ambientlight: 4
# # To render both night and day versions of tiles (when ambientlight is set), set true # # 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 # # Option to turn on transparency support (off by default) - slows render
# # transparency: true # transparency: true
# # Background color for map during the day # # Background color for map during the day
# # backgroundday: "#153E7E" # backgroundday: "#153E7E"
# # Background color for map during the night # # Background color for map during the night
# # backgroundnight: "#000000" # backgroundnight: "#000000"
# # Backgrounc color for map (independent of night/day) # # Backgrounc color for map (independent of night/day)
# # background: "#000000" # background: "#000000"
# - class: org.dynmap.kzedmap.KzedMap # - class: org.dynmap.kzedmap.KzedMap
# renderers: # renderers:
# - class: org.dynmap.kzedmap.DefaultTileRenderer # - class: org.dynmap.kzedmap.DefaultTileRenderer
@ -306,29 +319,29 @@ worlds:
# maximumheight: 127 # maximumheight: 127
# colorscheme: default # colorscheme: default
# # Add shadows to world (based on top-down shadows from chunk data) # # 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 # # 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 # # 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 # # Option to turn off transparency support (on by default) - speeds render
# # transparency: false # transparency: false
# # Background color for map during the day # # Background color for map during the day
# # backgroundday: "#153E7E" # backgroundday: "#153E7E"
# # Background color for map during the night # # Background color for map during the night
# # backgroundnight: "#000000" # backgroundnight: "#000000"
# # Backgrounc color for map (independent of night/day) # # Backgrounc color for map (independent of night/day)
# # background: "#000000" # background: "#000000"
# # Sets the icon to 'images/block_custom.png' # # Sets the icon to 'images/block_custom.png'
# # icon: custom # icon: custom
# #- class: org.dynmap.kzedmap.HighlightTileRenderer # - class: org.dynmap.kzedmap.HighlightTileRenderer
# # prefix: ht # prefix: ht
# # maximumheight: 127 # maximumheight: 127
# # colorscheme: default # colorscheme: default
# # highlight: # For highlighting multiple block-types. # highlight: # For highlighting multiple block-types.
# # - 56 # Highlight diamond-ore # - 56 # Highlight diamond-ore
# # - 66 # Highlight minecart track # - 66 # Highlight minecart track
# # highlight: 56 # For highlighting a single block-type. # highlight: 56 # For highlighting a single block-type.
# - class: org.dynmap.kzedmap.CaveTileRenderer # - class: org.dynmap.kzedmap.CaveTileRenderer
# name: cave # name: cave
# title: "Cave" # title: "Cave"

View File

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

View File

@ -164,7 +164,7 @@ public class MapManager {
World w = world.world; World w = world.world;
/* Fetch chunk cache from server thread */ /* Fetch chunk cache from server thread */
DynmapChunk[] requiredChunks = tile.getMap().getRequiredChunks(tile); DynmapChunk[] requiredChunks = tile.getMap().getRequiredChunks(tile);
MapChunkCache cache = createMapChunkCache(w, requiredChunks); MapChunkCache cache = createMapChunkCache(world, requiredChunks);
if(cache == null) { if(cache == null) {
cleanup(); cleanup();
return; /* Cancelled/aborted */ return; /* Cancelled/aborted */
@ -309,6 +309,29 @@ public class MapManager {
dynmapWorld.seedloc.add(lx); 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... // TODO: Make this less... weird...
// Insert the world on the same spot as in the configuration. // 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 * 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>() { Callable<MapChunkCache> job = new Callable<MapChunkCache>() {
public MapChunkCache call() { public MapChunkCache call() {
MapChunkCache c = null; MapChunkCache c = null;
@ -428,7 +451,13 @@ public class MapManager {
} }
if(c == null) if(c == null)
c = new LegacyMapChunkCache(); 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; return c;
} }
}; };

View File

@ -1,19 +1,20 @@
package org.dynmap.utils; package org.dynmap.utils;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.LinkedList;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.Log; import org.dynmap.Log;
import java.util.List;
/** /**
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread * Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/ */
public class LegacyMapChunkCache implements MapChunkCache { public class LegacyMapChunkCache implements MapChunkCache {
private World w;
private static Method getchunkdata = null; private static Method getchunkdata = null;
private static Method gethandle = null; private static Method gethandle = null;
private static Method poppreservedchunk = 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_min, x_max, z_min, z_max;
private int x_dim; 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) */ 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 { private static class EmptyChunk implements LegacyChunkSnapshot {
public final int getBlockTypeId(int x, int y, int z) { public final int getBlockTypeId(int x, int y, int z) {
@ -131,11 +134,42 @@ public class LegacyMapChunkCache implements MapChunkCache {
return 0; return 0;
} }
public final int getHighestBlockYAt(int x, int z) { 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 EmptyChunk EMPTY = new EmptyChunk();
private static final PlainChunk STONE = new PlainChunk(1);
private static final PlainChunk OCEAN = new PlainChunk(9);
/** /**
* Construct empty cache * Construct empty cache
@ -175,7 +209,6 @@ public class LegacyMapChunkCache implements MapChunkCache {
} }
x_dim = x_max - x_min + 1; x_dim = x_max - x_min + 1;
} }
this.w = w;
if(!initialized) { if(!initialized) {
try { try {
@ -208,22 +241,43 @@ public class LegacyMapChunkCache implements MapChunkCache {
if(gethandle != null) { if(gethandle != null) {
// Load the required chunks. // Load the required chunks.
for (DynmapChunk chunk : 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 wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
boolean didload = w.loadChunk(chunk.x, chunk.z, false); boolean didload = w.loadChunk(chunk.x, chunk.z, false);
/* If it did load, make cache of it */ /* If it did load, make cache of it */
if(didload) { if(didload) {
Chunk c = w.getChunkAt(chunk.x, chunk.z); LegacyChunkSnapshot ss = null;
try { if(!vis) {
Object cc = gethandle.invoke(c); if(hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN)
byte[] buf = new byte[32768 + 16384 + 16384 + 16384]; /* Get big enough buffer for whole chunk */ ss = STONE;
getchunkdata.invoke(cc, buf, 0, 0, 0, 16, 128, 16, 0); else if(hidestyle == HiddenChunkStyle.FILL_OCEAN)
byte[] h = (byte[])heightmap.get(cc); ss = OCEAN;
byte[] hmap = new byte[256]; else
System.arraycopy(h, 0, hmap, 0, 256); ss = EMPTY;
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) {
} }
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) { if ((!wasLoaded) && didload) {
/* It looks like bukkit "leaks" entities - they don't get removed from the world-level table /* 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) { public MapIterator getIterator(int x, int y, int z) {
return new OurMapIterator(x, y, 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; import org.dynmap.DynmapChunk;
public interface MapChunkCache { 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 * Load chunks into cache
* @param w - world * @param w - world
@ -37,4 +45,14 @@ public interface MapChunkCache {
* Get cache iterator * Get cache iterator
*/ */
public MapIterator getIterator(int x, int y, int z); 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; package org.dynmap.utils;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.LinkedList; import java.util.ArrayList;
import java.util.List;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.block.Biome; 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 * Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/ */
public class NewMapChunkCache implements MapChunkCache { public class NewMapChunkCache implements MapChunkCache {
private World w;
private static Method poppreservedchunk = null; private static Method poppreservedchunk = null;
private int x_min, x_max, z_min, z_max; private int x_min, x_max, z_min, z_max;
private int x_dim; 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) */ 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 { private static class EmptyChunk implements ChunkSnapshot {
/* Need these for interface, but not used */ /* Need these for interface, but not used */
@ -138,11 +140,49 @@ public class NewMapChunkCache implements MapChunkCache {
return 0; return 0;
} }
public final int getHighestBlockYAt(int x, int z) { 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 EmptyChunk EMPTY = new EmptyChunk();
private static final PlainChunk STONE = new PlainChunk(1);
private static final PlainChunk OCEAN = new PlainChunk(9);
/** /**
* Construct empty cache * Construct empty cache
@ -191,17 +231,38 @@ public class NewMapChunkCache implements MapChunkCache {
} }
x_dim = x_max - x_min + 1; x_dim = x_max - x_min + 1;
} }
this.w = w;
snaparray = new ChunkSnapshot[x_dim * (z_max-z_min+1)]; snaparray = new ChunkSnapshot[x_dim * (z_max-z_min+1)];
// Load the required chunks. // Load the required chunks.
for (DynmapChunk chunk : 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 wasLoaded = w.isChunkLoaded(chunk.x, chunk.z);
boolean didload = w.loadChunk(chunk.x, chunk.z, false); boolean didload = w.loadChunk(chunk.x, chunk.z, false);
/* If it did load, make cache of it */ /* If it did load, make cache of it */
if(didload) { if(didload) {
Chunk c = w.getChunkAt(chunk.x, chunk.z); ChunkSnapshot ss = null;
snaparray[(chunk.x-x_min) + (chunk.z - z_min)*x_dim] = c.getChunkSnapshot(); 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) { if ((!wasLoaded) && didload) {
/* It looks like bukkit "leaks" entities - they don't get removed from the world-level table /* 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) { public MapIterator getIterator(int x, int y, int z) {
return new OurMapIterator(x, y, 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);
}
} }