improve overwriting of the regenerated chunks

This commit is contained in:
Julian Krings
2025-12-18 10:59:32 +01:00
parent 93ca26e368
commit fbdae4c928
3 changed files with 25 additions and 20 deletions

View File

@@ -222,22 +222,8 @@ public class CommandStudio implements DecreeExecutor {
job.execute(sender(), latch::countDown); job.execute(sender(), latch::countDown);
latch.await(); latch.await();
int sections = mantle.getWorldHeight() >> 4; chunkMap.forEach((pos, chunk) ->
chunkMap.forEach((pos, chunk) -> { mantle.getChunk(pos.getX(), pos.getZ()).copyFrom(chunk));
var c = mantle.getChunk(pos.getX(), pos.getZ()).use();
try {
c.copyFlags(chunk);
c.clear();
for (int y = 0; y < sections; y++) {
var slice = chunk.get(y);
if (slice == null) continue;
var s = c.getOrCreate(y);
slice.getSliceMap().forEach(s::putSlice);
}
} finally {
c.release();
}
});
} catch (Throwable e) { } catch (Throwable e) {
sender().sendMessage("Error while regenerating chunks"); sender().sendMessage("Error while regenerating chunks");
e.printStackTrace(); e.printStackTrace();

View File

@@ -131,9 +131,13 @@ public class MantleChunk extends FlaggedChunk {
ref.release(); ref.release();
} }
public void copyFlags(MantleChunk chunk) { public void copyFrom(MantleChunk chunk) {
use(); use();
super.copyFlags(chunk); super.copyFrom(chunk, () -> {
for (int i = 0; i < sections.length(); i++) {
sections.set(i, chunk.get(i));
}
});
release(); release();
} }

View File

@@ -3,6 +3,9 @@ package com.volmit.iris.util.mantle
import com.volmit.iris.util.data.Varint import com.volmit.iris.util.data.Varint
import com.volmit.iris.util.mantle.flag.MantleFlag import com.volmit.iris.util.mantle.flag.MantleFlag
import com.volmit.iris.util.parallel.AtomicBooleanArray import com.volmit.iris.util.parallel.AtomicBooleanArray
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import java.io.DataInput import java.io.DataInput
@@ -22,9 +25,21 @@ abstract class FlaggedChunk() {
abstract fun isClosed(): Boolean abstract fun isClosed(): Boolean
protected fun copyFlags(other: FlaggedChunk) { protected fun copyFrom(other: FlaggedChunk, action: Runnable) = runBlocking {
coroutineScope {
for (i in 0 until flags.length()) { for (i in 0 until flags.length()) {
flags.set(i, other.flags.get(i)) launch { locks[i].lock() }.start()
}
}
action.run()
for (i in 0 until flags.length()) {
flags[i] = other.flags[i]
}
for (i in 0 until flags.length()) {
locks[i].unlock()
} }
} }