This commit is contained in:
mcrcortex
2025-12-29 13:00:04 +10:00
parent 470534831b
commit 848efe60a8
2 changed files with 13 additions and 1 deletions

View File

@@ -119,6 +119,7 @@ public class VoxelIngestService {
for (var section : chunk.getSections()) { for (var section : chunk.getSections()) {
i++; i++;
if (section == null || !shouldIngestSection(section, chunk.getPos().x, i, chunk.getPos().z)) continue; if (section == null || !shouldIngestSection(section, chunk.getPos().x, i, chunk.getPos().z)) continue;
engine.markActive();
this.ingestQueue.add(new IngestSection(chunk.getPos().x, i, chunk.getPos().z, engine, section, null, null)); this.ingestQueue.add(new IngestSection(chunk.getPos().x, i, chunk.getPos().z, engine, section, null, null));
try { try {
this.service.execute(); this.service.execute();
@@ -158,7 +159,7 @@ public class VoxelIngestService {
//if (blNone && slNone) { //if (blNone && slNone) {
// continue; // continue;
//} //}
engine.markActive();
this.ingestQueue.add(new IngestSection(chunk.getPos().x, i, chunk.getPos().z, engine, section, bl, sl));//TODO: fixme, this is technically not safe todo on the chunk load ingest, we need to copy the section data so it cant be modified while being read this.ingestQueue.add(new IngestSection(chunk.getPos().x, i, chunk.getPos().z, engine, section, bl, sl));//TODO: fixme, this is technically not safe todo on the chunk load ingest, we need to copy the section data so it cant be modified while being read
try { try {
this.service.execute(); this.service.execute();

View File

@@ -127,12 +127,18 @@ public abstract class VoxyInstance {
} }
public WorldEngine getOrCreate(WorldIdentifier identifier) { public WorldEngine getOrCreate(WorldIdentifier identifier) {
return this.getOrCreate(identifier, false);
}
public WorldEngine getOrCreate(WorldIdentifier identifier, boolean incrementRef) {
if (!this.isRunning) { if (!this.isRunning) {
Logger.error("Tried getting world object on voxy instance but its not running"); Logger.error("Tried getting world object on voxy instance but its not running");
return null; return null;
} }
var world = this.getNullable(identifier); var world = this.getNullable(identifier);
if (world != null) { if (world != null) {
world.markActive();
if (incrementRef) world.acquireRef();
return world; return world;
} }
long stamp = this.activeWorldLock.writeLock(); long stamp = this.activeWorldLock.writeLock();
@@ -147,6 +153,10 @@ public abstract class VoxyInstance {
//Create world here //Create world here
world = this.createWorld(identifier); world = this.createWorld(identifier);
} }
world.markActive();
if (incrementRef) world.acquireRef();
this.activeWorldLock.unlockWrite(stamp); this.activeWorldLock.unlockWrite(stamp);
identifier.cachedEngineObject = new WeakReference<>(world); identifier.cachedEngineObject = new WeakReference<>(world);
return world; return world;
@@ -199,6 +209,7 @@ public abstract class VoxyInstance {
public void addDebug(List<String> debug) { public void addDebug(List<String> debug) {
debug.add("MemoryBuffer, Count/Size (mb): " + MemoryBuffer.getCount() + "/" + (MemoryBuffer.getTotalSize()/1_000_000)); debug.add("MemoryBuffer, Count/Size (mb): " + MemoryBuffer.getCount() + "/" + (MemoryBuffer.getTotalSize()/1_000_000));
//TODO: fixme, doing this.activeWorlds.values() is not thread safe
debug.add("I/S/AWSC: " + this.ingestService.getTaskCount() + "/" + this.savingService.getTaskCount() + "/[" + this.activeWorlds.values().stream().map(a->""+a.getActiveSectionCount()).collect(Collectors.joining(", ")) + "]");//Active world section count debug.add("I/S/AWSC: " + this.ingestService.getTaskCount() + "/" + this.savingService.getTaskCount() + "/[" + this.activeWorlds.values().stream().map(a->""+a.getActiveSectionCount()).collect(Collectors.joining(", ")) + "]");//Active world section count
} }