mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Remove block data caching
This commit is contained in:
parent
56e13641df
commit
617066340b
@ -32,7 +32,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'com.volmit.iris'
|
group 'com.volmit.iris'
|
||||||
version '1.7.8'
|
version '1.7.8-Dumpy'
|
||||||
def apiVersion = '1.17'
|
def apiVersion = '1.17'
|
||||||
def name = getRootProject().getName() // See settings.gradle
|
def name = getRootProject().getName() // See settings.gradle
|
||||||
def main = 'com.volmit.iris.Iris'
|
def main = 'com.volmit.iris.Iris'
|
||||||
|
@ -107,6 +107,14 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
IO.delete(new File("iris"));
|
IO.delete(new File("iris"));
|
||||||
installDataPacks();
|
installDataPacks();
|
||||||
fixShading();
|
fixShading();
|
||||||
|
(new Looper() {
|
||||||
|
protected long loop() {
|
||||||
|
File ff = Iris.instance.getDataFolderNoCreate("dump");
|
||||||
|
if (ff.exists() && ff.isDirectory() && ff.listFiles().length == 0)
|
||||||
|
Iris.dump();
|
||||||
|
return 10000L;
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -59,7 +59,6 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -68,9 +67,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
@Data
|
||||||
public class IrisEngine extends BlockPopulator implements Engine {
|
public class IrisEngine implements Engine {
|
||||||
// TODO: Remove block population, stop using bukkit
|
// TODO: Remove block population, stop using bukkit
|
||||||
private final AtomicInteger generated;
|
private final AtomicInteger generated;
|
||||||
private final AtomicInteger generatedLast;
|
private final AtomicInteger generatedLast;
|
||||||
@ -460,22 +458,6 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
|||||||
return getData().getBiomeLoader().load(getDimension().getFocus());
|
return getData().getBiomeLoader().load(getDimension().getFocus());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove block population
|
|
||||||
@ChunkCoordinates
|
|
||||||
@Override
|
|
||||||
public void populate(World world, Random random, Chunk c) {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
updateChunk(c);
|
|
||||||
placeTiles(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch(Throwable e)
|
|
||||||
{
|
|
||||||
Iris.reportError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fail(String error, Throwable e) {
|
public void fail(String error, Throwable e) {
|
||||||
failing = true;
|
failing = true;
|
||||||
|
@ -39,11 +39,13 @@ import com.volmit.iris.util.math.RNG;
|
|||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
import com.volmit.iris.util.scheduling.Looper;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -64,6 +66,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
private final ChronoLatch cl;
|
private final ChronoLatch cl;
|
||||||
private final ChronoLatch ecl;
|
private final ChronoLatch ecl;
|
||||||
private final ChronoLatch cln;
|
private final ChronoLatch cln;
|
||||||
|
private final ChronoLatch chunkUpdater;
|
||||||
private long charge = 0;
|
private long charge = 0;
|
||||||
private int actuallySpawned = 0;
|
private int actuallySpawned = 0;
|
||||||
private int cooldown = 0;
|
private int cooldown = 0;
|
||||||
@ -76,11 +79,13 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
cln = null;
|
cln = null;
|
||||||
chunkCooldowns = null;
|
chunkCooldowns = null;
|
||||||
looper = null;
|
looper = null;
|
||||||
|
chunkUpdater = null;
|
||||||
id = -1;
|
id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IrisWorldManager(Engine engine) {
|
public IrisWorldManager(Engine engine) {
|
||||||
super(engine);
|
super(engine);
|
||||||
|
chunkUpdater = new ChronoLatch(1000);
|
||||||
cln = new ChronoLatch(60000);
|
cln = new ChronoLatch(60000);
|
||||||
cl = new ChronoLatch(3000);
|
cl = new ChronoLatch(3000);
|
||||||
ecl = new ChronoLatch(250);
|
ecl = new ChronoLatch(250);
|
||||||
@ -94,42 +99,50 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
interrupt();
|
interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getDimension().isInfiniteEnergy()) {
|
if(getEngine().getWorld().hasRealWorld())
|
||||||
energy += 1000;
|
{
|
||||||
fixEnergy();
|
if(chunkUpdater.flip())
|
||||||
}
|
{
|
||||||
|
updateChunks();
|
||||||
|
}
|
||||||
|
|
||||||
if (M.ms() < charge) {
|
if (getDimension().isInfiniteEnergy()) {
|
||||||
energy += 70;
|
energy += 1000;
|
||||||
fixEnergy();
|
fixEnergy();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cln.flip()) {
|
if (M.ms() < charge) {
|
||||||
engine.getEngineData().cleanup(getEngine());
|
energy += 70;
|
||||||
}
|
fixEnergy();
|
||||||
|
}
|
||||||
|
|
||||||
if (precount != null) {
|
if (cln.flip()) {
|
||||||
entityCount = 0;
|
engine.getEngineData().cleanup(getEngine());
|
||||||
for (Entity i : precount) {
|
}
|
||||||
if (i instanceof LivingEntity) {
|
|
||||||
if (!i.isDead()) {
|
if (precount != null) {
|
||||||
entityCount++;
|
entityCount = 0;
|
||||||
|
for (Entity i : precount) {
|
||||||
|
if (i instanceof LivingEntity) {
|
||||||
|
if (!i.isDead()) {
|
||||||
|
entityCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
precount = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (energy < 650) {
|
||||||
|
if (ecl.flip()) {
|
||||||
|
energy *= 1 + (0.02 * M.clip((1D - getEntitySaturation()), 0D, 1D));
|
||||||
|
fixEnergy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
precount = null;
|
onAsyncTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (energy < 650) {
|
|
||||||
if (ecl.flip()) {
|
|
||||||
energy *= 1 + (0.02 * M.clip((1D - getEntitySaturation()), 0D, 1D));
|
|
||||||
fixEnergy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onAsyncTick();
|
|
||||||
|
|
||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -138,6 +151,16 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
looper.start();
|
looper.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateChunks() {
|
||||||
|
for(Player i : getEngine().getWorld().realWorld().getPlayers())
|
||||||
|
{
|
||||||
|
J.s(() -> {
|
||||||
|
Chunk c = i.getLocation().getChunk();
|
||||||
|
J.a(() -> getEngine().updateChunk(c));
|
||||||
|
}, RNG.r.i(0, 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean onAsyncTick() {
|
private boolean onAsyncTick() {
|
||||||
if (getEngine().isClosed()) {
|
if (getEngine().isClosed()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -21,6 +21,8 @@ package com.volmit.iris.engine.framework;
|
|||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.generator.LimitedRegion;
|
||||||
|
import org.bukkit.generator.WorldInfo;
|
||||||
|
|
||||||
public interface BlockUpdater {
|
public interface BlockUpdater {
|
||||||
|
|
||||||
|
@ -45,8 +45,10 @@ import com.volmit.iris.util.data.B;
|
|||||||
import com.volmit.iris.util.data.DataProvider;
|
import com.volmit.iris.util.data.DataProvider;
|
||||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.function.Function2;
|
import com.volmit.iris.util.function.Function2;
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
import com.volmit.iris.util.hunk.Hunk;
|
||||||
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.math.BlockPosition;
|
import com.volmit.iris.util.math.BlockPosition;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
@ -57,9 +59,8 @@ import com.volmit.iris.util.scheduling.ChronoLatch;
|
|||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import com.volmit.iris.util.stream.ProceduralStream;
|
import com.volmit.iris.util.stream.ProceduralStream;
|
||||||
import org.bukkit.Chunk;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
@ -69,6 +70,7 @@ import org.bukkit.inventory.InventoryHolder;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@ -232,19 +234,21 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
@Override
|
@Override
|
||||||
default void updateChunk(Chunk c) {
|
default void updateChunk(Chunk c) {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
getMantle().getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.UPDATE, () -> J.s(() -> {
|
||||||
getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), Boolean.class, (x, y, z, v) -> {
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
if (v != null && v) {
|
getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), Boolean.class, (x, y, z, v) -> {
|
||||||
int vx = x & 15;
|
if (v != null && v) {
|
||||||
int vz = z & 15;
|
int vx = x & 15;
|
||||||
update(x, y, z, c, new RNG(Cache.key(c.getX(), c.getZ())));
|
int vz = z & 15;
|
||||||
|
update(x, y, z, c, new RNG(Cache.key(c.getX(), c.getZ())));
|
||||||
|
|
||||||
if (vx > 0 && vx < 15 && vz > 0 && vz < 15) {
|
if (vx > 0 && vx < 15 && vz > 0 && vz < 15) {
|
||||||
updateLighting(x, y, z, c);
|
updateLighting(x, y, z, c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
getMetrics().getUpdates().put(p.getMilliseconds());
|
||||||
getMetrics().getUpdates().put(p.getMilliseconds());
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@BlockCoordinates
|
@BlockCoordinates
|
||||||
@ -389,11 +393,37 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
items.addAll(i.getLoot(debug, items.isEmpty(), rng, slot, x, y, z, b + b, mgf + b));
|
items.addAll(i.getLoot(debug, items.isEmpty(), rng, slot, x, y, z, b + b, mgf + b));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemStack i : items) {
|
if(PaperLib.isPaper() && getWorld().hasRealWorld())
|
||||||
inv.addItem(i);
|
{
|
||||||
|
PaperLib.getChunkAtAsync(getWorld().realWorld(), x >> 4, z >> 4).thenAccept((c) -> {
|
||||||
|
Runnable r = () -> {
|
||||||
|
for (ItemStack i : items) {
|
||||||
|
inv.addItem(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
scramble(inv, rng);
|
||||||
|
};
|
||||||
|
|
||||||
|
if(Bukkit.isPrimaryThread())
|
||||||
|
{
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
J.s(r);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
scramble(inv, rng);
|
else
|
||||||
|
{
|
||||||
|
for (ItemStack i : items) {
|
||||||
|
inv.addItem(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
scramble(inv, rng);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EngineEffects getEffects();
|
EngineEffects getEffects();
|
||||||
|
@ -136,7 +136,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
|
|
||||||
engine = new IrisEngine(new EngineTarget(world, dimension, data), studio);
|
engine = new IrisEngine(new EngineTarget(world, dimension, data), studio);
|
||||||
populators.clear();
|
populators.clear();
|
||||||
populators.add((BlockPopulator) engine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,7 +46,6 @@ public class B {
|
|||||||
private static final IntSet storageCache = buildStorageCache();
|
private static final IntSet storageCache = buildStorageCache();
|
||||||
private static final IntSet storageChestCache = buildStorageChestCache();
|
private static final IntSet storageChestCache = buildStorageChestCache();
|
||||||
private static final IntSet litCache = buildLitCache();
|
private static final IntSet litCache = buildLitCache();
|
||||||
private static final KMap<String, BlockData> blockDataCache = new KMap<>();
|
|
||||||
private static final ChronoLatch clw = new ChronoLatch(1000);
|
private static final ChronoLatch clw = new ChronoLatch(1000);
|
||||||
|
|
||||||
private static IntSet buildFoliageCache() {
|
private static IntSet buildFoliageCache() {
|
||||||
@ -346,12 +345,6 @@ public class B {
|
|||||||
|
|
||||||
private static BlockData parseBlockData(String ix) {
|
private static BlockData parseBlockData(String ix) {
|
||||||
try {
|
try {
|
||||||
BlockData bb = blockDataCache.get(ix);
|
|
||||||
|
|
||||||
if (bb != null) {
|
|
||||||
return bb;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockData bx = null;
|
BlockData bx = null;
|
||||||
|
|
||||||
if (ix.startsWith("oraxen:") && Iris.linkOraxen.supported()) {
|
if (ix.startsWith("oraxen:") && Iris.linkOraxen.supported()) {
|
||||||
@ -368,7 +361,6 @@ public class B {
|
|||||||
((Leaves) bx).setPersistent(false);
|
((Leaves) bx).setPersistent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDataCache.put(ix, bx);
|
|
||||||
return bx;
|
return bx;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if(clw.flip())
|
if(clw.flip())
|
||||||
@ -420,9 +412,7 @@ public class B {
|
|||||||
Iris.debug("Converting " + ix + " to " + newBlock);
|
Iris.debug("Converting " + ix + " to " + newBlock);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BlockData bd = Bukkit.createBlockData(newBlock);
|
return Bukkit.createBlockData(newBlock);
|
||||||
blockDataCache.put(ix, bd);
|
|
||||||
return bd;
|
|
||||||
} catch (Throwable e1) {
|
} catch (Throwable e1) {
|
||||||
Iris.reportError(e1);
|
Iris.reportError(e1);
|
||||||
}
|
}
|
||||||
|
@ -473,8 +473,7 @@ public class Mantle {
|
|||||||
* @return the file
|
* @return the file
|
||||||
*/
|
*/
|
||||||
public static File fileForRegion(File folder, Long key) {
|
public static File fileForRegion(File folder, Long key) {
|
||||||
String id = UUID.nameUUIDFromBytes(("TectonicPlate:" + key).getBytes(StandardCharsets.UTF_8)).toString();
|
File f = new File(folder, "p." + key + ".ttp");
|
||||||
File f = new File(folder, id.substring(0, 2) + "/" + id.split("\\Q-\\E")[3] + "/" + id + ".ttp");
|
|
||||||
if(!f.getParentFile().exists())
|
if(!f.getParentFile().exists())
|
||||||
{
|
{
|
||||||
f.getParentFile().mkdirs();
|
f.getParentFile().mkdirs();
|
||||||
|
@ -513,6 +513,16 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getDataFolderNoCreate(String... strings) {
|
||||||
|
if (strings.length == 0) {
|
||||||
|
return super.getDataFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
File f = new File(getDataFolder(), new KList<>(strings).toString(File.separator));
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
public File getDataFolderList(String pre, String[] strings) {
|
public File getDataFolderList(String pre, String[] strings) {
|
||||||
KList<String> v = new KList<>(strings);
|
KList<String> v = new KList<>(strings);
|
||||||
v.add(0, pre);
|
v.add(0, pre);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user