Close #447 Add the ability to limit LOD chunk update rate
This commit is contained in:
@@ -43,6 +43,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@@ -62,6 +64,8 @@ public class SharedApi
|
||||
private static ThreadPoolExecutor lightPopulatorThreadPool;
|
||||
private static ConfigChangeListener<Integer> threadConfigListener;
|
||||
|
||||
private static final Timer CHUNK_UPDATE_TIMER = new Timer();
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
@@ -236,13 +240,6 @@ public class SharedApi
|
||||
}
|
||||
private static void bakeChunkLightingAndSendToLevelAsync(IChunkWrapper chunkWrapper, @Nullable ArrayList<IChunkWrapper> neighbourChunkList, IDhLevel dhLevel)
|
||||
{
|
||||
if (UPDATING_CHUNK_SET.size() > lightPopulatorThreadPool.getPoolSize() * 100)
|
||||
{
|
||||
// limit how many tasks can be queued at a time
|
||||
// attempt to limit memory leaking
|
||||
return;
|
||||
}
|
||||
|
||||
// prevent duplicate update requests
|
||||
if (UPDATING_CHUNK_SET.contains(chunkWrapper.getChunkPos()))
|
||||
{
|
||||
@@ -299,7 +296,22 @@ public class SharedApi
|
||||
}
|
||||
finally
|
||||
{
|
||||
UPDATING_CHUNK_SET.remove(chunkWrapper.getChunkPos());
|
||||
// the LOD chunk has finished being updated
|
||||
int updateTimeoutInSec = Config.Client.Advanced.LodBuilding.minTimeBetweenChunkUpdatesInSeconds.get();
|
||||
if (updateTimeoutInSec != 0)
|
||||
{
|
||||
// prevent updating this chunk again until the timeout finishes
|
||||
CHUNK_UPDATE_TIMER.schedule(new TimerTask()
|
||||
{
|
||||
@Override
|
||||
public void run() { UPDATING_CHUNK_SET.remove(chunkWrapper.getChunkPos()); }
|
||||
}, updateTimeoutInSec * 1000L);
|
||||
}
|
||||
else
|
||||
{
|
||||
// instantly allow this chunk to be updated again
|
||||
UPDATING_CHUNK_SET.remove(chunkWrapper.getChunkPos());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ public class Config
|
||||
public static ConfigCategory graphics = new ConfigCategory.Builder().set(Graphics.class).build();
|
||||
public static ConfigCategory worldGenerator = new ConfigCategory.Builder().set(WorldGenerator.class).build();
|
||||
public static ConfigCategory multiplayer = new ConfigCategory.Builder().set(Multiplayer.class).build();
|
||||
public static ConfigCategory lodBuilding = new ConfigCategory.Builder().set(LodBuilding.class).build();
|
||||
public static ConfigCategory multiThreading = new ConfigCategory.Builder().set(MultiThreading.class).build();
|
||||
public static ConfigCategory buffers = new ConfigCategory.Builder().set(GpuBuffers.class).build();
|
||||
public static ConfigCategory autoUpdater = new ConfigCategory.Builder().set(AutoUpdater.class).build();
|
||||
@@ -750,6 +751,21 @@ public class Config
|
||||
|
||||
}
|
||||
|
||||
public static class LodBuilding
|
||||
{
|
||||
public static ConfigEntry<Integer> minTimeBetweenChunkUpdatesInSeconds = new ConfigEntry.Builder<Integer>()
|
||||
.setMinDefaultMax(0, 1, 60)
|
||||
.comment(""
|
||||
+ "Determines how long must pass between LOD chunk updates before another. \n"
|
||||
+ "update can occur\n"
|
||||
+ "\n"
|
||||
+ "Increasing this value will reduce CPU load but may may cause \n"
|
||||
+ "LODs to become outdated more frequently or for longer. \n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static class Multiplayer
|
||||
{
|
||||
public static ConfigEntry<EServerFolderNameMode> serverFolderNameMode = new ConfigEntry.Builder<EServerFolderNameMode>()
|
||||
|
||||
@@ -326,8 +326,17 @@
|
||||
"Generation Priority",
|
||||
"distanthorizons.config.client.advanced.worldGenerator.generationPriority.@tooltip":
|
||||
"The priority for chunks being generated around the player.",
|
||||
|
||||
|
||||
"distanthorizons.config.client.advanced.lodBuilding":
|
||||
"Lod Building",
|
||||
|
||||
"distanthorizons.config.client.advanced.lodBuilding.minTimeBetweenChunkUpdatesInSeconds":
|
||||
"Minimum Time Between Chunk Updates In Seconds",
|
||||
"distanthorizons.config.client.advanced.lodBuilding.minTimeBetweenChunkUpdatesInSeconds.@tooltip":
|
||||
"Determines how long must pass between LOD chunk updates before another. \nupdate can occur\n\nIncreasing this value will reduce CPU load but may may cause \nLODs to become outdated more frequently or for longer.",
|
||||
|
||||
|
||||
|
||||
"distanthorizons.config.client.advanced.multiplayer":
|
||||
"Multiplayer",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user