This commit is contained in:
mcrcortex
2025-03-15 11:17:26 +10:00
parent 699ccb90b2
commit 4368f5bc4d
3 changed files with 21 additions and 7 deletions

View File

@@ -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) {

View File

@@ -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;
}
}

View File

@@ -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;