From 377c51f3652ada9f628a70968d36c538164e537d Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 6 Aug 2024 22:57:15 +1000 Subject: [PATCH] Tweeks --- .../cortex/voxy/client/config/VoxyConfig.java | 2 +- .../hierachical2/HierarchicalNodeManager.java | 17 ++++++++--- .../voxy/client/importers/WorldImporter.java | 2 +- .../common/world/thread/ServiceSlice.java | 4 +++ .../world/thread/ServiceThreadPool.java | 28 +++++++++++++++---- 5 files changed, 42 insertions(+), 11 deletions(-) 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 3523f5ad..1aabf368 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java @@ -24,7 +24,7 @@ public class VoxyConfig { public boolean enabled = true; public boolean ingestEnabled = true; - public int renderDistance = 128;//Unused at the present + public int renderDistance = 128; public int serviceThreads = Math.max(Runtime.getRuntime().availableProcessors()/2, 1); public String defaultSaveConfig; public int renderQuality = 256;//Smaller is higher quality diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalNodeManager.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalNodeManager.java index c53f63d8..37d62c0c 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalNodeManager.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical2/HierarchicalNodeManager.java @@ -40,11 +40,11 @@ public class HierarchicalNodeManager { } catch (InterruptedException e) { throw new RuntimeException(e); } - for(int x = -1; x<=1;x++) { - for (int z = -1; z <= 1; z++) { + for(int x = -100; x<=100;x++) { + for (int z = -100; z <= 100; z++) { for (int y = -3; y <= 3; y++) { - updateFilterer.watch(4,x,y,z); - updateFilterer.unwatch(4,x,y,z); + updateFilterer.watch(0,x,y,z); + updateFilterer.unwatch(0,x,y,z); } } } @@ -102,6 +102,15 @@ public class HierarchicalNodeManager { } public void processBuildResult(BuiltSection section) { + section.free(); + /* + if (!section.isEmpty()) { + this.geometryManager.uploadSection(section); + } else { + section.free(); + } + */ + int nodeId = this.activeSectionMap.get(section.position); if (nodeId == -1) { //Not tracked or mapped to a node!!! diff --git a/src/main/java/me/cortex/voxy/client/importers/WorldImporter.java b/src/main/java/me/cortex/voxy/client/importers/WorldImporter.java index 50d70777..f5c239f9 100644 --- a/src/main/java/me/cortex/voxy/client/importers/WorldImporter.java +++ b/src/main/java/me/cortex/voxy/client/importers/WorldImporter.java @@ -126,7 +126,7 @@ public class WorldImporter { this.totalRegions.addAndGet(1); workers.submit(() -> { try { - if (!isRunning) { + if (!this.isRunning) { return; } this.importRegionFile(file.toPath(), rx, rz); diff --git a/src/main/java/me/cortex/voxy/common/world/thread/ServiceSlice.java b/src/main/java/me/cortex/voxy/common/world/thread/ServiceSlice.java index ebaabc65..3facff56 100644 --- a/src/main/java/me/cortex/voxy/common/world/thread/ServiceSlice.java +++ b/src/main/java/me/cortex/voxy/common/world/thread/ServiceSlice.java @@ -100,4 +100,8 @@ public class ServiceSlice extends TrackedObject { public int getJobCount() { return this.jobCount.availablePermits(); } + + public boolean hasJobs() { + return this.jobCount.availablePermits() != 0; + } } diff --git a/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java b/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java index d1b150fc..f8927428 100644 --- a/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java +++ b/src/main/java/me/cortex/voxy/common/world/thread/ServiceThreadPool.java @@ -83,6 +83,7 @@ public class ServiceThreadPool { private void worker(int threadId) { long seed = 1234342; + int revolvingSelector = 0; while (true) { this.jobCounter.acquireUninterruptibly(); if (!this.running) { @@ -102,12 +103,29 @@ public class ServiceThreadPool { System.err.println("Service worker tried to run but had 0 slices"); break; } - long chosenNumber = clamped % this.totalJobWeight.get(); + + ServiceSlice service = ref[(int) (clamped % ref.length)]; - for (var slice : ref) { - chosenNumber -= ((long) slice.weightPerJob) * slice.jobCount.availablePermits(); - if (chosenNumber <= 0) { - service = slice; + //1 in 64 chance just to pick a service that has a task, in a cycling manor, this is to keep at least one service from overloading all services constantly + if (((seed>>10)&63) == 0) { + for (int i = 0; i < ref.length; i++) { + int idx = (i+revolvingSelector)%ref.length; + var slice = ref[idx]; + if (slice.hasJobs()) { + service = slice; + revolvingSelector = (idx+1)%ref.length; + break; + } + } + + } else { + long chosenNumber = clamped % this.totalJobWeight.get(); + for (var slice : ref) { + chosenNumber -= ((long) slice.weightPerJob) * slice.jobCount.availablePermits(); + if (chosenNumber <= 0) { + service = slice; + break; + } } }