mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-02-16 02:20:44 +00:00
improve overwriting of the regenerated chunks
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
launch { locks[i].lock() }.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
action.run()
|
||||||
|
|
||||||
for (i in 0 until flags.length()) {
|
for (i in 0 until flags.length()) {
|
||||||
flags.set(i, other.flags.get(i))
|
flags[i] = other.flags[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i in 0 until flags.length()) {
|
||||||
|
locks[i].unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user