From 4368f5bc4d912715f00d6fdb7f9256ecf158f21e Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sat, 15 Mar 2025 11:17:26 +1000 Subject: [PATCH] stuff --- .../cortex/voxy/common/world/WorldEngine.java | 2 +- .../voxy/common/world/WorldSection.java | 24 +++++++++++++++---- .../cortex/voxy/commonImpl/VoxyInstance.java | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) 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 9c47ccd3..19f78805 100644 --- a/src/main/java/me/cortex/voxy/common/world/WorldEngine.java +++ b/src/main/java/me/cortex/voxy/common/world/WorldEngine.java @@ -46,7 +46,7 @@ public class WorldEngine { this.storage = storage; this.mapper = new Mapper(this.storage); //5 cache size bits means that the section tracker has 32 separate maps that it uses - this.sectionTracker = new ActiveSectionTracker(5, storage::loadSection, cacheCount, this); + this.sectionTracker = new ActiveSectionTracker(7, storage::loadSection, cacheCount, this); } public WorldSection acquireIfExists(int lvl, int x, int y, int z) { diff --git a/src/main/java/me/cortex/voxy/common/world/WorldSection.java b/src/main/java/me/cortex/voxy/common/world/WorldSection.java index cd4d3a18..3f8cf043 100644 --- a/src/main/java/me/cortex/voxy/common/world/WorldSection.java +++ b/src/main/java/me/cortex/voxy/common/world/WorldSection.java @@ -90,16 +90,34 @@ public final class WorldSection { } public boolean tryAcquire() { + int prev, next; + do { + prev = (int) ATOMIC_STATE_HANDLE.get(this); + if ((prev&1) == 0) { + //The object has been release so early exit + return false; + } + next = prev + 2; + } while (!ATOMIC_STATE_HANDLE.compareAndSet(this, prev, next)); + return (next&1) != 0; + + + /* int prev, next; do { prev = (int) ATOMIC_STATE_HANDLE.get(this); next = ((prev&1) != 0)?prev+2:prev; } while (!ATOMIC_STATE_HANDLE.compareAndSet(this, prev, next)); return (next&1) != 0; + */ } public int acquire() { - int state =((int) ATOMIC_STATE_HANDLE.getAndAdd(this, 2)) + 2; + return this.acquire(1); + } + + public int acquire(int count) { + int state =((int) ATOMIC_STATE_HANDLE.getAndAdd(this, count<<1)) + (count<<1); if (VERIFY_WORLD_SECTION_EXECUTION) { if ((state & 1) == 0) { throw new IllegalStateException("Tried to acquire unloaded section"); @@ -259,8 +277,4 @@ public final class WorldSection { public static WorldSection _createRawUntrackedUnsafeSection(int lvl, int x, int y, int z) { return new WorldSection(lvl, x, y, z, null); } - - public ActiveSectionTracker _getSectionTracker() { - return this.tracker; - } } \ No newline at end of file diff --git a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java index 2b69bc8a..18a1368b 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java +++ b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java @@ -81,7 +81,7 @@ public class VoxyInstance { } protected WorldEngine createWorld(SectionStorage storage) { - var world = new WorldEngine(storage, 1024); + var world = new WorldEngine(storage, 2048); world.setSaveCallback(this.savingService::enqueueSave); this.activeWorlds.add(world); return world;