use of org.dynmap.DynmapChunk in project dynmap by webbukkit.
the class ForgeMapChunkCache method getLoadedChunks.
/**
* Read NBT data from loaded chunks - needs to be called from server/world thread to be safe
* @returns number loaded
*/
public int getLoadedChunks() {
int cnt = 0;
if (!dw.isLoaded()) {
isempty = true;
unloadChunks();
return 0;
}
ListIterator<DynmapChunk> iter = chunks.listIterator();
while (iter.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iter.next();
int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
// Skip if already processed
if (snaparray[chunkindex] != null)
continue;
boolean vis = isChunkVisible(chunk);
/* Check if cached chunk snapshot found */
if (tryChunkCache(chunk, vis)) {
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
cnt++;
} else // If chunk is loaded and not being unloaded, we're grabbing its NBT data
if (cps.chunkExists(chunk.x, chunk.z)) {
ChunkSnapshot ss;
DynIntHashMap tileData;
if (vis) {
// If visible
CompoundNBT nbt = ChunkSerializer.write((ServerWorld) w, cps.getChunk(chunk.x, chunk.z, false));
if (nbt != null)
nbt = nbt.getCompound("Level");
SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} else {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
tileData = new DynIntHashMap();
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
cnt++;
}
}
return cnt;
}
use of org.dynmap.DynmapChunk in project dynmap by webbukkit.
the class ForgeMapChunkCache method getLoadedChunks.
/**
* Read NBT data from loaded chunks - needs to be called from server/world thread to be safe
* @returns number loaded
*/
public int getLoadedChunks() {
int cnt = 0;
if (!dw.isLoaded()) {
isempty = true;
unloadChunks();
return 0;
}
ListIterator<DynmapChunk> iter = chunks.listIterator();
while (iter.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iter.next();
int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
// Skip if already processed
if (snaparray[chunkindex] != null)
continue;
boolean vis = isChunkVisible(chunk);
/* Check if cached chunk snapshot found */
if (tryChunkCache(chunk, vis)) {
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
cnt++;
} else // If chunk is loaded and not being unloaded, we're grabbing its NBT data
if (cps.chunkExists(chunk.x, chunk.z)) {
ChunkSnapshot ss;
DynIntHashMap tileData;
if (vis) {
// If visible
CompoundNBT nbt = ChunkSerializer.write((ServerWorld) w, cps.getChunk(chunk.x, chunk.z, false));
if (nbt != null)
nbt = nbt.getCompound("Level");
SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} else {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
tileData = new DynIntHashMap();
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
cnt++;
}
}
return cnt;
}
use of org.dynmap.DynmapChunk in project dynmap by webbukkit.
the class ForgeMapChunkCache method getLoadedChunks.
/**
* Read NBT data from loaded chunks - needs to be called from server/world thread to be safe
* @returns number loaded
*/
public int getLoadedChunks() {
int cnt = 0;
if (!dw.isLoaded()) {
isempty = true;
unloadChunks();
return 0;
}
ListIterator<DynmapChunk> iter = chunks.listIterator();
while (iter.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iter.next();
int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
// Skip if already processed
if (snaparray[chunkindex] != null)
continue;
boolean vis = isChunkVisible(chunk);
/* Check if cached chunk snapshot found */
if (tryChunkCache(chunk, vis)) {
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
cnt++;
} else // If chunk is loaded and not being unloaded, we're grabbing its NBT data
if (cps.chunkExists(chunk.x, chunk.z) && (!isChunkUnloadPending(chunk))) {
ChunkSnapshot ss;
DynIntHashMap tileData;
if (vis) {
// If visible
NBTTagCompound nbt = new NBTTagCompound();
try {
writechunktonbt.invoke(cps.chunkLoader, cps.loadChunk(chunk.x, chunk.z), w, nbt);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}
SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} else {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
tileData = new DynIntHashMap();
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
cnt++;
}
}
return cnt;
}
use of org.dynmap.DynmapChunk in project dynmap by webbukkit.
the class ForgeMapChunkCache method readChunks.
public int readChunks(int max_to_load) {
if (!dw.isLoaded()) {
isempty = true;
unloadChunks();
return 0;
}
int cnt = 0;
if (iterator == null) {
iterator = chunks.listIterator();
}
DynmapCore.setIgnoreChunkLoads(true);
// Load the required chunks.
while ((cnt < max_to_load) && iterator.hasNext()) {
long startTime = System.nanoTime();
DynmapChunk chunk = iterator.next();
int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
// Skip if already processed
if (snaparray[chunkindex] != null)
continue;
boolean vis = isChunkVisible(chunk);
/* Check if cached chunk snapshot found */
if (tryChunkCache(chunk, vis)) {
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
} else {
NBTTagCompound nbt = readChunk(chunk.x, chunk.z);
// If read was good
if (nbt != null) {
ChunkSnapshot ss;
DynIntHashMap tileData;
// If hidden
if (!vis) {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
ss = OCEAN;
} else {
ss = EMPTY;
}
tileData = new DynIntHashMap();
} else {
// Prep snapshot
SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
endChunkLoad(startTime, ChunkStats.UNLOADED_CHUNKS);
} else {
endChunkLoad(startTime, ChunkStats.UNGENERATED_CHUNKS);
}
}
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;
}
}
}
return cnt;
}
use of org.dynmap.DynmapChunk in project dynmap by webbukkit.
the class ForgeMapChunkCache method setChunks.
public void setChunks(ForgeWorld dw, List<DynmapChunk> chunks) {
this.dw = dw;
this.w = dw.getWorld();
if (dw.isLoaded()) {
/* Check if world's provider is ServerChunkProvider */
AbstractChunkProvider cp = this.w.getChunkProvider();
if (cp instanceof ServerChunkProvider) {
cps = (ServerChunkProvider) cp;
} else {
Log.severe("Error: world " + dw.getName() + " has unsupported chunk provider");
}
} else {
chunks = new ArrayList<DynmapChunk>();
}
nsect = dw.worldheight >> 4;
this.chunks = chunks;
/* Compute range */
if (chunks.size() == 0) {
this.x_min = 0;
this.x_max = 0;
this.z_min = 0;
this.z_max = 0;
x_dim = 1;
} else {
x_min = x_max = chunks.get(0).x;
z_min = z_max = chunks.get(0).z;
for (DynmapChunk c : chunks) {
if (c.x > x_max) {
x_max = c.x;
}
if (c.x < x_min) {
x_min = c.x;
}
if (c.z > z_max) {
z_max = c.z;
}
if (c.z < z_min) {
z_min = c.z;
}
}
x_dim = x_max - x_min + 1;
}
snapcnt = x_dim * (z_max - z_min + 1);
snaparray = new ChunkSnapshot[snapcnt];
snaptile = new DynIntHashMap[snapcnt];
isSectionNotEmpty = new boolean[snapcnt][];
}
Aggregations