9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-28 03:29:06 +00:00

Performance Improvements

This commit is contained in:
cyberpwn
2021-08-23 03:12:17 -04:00
parent 44acfc7ec8
commit 9d62113388
20 changed files with 292 additions and 106 deletions

View File

@@ -48,6 +48,7 @@ import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.math.RollingSequence;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
@@ -408,8 +409,8 @@ public class IrisEngine extends BlockPopulator implements Engine {
try {
PrecisionStopwatch p = PrecisionStopwatch.start();
Hunk<BlockData> blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y + getMinHeight(), z + zz, t));
getMantle().generateMatter(x >> 4, z >> 4, multicore);
burst().burst(multicore,
() -> getTerrainActuator().actuate(x, z, vblocks, multicore),
() -> getBiomeActuator().actuate(x, z, vbiomes, multicore)
@@ -420,12 +421,11 @@ public class IrisEngine extends BlockPopulator implements Engine {
() -> getRavineModifier().modify(x, z, vblocks, multicore)
);
getDecorantActuator().actuate(x, z, blocks, multicore);
getPostModifier().modify(x, z, vblocks, multicore);
burst().burst(multicore,
() -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore),
() -> getDepositModifier().modify(x, z, blocks, multicore)
() -> getDepositModifier().modify(x, z, vblocks, multicore)
);
getMetrics().getTotal().put(p.getMilliseconds());

View File

@@ -18,6 +18,7 @@
package com.volmit.iris.engine.data.chunk;
import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.BiomeBaseInjector;
import com.volmit.iris.util.nbt.mca.Chunk;
import com.volmit.iris.util.nbt.mca.NBTWorld;
@@ -69,7 +70,7 @@ public class MCATerrainChunk implements TerrainChunk {
@Override
public void setBiome(int x, int y, int z, Biome bio) {
writer.setBiome(ox + x, y, oz + z, bio);
mcaChunk.setBiomeAt((ox + x) & 15, y, (oz + z) & 15, writer.getBiomeId(bio));
}
@Override
@@ -91,6 +92,11 @@ public class MCATerrainChunk implements TerrainChunk {
return;
}
if(blockData == null)
{
Iris.error("NULL BD");
}
mcaChunk.setBlockStateAt(xx, y, zz, NBTWorld.getCompound(blockData), false);
}

View File

@@ -37,6 +37,7 @@ import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.noise.CNG;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import org.bukkit.Chunk;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
@@ -187,13 +188,13 @@ public interface EngineMantle extends IObjectPlacer {
};
int s = getRealRadius();
BurstExecutor burst = burst().burst(multicore);
MantleWriter writer = getMantle().write(this, x, z, s * 2);
for (int i = -s; i <= s; i++) {
for (int j = -s; j <= s; j++) {
int xx = i + x;
int zz = j + z;
burst.queue(() -> {
getComponents().forEach((f) -> generateMantleComponent(xx, zz, f, c));
getComponents().forEach((f) -> generateMantleComponent(writer, xx, zz, f, c));
});
}
}
@@ -208,8 +209,8 @@ public interface EngineMantle extends IObjectPlacer {
}
}
default void generateMantleComponent(int x, int z, MantleComponent c, Consumer<Runnable> post) {
getMantle().raiseFlag(x, z, c.getFlag(), () -> c.generateLayer(x, z, post));
default void generateMantleComponent(MantleWriter writer, int x, int z, MantleComponent c, Consumer<Runnable> post) {
getMantle().raiseFlag(x, z, c.getFlag(), () -> c.generateLayer(writer, x, z, post));
}
@ChunkCoordinates

View File

@@ -62,5 +62,5 @@ public interface MantleComponent {
MantleFlag getFlag();
@ChunkCoordinates
void generateLayer(int x, int z, Consumer<Runnable> post);
void generateLayer(MantleWriter writer, int x, int z, Consumer<Runnable> post);
}

View File

@@ -0,0 +1,149 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.mantle;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.engine.IrisEngineMantle;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.object.common.IObjectPlacer;
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
import com.volmit.iris.engine.object.tile.TileData;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.mantle.MantleChunk;
import com.volmit.iris.util.matter.Matter;
import lombok.Data;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
@Data
public class MantleWriter implements IObjectPlacer
{
private final EngineMantle engineMantle;
private final Mantle mantle;
private final KMap<Long, MantleChunk> cachedChunks;
private final int radius;
private final int x;
private final int z;
public MantleWriter(EngineMantle engineMantle, Mantle mantle, int x, int z, int radius)
{
this.engineMantle = engineMantle;
this.mantle = mantle;
this.cachedChunks = new KMap<>();
this.radius = radius;
this.x = x;
this.z = z;
for (int i = -radius; i <= radius; i++) {
for (int j = -radius; j <= radius; j++) {
cachedChunks.put(Cache.key(i + x, j + z), mantle.getChunk(i + x, j + z));
}
}
}
public <T> void setData(int x, int y, int z, T t)
{
int cx = x >> 4;
int cz = z >> 4;
if (y < 0 || y >= mantle.getWorldHeight()) {
return;
}
if(cx >= this.x - radius && cx <= this.x + radius
&& cz >= this.z - radius && cz <= this.z + radius)
{
MantleChunk chunk = cachedChunks.get(Cache.key(cx, cz));
if(chunk == null)
{
Iris.error("Mantle Writer Accessed " + cx + "," + cz + " and came up null (and yet within bounds!)");
return;
}
if(t instanceof IrisFeaturePositional)
{
chunk.addFeature((IrisFeaturePositional) t);
}
else
{
Matter matter = chunk.getOrCreate(y >> 4);
matter.slice(matter.getClass(t)).set(x & 15, y & 15, z & 15, t);
}
}
else
{
Iris.error("Mantle Writer[" + this.x + "," + this.z + ",R" + this.radius + "] Tried to access " + x + "," + y + "," + z + " (Chunk " + cx + "," + cz + ") which is OUT OF BOUNDS!");
}
}
@Override
public int getHighest(int x, int z, IrisData data) {
return engineMantle.getHighest(x, z, data);
}
@Override
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
return engineMantle.getHighest(x, z, data, ignoreFluid);
}
@Override
public void set(int x, int y, int z, BlockData d) {
setData(x, y, z, d);
}
@Override
public BlockData get(int x, int y, int z) {
return getEngineMantle().get(x, y, z);
}
@Override
public boolean isPreventingDecay() {
return getEngineMantle().isPreventingDecay();
}
@Override
public boolean isSolid(int x, int y, int z) {
return getEngineMantle().isSolid(x, y, z);
}
@Override
public boolean isUnderwater(int x, int z) {
return getEngineMantle().isUnderwater(x, z);
}
@Override
public int getFluidHeight() {
return getEngineMantle().getFluidHeight();
}
@Override
public boolean isDebugSmartBore() {
return getEngineMantle().isDebugSmartBore();
}
@Override
public void setTile(int xx, int yy, int zz, TileData<? extends TileState> tile) {
getEngineMantle().setTile(xx,yy,zz,tile);
}
}

View File

@@ -21,6 +21,7 @@ package com.volmit.iris.engine.mantle.components;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.mantle.EngineMantle;
import com.volmit.iris.engine.mantle.IrisMantleComponent;
import com.volmit.iris.engine.mantle.MantleWriter;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
@@ -38,34 +39,34 @@ public class MantleFeatureComponent extends IrisMantleComponent {
}
@Override
public void generateLayer(int x, int z, Consumer<Runnable> post) {
public void generateLayer(MantleWriter writer, int x, int z, Consumer<Runnable> post) {
RNG rng = new RNG(Cache.key(x, z) + seed());
int xxx = 8 + (x << 4);
int zzz = 8 + (z << 4);
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz);
generateFeatures(rng, x, z, region, biome);
generateFeatures(writer, rng, x, z, region, biome);
}
@ChunkCoordinates
private void generateFeatures(RNG rng, int cx, int cz, IrisRegion region, IrisBiome biome) {
private void generateFeatures(MantleWriter writer, RNG rng, int cx, int cz, IrisRegion region, IrisBiome biome) {
for (IrisFeaturePotential i : getFeatures()) {
placeZone(rng, cx, cz, i);
placeZone(writer, rng, cx, cz, i);
}
for (IrisFeaturePotential i : region.getFeatures()) {
placeZone(rng, cx, cz, i);
placeZone(writer, rng, cx, cz, i);
}
for (IrisFeaturePotential i : biome.getFeatures()) {
placeZone(rng, cx, cz, i);
placeZone(writer, rng, cx, cz, i);
}
}
private void placeZone(RNG rng, int cx, int cz, IrisFeaturePotential i) {
private void placeZone(MantleWriter writer, RNG rng, int cx, int cz, IrisFeaturePotential i) {
int x = (cx << 4) + rng.nextInt(16);
int z = (cz << 4) + rng.nextInt(16);
getMantle().set(x, 0, z, new IrisFeaturePositional(x, z, i.getZone()));
writer.setData(x, 0, z, new IrisFeaturePositional(x, z, i.getZone()));
}
private KList<IrisFeaturePotential> getFeatures() {

View File

@@ -18,12 +18,10 @@
package com.volmit.iris.engine.mantle.components;
import com.google.gson.Gson;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.jigsaw.PlannedStructure;
import com.volmit.iris.engine.mantle.EngineMantle;
import com.volmit.iris.engine.mantle.IrisMantleComponent;
import com.volmit.iris.engine.mantle.MantleWriter;
import com.volmit.iris.engine.object.basic.IrisPosition;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
@@ -50,17 +48,17 @@ public class MantleJigsawComponent extends IrisMantleComponent {
}
@Override
public void generateLayer(int x, int z, Consumer<Runnable> post) {
public void generateLayer(MantleWriter writer, int x, int z, Consumer<Runnable> post) {
RNG rng = new RNG(cng.fit(-Integer.MAX_VALUE, Integer.MAX_VALUE, x, z));
int xxx = 8 + (x << 4);
int zzz = 8 + (z << 4);
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz);
generateJigsaw(rng, x, z, biome, region, post);
generateJigsaw(writer, rng, x, z, biome, region, post);
}
@ChunkCoordinates
private void generateJigsaw(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer<Runnable> post) {
private void generateJigsaw(MantleWriter writer, RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer<Runnable> post) {
boolean placed = false;
if (getDimension().getStronghold() != null) {
@@ -70,7 +68,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
for (Position2 pos : poss) {
if (x == pos.getX() >> 4 && z == pos.getZ() >> 4) {
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getDimension().getStronghold());
place(pos.toIris(), structure, rng, post);
place(writer, pos.toIris(), structure, rng, post);
placed = true;
}
}
@@ -82,7 +80,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
if (rng.nextInt(i.getRarity()) == 0) {
IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15));
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure());
place(position, structure, rng, post);
place(writer, position, structure, rng, post);
placed = true;
}
}
@@ -93,7 +91,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
if (rng.nextInt(i.getRarity()) == 0) {
IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15));
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure());
place(position, structure, rng, post);
place(writer, position, structure, rng, post);
placed = true;
}
}
@@ -104,22 +102,22 @@ public class MantleJigsawComponent extends IrisMantleComponent {
if (rng.nextInt(i.getRarity()) == 0) {
IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15));
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure());
place(position, structure, rng, post);
place(writer, position, structure, rng, post);
}
}
}
}
@BlockCoordinates
private void place(IrisPosition position, IrisJigsawStructure structure, RNG rng, Consumer<Runnable> post) {
private void place(MantleWriter writer, IrisPosition position, IrisJigsawStructure structure, RNG rng, Consumer<Runnable> post) {
if (structure.getFeature() != null) {
if (structure.getFeature().getBlockRadius() == 32) {
structure.getFeature().setBlockRadius((double) structure.getMaxDimension() / 3);
}
getMantle().set(position.getX(), 0, position.getZ(),
writer.setData(position.getX(), 0, position.getZ(),
new IrisFeaturePositional(position.getX(), position.getZ(), structure.getFeature()));
}
post.accept(() -> new PlannedStructure(structure, position, rng).place(getEngineMantle(), getMantle(), post));
post.accept(() -> new PlannedStructure(structure, position, rng).place(writer, getMantle(), post));
}
}

View File

@@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.mantle.EngineMantle;
import com.volmit.iris.engine.mantle.IrisMantleComponent;
import com.volmit.iris.engine.mantle.MantleWriter;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.feature.IrisFeature;
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
@@ -42,21 +43,21 @@ public class MantleObjectComponent extends IrisMantleComponent {
}
@Override
public void generateLayer(int x, int z, Consumer<Runnable> post) {
public void generateLayer(MantleWriter writer, int x, int z, Consumer<Runnable> post) {
RNG rng = new RNG(Cache.key(x, z) + seed());
int xxx = 8 + (x << 4);
int zzz = 8 + (z << 4);
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz);
placeObjects(rng, x, z, biome, region, post);
placeObjects(writer, rng, x, z, biome, region, post);
}
@ChunkCoordinates
private void placeObjects(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer<Runnable> post) {
private void placeObjects(MantleWriter writer, RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer<Runnable> post) {
for (IrisObjectPlacement i : biome.getSurfaceObjects()) {
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && rng.chance(getComplex().getObjectChanceStream().get(x << 4, z << 4))) {
try {
placeObject(rng, x << 4, z << 4, i, post);
placeObject(writer, rng, x << 4, z << 4, i, post);
} catch (Throwable e) {
Iris.reportError(e);
Iris.error("Failed to place objects in the following biome: " + biome.getName());
@@ -70,7 +71,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
for (IrisObjectPlacement i : region.getSurfaceObjects()) {
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && rng.chance(getComplex().getObjectChanceStream().get(x << 4, z << 4))) {
try {
placeObject(rng, x << 4, z << 4, i, post);
placeObject(writer, rng, x << 4, z << 4, i, post);
} catch (Throwable e) {
Iris.reportError(e);
Iris.error("Failed to place objects in the following region: " + region.getName());
@@ -83,7 +84,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
}
@BlockCoordinates
private void placeObject(RNG rng, int x, int z, IrisObjectPlacement objectPlacement, Consumer<Runnable> post) {
private void placeObject(MantleWriter writer, RNG rng, int x, int z, IrisObjectPlacement objectPlacement, Consumer<Runnable> post) {
for (int i = 0; i < objectPlacement.getDensity(); i++) {
IrisObject v = objectPlacement.getScale().get(rng, objectPlacement.getObject(getComplex(), rng));
if (v == null) {
@@ -94,8 +95,8 @@ public class MantleObjectComponent extends IrisMantleComponent {
int id = rng.i(0, Integer.MAX_VALUE);
Runnable r = () -> {
int h = v.place(xx, -1, zz, getEngineMantle(), objectPlacement, rng,
(b) -> getMantle().set(b.getX(), b.getY(), b.getZ(),
int h = v.place(xx, -1, zz, writer, objectPlacement, rng,
(b) -> writer.setData(b.getX(), b.getY(), b.getZ(),
v.getLoadKey() + "@" + id), null, getData());
if (objectPlacement.usesFeatures()) {
@@ -108,12 +109,12 @@ public class MantleObjectComponent extends IrisMantleComponent {
f.setInterpolationRadius(objectPlacement.getVacuumInterpolationRadius());
f.setInterpolator(objectPlacement.getVacuumInterpolationMethod());
f.setStrength(1D);
getMantle().set(xx, 0, zz, new IrisFeaturePositional(xx, zz, f));
writer.setData(xx, 0, zz, new IrisFeaturePositional(xx, zz, f));
}
for (IrisFeaturePotential j : objectPlacement.getAddFeatures()) {
if (j.hasZone(rng, xx >> 4, zz >> 4)) {
getMantle().set(xx, 0, zz, new IrisFeaturePositional(xx, zz, j.getZone()));
writer.setData(xx, 0, zz, new IrisFeaturePositional(xx, zz, j.getZone()));
}
}
}

View File

@@ -34,6 +34,7 @@ import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.documentation.RegionCoordinates;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.math.Position2;
import com.volmit.iris.util.nbt.mca.MCAFile;
import com.volmit.iris.util.nbt.mca.MCAUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.tag.CompoundTag;
@@ -64,12 +65,11 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
}
@ChunkCoordinates
public void generateChunk(int x, int z) {
public void generateChunk(MCAFile file, int x, int z) {
try {
int ox = x << 4;
int oz = z << 4;
com.volmit.iris.util.nbt.mca.Chunk chunk = writer.getChunk(x, z);
com.volmit.iris.util.nbt.mca.Chunk chunk = writer.getChunk(file, x, z);
TerrainChunk tc = MCATerrainChunk.builder()
.writer(writer).ox(ox).oz(oz).mcaChunk(chunk)
.minHeight(world.getWorld().minHeight()).maxHeight(world.getWorld().maxHeight())
@@ -102,11 +102,12 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
@RegionCoordinates
public void generateRegion(int x, int z, PregenListener listener) {
BurstExecutor e = burst.burst(1024);
MCAFile f = writer.getMCA(x, x);
PregenTask.iterateRegion(x, z, (ii, jj) -> e.queue(() -> {
if (listener != null) {
listener.onChunkGenerating(ii, jj);
}
generateChunk(ii, jj);
generateChunk(f, ii, jj);
if (listener != null) {
listener.onChunkGenerated(ii, jj);
}