Optimize some performance. Now less lag spikes and stuff
Also fixed the WorldGen Disable not working issue
This commit is contained in:
@@ -81,17 +81,24 @@ public class EventApi {
|
||||
if (ApiShared.isShuttingDown)
|
||||
return;
|
||||
|
||||
try {
|
||||
if (VERSION_CONSTANTS.hasBatchGenerationImplementation()) {
|
||||
if (batchGenerator == null)
|
||||
batchGenerator = new BatchGenerator(ApiShared.lodBuilder, lodDim);
|
||||
batchGenerator.queueGenerationRequests(lodDim, ApiShared.lodBuilder);
|
||||
} else {
|
||||
LodWorldGenerator.INSTANCE.queueGenerationRequests(lodDim, ApiShared.lodBuilder);
|
||||
if (CONFIG.client().worldGenerator().getEnableDistantGeneration()) {
|
||||
try {
|
||||
if (VERSION_CONSTANTS.hasBatchGenerationImplementation()) {
|
||||
if (batchGenerator == null)
|
||||
batchGenerator = new BatchGenerator(ApiShared.lodBuilder, lodDim);
|
||||
batchGenerator.queueGenerationRequests(lodDim, ApiShared.lodBuilder);
|
||||
} else {
|
||||
LodWorldGenerator.INSTANCE.queueGenerationRequests(lodDim, ApiShared.lodBuilder);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Exception may happen if world got unloaded unorderly
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (batchGenerator != null) {
|
||||
batchGenerator.stop(false);
|
||||
batchGenerator = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Exception may happen if world got unloaded unorderly
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +160,7 @@ public class EventApi {
|
||||
// TODO Better report on when world gen is stuck and timeout
|
||||
if (VERSION_CONSTANTS.hasBatchGenerationImplementation()) {
|
||||
if (batchGenerator != null)
|
||||
batchGenerator.stop();
|
||||
batchGenerator.stop(true);
|
||||
batchGenerator = null;
|
||||
} else {
|
||||
LodWorldGenerator.INSTANCE.restartExecutorService();
|
||||
|
||||
+2
-2
@@ -114,8 +114,8 @@ public class LodBufferBuilderFactory
|
||||
* This size will be too small, more than likely. The buffers will be expanded
|
||||
* when need be to fit the larger sizes.
|
||||
*/
|
||||
public static final int DEFAULT_MEMORY_ALLOCATION = 1024;
|
||||
public static final int MAX_TRIANGLES_PER_BUFFER = (1024*1024*2) / (LodUtil.LOD_VERTEX_FORMAT.getByteSize()*3);
|
||||
public static final int DEFAULT_MEMORY_ALLOCATION = 128;
|
||||
public static final int MAX_TRIANGLES_PER_BUFFER = (1024*1024*1) / (LodUtil.LOD_VERTEX_FORMAT.getByteSize()*3);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -52,15 +52,16 @@ public class BatchGenerator {
|
||||
|
||||
public BatchGenerator(LodBuilder newLodBuilder, LodDimension newLodDimension) {
|
||||
IWorldWrapper world = LodUtil.getServerWorldFromDimension(newLodDimension.dimension);
|
||||
targetLodDim = newLodDimension;
|
||||
generationGroup = FACTORY.createBatchGenerator(newLodBuilder, newLodDimension, world);
|
||||
MC.sendChatMessage("NOTE: You are currently using Distant Horizon's Batch Chunk Pre-Generator.");
|
||||
ClientApi.LOGGER.info("1.18 Experimental Chunk Generator initialized");
|
||||
ClientApi.LOGGER.info("Batch Chunk Generator initialized");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void queueGenerationRequests(LodDimension lodDim, LodBuilder lodBuilder) {
|
||||
if (lodDim != targetLodDim) {
|
||||
stop();
|
||||
stop(false);
|
||||
IWorldWrapper dim = LodUtil.getServerWorldFromDimension(lodDim.dimension);
|
||||
generationGroup = FACTORY.createBatchGenerator(lodBuilder, lodDim, dim);
|
||||
targetLodDim = lodDim;
|
||||
@@ -256,9 +257,9 @@ public class BatchGenerator {
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
public void stop(boolean blocking) {
|
||||
ClientApi.LOGGER.info("1.18 Experimental Chunk Generator shutting down...");
|
||||
generationGroup.stop();
|
||||
generationGroup.stop(blocking);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -345,14 +345,11 @@ public class LodDimension
|
||||
//ClientApi.LOGGER.info("LodDim expend Region: " + playerPosX + "," + playerPosZ);
|
||||
Pos minPos = regions.getMinInRange();
|
||||
iterateWithSpiral((int x, int z) -> {
|
||||
if (!expandOrLoadPaused && !LodUtil.checkRamUsage(0.1, 32)) {
|
||||
Runtime.getRuntime().gc();
|
||||
if (!LodUtil.checkRamUsage(0.2, 64)) {
|
||||
ClientApi.LOGGER.warn("Not enough ram for expandOrLoadThread. Pausing until Ram is freed...");
|
||||
// We have less than 10% or 1MB ram left. Don't expend.
|
||||
expandOrLoadPaused = true;
|
||||
saveDirtyRegionsToFile(false);
|
||||
}
|
||||
if (!expandOrLoadPaused && !LodUtil.checkRamUsage(0.2, 64)) {
|
||||
ClientApi.LOGGER.warn("Not enough ram for expandOrLoadThread. Pausing until Ram is freed...");
|
||||
// We have less than 10% or 1MB ram left. Don't expend.
|
||||
expandOrLoadPaused = true;
|
||||
saveDirtyRegionsToFile(false);
|
||||
}
|
||||
|
||||
int regionX;
|
||||
|
||||
+1
-1
@@ -21,5 +21,5 @@ public abstract class AbstractBatchGenerationEnvionmentWrapper {
|
||||
|
||||
public abstract boolean tryAddPoint(int chunkX, int chunkZ, int genSize, Steps targetStep);
|
||||
|
||||
public abstract void stop();
|
||||
public abstract void stop(boolean blocking);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user