diff --git a/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java b/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java index 9f0e0786..2eb22b93 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java @@ -24,8 +24,9 @@ public class VoxyConfig { public boolean ingestEnabled = true; //public int renderDistance = 128; public int serviceThreads = Math.max(Runtime.getRuntime().availableProcessors()/2, 1); + public float subDivisionSize = 128; + public int secondaryLruCacheSize = 4096; public String defaultSaveConfig; - public int subDivisionSize = 128; //public int renderQuality = 256;//Smaller is higher quality diff --git a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java index 72ecd02a..7181e0cf 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java @@ -66,12 +66,17 @@ public class VoxyConfigScreenFactory implements ModMenuApi { .setDefaultValue(DEFAULT.ingestEnabled) .build()); - category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.subDivisionSize"), config.subDivisionSize, 25, 256) + category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.subDivisionSize"), (int) config.subDivisionSize, 25, 256) .setTooltip(Text.translatable("voxy.config.general.subDivisionSize.tooltip")) .setSaveConsumer(val -> config.subDivisionSize = val) - .setDefaultValue(DEFAULT.subDivisionSize) + .setDefaultValue((int) DEFAULT.subDivisionSize) .build()); + category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.lruCacheSize"), config.secondaryLruCacheSize, 16, 1<<13) + .setTooltip(Text.translatable("voxy.config.general.lruCacheSize.tooltip")) + .setSaveConsumer(val ->{if (config.secondaryLruCacheSize != val) reload(); config.secondaryLruCacheSize = val;}) + .setDefaultValue(DEFAULT.secondaryLruCacheSize) + .build()); category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.serviceThreads"), config.serviceThreads, 1, Runtime.getRuntime().availableProcessors()) .setTooltip(Text.translatable("voxy.config.general.serviceThreads.tooltip")) diff --git a/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java b/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java index bb20fbfa..98d158f5 100644 --- a/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java +++ b/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java @@ -98,7 +98,7 @@ public class ContextSelectionSystem { } public WorldEngine createEngine(ServiceThreadPool serviceThreadPool) { - return new WorldEngine(this.createStorageBackend(), serviceThreadPool); + return new WorldEngine(this.createStorageBackend(), serviceThreadPool, VoxyConfig.CONFIG.secondaryLruCacheSize); } //Saves the config for the world selection or something, need to figure out how to make it work with dimensional configs maybe? diff --git a/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java b/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java index 237faff8..9212b76c 100644 --- a/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java +++ b/src/main/java/me/cortex/voxy/common/world/ActiveSectionTracker.java @@ -112,8 +112,9 @@ public class ActiveSectionTracker { var cache = this.loadedSectionCache[index]; synchronized (cache) { if (section.trySetFreed()) { - if (cache.remove(section.key).obj != section) { - throw new IllegalStateException("Removed section not the same as the referenced section in the cache"); + var cached = cache.remove(section.key); + if (cached.obj != section) { + throw new IllegalStateException("Removed section not the same as the referenced section in the cache: cached: " + cached.obj.key + "got: " + section.key); } //Add section to secondary cache while primary is locked diff --git a/src/main/java/me/cortex/voxy/common/world/WorldEngine.java b/src/main/java/me/cortex/voxy/common/world/WorldEngine.java index 87777aba..d6173eb1 100644 --- a/src/main/java/me/cortex/voxy/common/world/WorldEngine.java +++ b/src/main/java/me/cortex/voxy/common/world/WorldEngine.java @@ -39,16 +39,16 @@ public class WorldEngine { public Mapper getMapper() {return this.mapper;} - public WorldEngine(StorageBackend storageBackend, ServiceThreadPool serviceThreadPool) { - this(storageBackend, serviceThreadPool, MAX_LOD_LAYERS); + public WorldEngine(StorageBackend storageBackend, ServiceThreadPool serviceThreadPool, int cacheCount) { + this(storageBackend, serviceThreadPool, MAX_LOD_LAYERS, cacheCount); } - private WorldEngine(StorageBackend storageBackend, ServiceThreadPool serviceThreadPool, int maxMipLayers) { + private WorldEngine(StorageBackend storageBackend, ServiceThreadPool serviceThreadPool, int maxMipLayers, int cacheCount) { this.maxMipLevels = maxMipLayers; this.storage = storageBackend; this.mapper = new Mapper(this.storage); //4 cache size bits means that the section tracker has 16 separate maps that it uses - this.sectionTracker = new ActiveSectionTracker(4, this::unsafeLoadSection, 1<<12);//1 gb of cpu section cache + this.sectionTracker = new ActiveSectionTracker(4, this::unsafeLoadSection, cacheCount); this.savingService = new SectionSavingService(this, serviceThreadPool); this.ingestService = new VoxelIngestService(this, serviceThreadPool);