Readd ignore chunk loads
This commit is contained in:
parent
3760549dda
commit
4d046fc4de
3 changed files with 67 additions and 60 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package org.dynmap.common.chunk;
|
package org.dynmap.common.chunk;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
@ -38,6 +39,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
private int snapcnt;
|
private int snapcnt;
|
||||||
private GenericChunk[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
|
private GenericChunk[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */
|
||||||
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */
|
private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */
|
||||||
|
private AtomicInteger loadingChunks = new AtomicInteger(0); //the amount of threads loading threads at this moment, used by async loading
|
||||||
|
|
||||||
private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS,
|
private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS,
|
||||||
BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS };
|
BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS };
|
||||||
|
|
@ -928,64 +930,70 @@ public abstract class GenericMapChunkCache extends MapChunkCache {
|
||||||
chunks = new ArrayList<>();
|
chunks = new ArrayList<>();
|
||||||
iterator.forEachRemaining(chunks::add);
|
iterator.forEachRemaining(chunks::add);
|
||||||
}
|
}
|
||||||
// DynmapCore.setIgnoreChunkLoads(true);
|
//if before increent was 0, means that we are the first, so we need to set this
|
||||||
|
if (loadingChunks.getAndIncrement() == 0) {
|
||||||
List<DynmapChunk> cached = new ArrayList<>();
|
DynmapCore.setIgnoreChunkLoads(true);
|
||||||
List<Map.Entry<Supplier<GenericChunk>,DynmapChunk>> notCached = new ArrayList<>();
|
|
||||||
|
|
||||||
iterator.forEachRemaining(chunks::add);
|
|
||||||
chunks.stream()
|
|
||||||
.filter(chunk -> snaparray[(chunk.x - x_min) + (chunk.z - z_min) * x_dim] == null)
|
|
||||||
.forEach(chunk -> {
|
|
||||||
if (cache.getSnapshot(dw.getName(),chunk.x, chunk.z) == null) {
|
|
||||||
notCached.add(new AbstractMap.SimpleEntry<>(loadChunkAsync(chunk),chunk));
|
|
||||||
} else {
|
|
||||||
cached.add(chunk);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cached.forEach(chunk -> {
|
|
||||||
long startTime = System.nanoTime();
|
|
||||||
tryChunkCache(chunk, isChunkVisible(chunk));
|
|
||||||
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
|
|
||||||
});
|
|
||||||
notCached.forEach(chunkSupplier -> {
|
|
||||||
long startTime = System.nanoTime();
|
|
||||||
GenericChunk chunk = chunkSupplier.getKey().get();
|
|
||||||
DynmapChunk dynmapChunk = chunkSupplier.getValue();
|
|
||||||
if (chunk != null) {
|
|
||||||
// If hidden
|
|
||||||
if (isChunkVisible(dynmapChunk)) {
|
|
||||||
// Prep snapshot
|
|
||||||
prepChunkSnapshot(dynmapChunk, chunk);
|
|
||||||
} else {
|
|
||||||
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
|
|
||||||
chunk = getStone();
|
|
||||||
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
|
|
||||||
chunk = getOcean();
|
|
||||||
} else {
|
|
||||||
chunk = getEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
snaparray[(dynmapChunk.x - x_min) + (dynmapChunk.z - z_min) * x_dim] = chunk;
|
|
||||||
endChunkLoad(startTime, ChunkStats.UNLOADED_CHUNKS);
|
|
||||||
} else {
|
|
||||||
endChunkLoad(startTime, ChunkStats.UNGENERATED_CHUNKS);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// DynmapCore.setIgnoreChunkLoads(false);
|
|
||||||
|
|
||||||
isempty = true;
|
|
||||||
/* Fill missing chunks with empty dummy chunk */
|
|
||||||
for (int i = 0; i < snaparray.length; i++) {
|
|
||||||
if (snaparray[i] == null) {
|
|
||||||
snaparray[i] = getEmpty();
|
|
||||||
} else if (!snaparray[i].isEmpty) {
|
|
||||||
isempty = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<DynmapChunk> cached = new ArrayList<>();
|
||||||
|
List<Map.Entry<Supplier<GenericChunk>, DynmapChunk>> notCached = new ArrayList<>();
|
||||||
|
|
||||||
|
iterator.forEachRemaining(chunks::add);
|
||||||
|
chunks.stream()
|
||||||
|
.filter(chunk -> snaparray[(chunk.x - x_min) + (chunk.z - z_min) * x_dim] == null)
|
||||||
|
.forEach(chunk -> {
|
||||||
|
if (cache.getSnapshot(dw.getName(), chunk.x, chunk.z) == null) {
|
||||||
|
notCached.add(new AbstractMap.SimpleEntry<>(loadChunkAsync(chunk), chunk));
|
||||||
|
} else {
|
||||||
|
cached.add(chunk);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cached.forEach(chunk -> {
|
||||||
|
long startTime = System.nanoTime();
|
||||||
|
tryChunkCache(chunk, isChunkVisible(chunk));
|
||||||
|
endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
|
||||||
|
});
|
||||||
|
notCached.forEach(chunkSupplier -> {
|
||||||
|
long startTime = System.nanoTime();
|
||||||
|
GenericChunk chunk = chunkSupplier.getKey().get();
|
||||||
|
DynmapChunk dynmapChunk = chunkSupplier.getValue();
|
||||||
|
if (chunk != null) {
|
||||||
|
// If hidden
|
||||||
|
if (isChunkVisible(dynmapChunk)) {
|
||||||
|
// Prep snapshot
|
||||||
|
prepChunkSnapshot(dynmapChunk, chunk);
|
||||||
|
} else {
|
||||||
|
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
|
||||||
|
chunk = getStone();
|
||||||
|
} else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
|
||||||
|
chunk = getOcean();
|
||||||
|
} else {
|
||||||
|
chunk = getEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snaparray[(dynmapChunk.x - x_min) + (dynmapChunk.z - z_min) * x_dim] = chunk;
|
||||||
|
endChunkLoad(startTime, ChunkStats.UNLOADED_CHUNKS);
|
||||||
|
} else {
|
||||||
|
endChunkLoad(startTime, ChunkStats.UNGENERATED_CHUNKS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
isempty = true;
|
||||||
|
/* Fill missing chunks with empty dummy chunk */
|
||||||
|
for (int i = 0; i < snaparray.length; i++) {
|
||||||
|
if (snaparray[i] == null) {
|
||||||
|
snaparray[i] = getEmpty();
|
||||||
|
} else if (!snaparray[i].isEmpty) {
|
||||||
|
isempty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (loadingChunks.decrementAndGet() == 0) {
|
||||||
|
DynmapCore.setIgnoreChunkLoads(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ package org.dynmap.bukkit.helper.v118_2;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.server.level.WorldServer;
|
import net.minecraft.server.level.WorldServer;
|
||||||
import net.minecraft.world.level.World;
|
|
||||||
import net.minecraft.world.level.chunk.Chunk;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
@ -51,7 +49,8 @@ public class AsyncChunkProvider118_2 {
|
||||||
return future.thenApply((resultFuture) -> {
|
return future.thenApply((resultFuture) -> {
|
||||||
if (resultFuture == null) return null;
|
if (resultFuture == null) return null;
|
||||||
try {
|
try {
|
||||||
return (NBTTagCompound) resultFuture.getClass().getField("chunkData").get(resultFuture);
|
NBTTagCompound compound = (NBTTagCompound) resultFuture.getClass().getField("chunkData").get(resultFuture);
|
||||||
|
return ifFailed.test(compound) ? null : compound;
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ public class MapChunkCache118_2 extends GenericMapChunkCache {
|
||||||
};
|
};
|
||||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return () -> loadChunk(chunk);
|
||||||
}
|
}
|
||||||
return () -> null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Supplier<GenericChunk> getLoadedChunk(DynmapChunk chunk, boolean async) {
|
private Supplier<GenericChunk> getLoadedChunk(DynmapChunk chunk, boolean async) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue