mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-27 19:19:07 +00:00
Cleanup components
This commit is contained in:
@@ -24,6 +24,7 @@ import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||
import com.volmit.iris.engine.mantle.MantleComponent;
|
||||
import com.volmit.iris.engine.mantle.components.MantleFeatureComponent;
|
||||
import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import lombok.Data;
|
||||
@@ -45,6 +46,7 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
components = new KList<>();
|
||||
registerComponent(new MantleFeatureComponent(this));
|
||||
registerComponent(new MantleJigsawComponent(this));
|
||||
registerComponent(new MantleObjectComponent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,10 +41,14 @@ import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.mantle.TectonicPlate;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
@@ -171,6 +175,11 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
getMantle().trim(60000);
|
||||
}
|
||||
|
||||
default MultiBurst burst()
|
||||
{
|
||||
return getEngine().burst();
|
||||
}
|
||||
|
||||
default int getRealRadius()
|
||||
{
|
||||
getMantle().set(0, 34, 292393, Bukkit.getPlayer("cyberpwn"));
|
||||
@@ -193,10 +202,15 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
return;
|
||||
}
|
||||
|
||||
KList<Runnable> post = new KList<>();
|
||||
List<Runnable> post = Collections.synchronizedList(new KList<>());
|
||||
Consumer<Runnable> c = post::add;
|
||||
getComponents().forEach((i) -> getMantle().raiseFlag(x, z, i.getFlag(), () -> i.generateLayer(x, z, c)));
|
||||
post.forEach(Runnable::run);
|
||||
getComponents().forEach((i) -> generateMantleComponent(x, z, i, c));
|
||||
burst().burst(post);
|
||||
}
|
||||
|
||||
default void generateMantleComponent(int x, int z, MantleComponent i, Consumer<Runnable> post)
|
||||
{
|
||||
getMantle().raiseFlag(x, z, i.getFlag(), () -> i.generateLayer(x, z, post));
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
|
||||
@@ -28,7 +28,8 @@ import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure;
|
||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
||||
import com.volmit.iris.engine.object.regional.IrisRegion;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
@@ -58,7 +59,7 @@ public class MantleJigsawComponent extends IrisMantleComponent
|
||||
RNG rng = new RNG(Cache.key(xx, zz) + seed());
|
||||
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
|
||||
IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz);
|
||||
generateParallaxJigsaw(rng, xx, zz, biome, region, post);
|
||||
generateJigsaw(rng, xx, zz, biome, region, post);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -66,7 +67,8 @@ public class MantleJigsawComponent extends IrisMantleComponent
|
||||
burst.complete();
|
||||
}
|
||||
|
||||
private void generateParallaxJigsaw(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer<Runnable> post) {
|
||||
@ChunkCoordinates
|
||||
private void generateJigsaw(RNG rng, int x, int z, IrisBiome biome, IrisRegion region, Consumer<Runnable> post) {
|
||||
boolean placed = false;
|
||||
|
||||
if (getDimension().getStronghold() != null) {
|
||||
@@ -76,7 +78,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());
|
||||
placeStructure(pos.toIris(), structure, rng, post);
|
||||
place(pos.toIris(), structure, rng, post);
|
||||
placed = true;
|
||||
}
|
||||
}
|
||||
@@ -88,7 +90,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());
|
||||
placeStructure(position, structure, rng, post);
|
||||
place(position, structure, rng, post);
|
||||
placed = true;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +101,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());
|
||||
placeStructure(position, structure, rng, post);
|
||||
place(position, structure, rng, post);
|
||||
placed = true;
|
||||
}
|
||||
}
|
||||
@@ -110,14 +112,14 @@ 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());
|
||||
placeStructure(position, structure, rng, post);
|
||||
place(position, structure, rng, post);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void placeStructure(IrisPosition position, IrisJigsawStructure structure, RNG rng, Consumer<Runnable> post) {
|
||||
@BlockCoordinates
|
||||
private void place(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);
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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.components;
|
||||
|
||||
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.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeature;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
import com.volmit.iris.engine.object.objects.IrisObjectPlacement;
|
||||
import com.volmit.iris.engine.object.regional.IrisRegion;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class MantleObjectComponent extends IrisMantleComponent {
|
||||
public MantleObjectComponent(EngineMantle engineMantle) {
|
||||
super(engineMantle, MantleFlag.FEATURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateLayer(int x, int z, Consumer<Runnable> post) {
|
||||
int s = getRadius();
|
||||
BurstExecutor burst = burst();
|
||||
|
||||
for (int i = -s; i <= s; i++) {
|
||||
int xx = i + x;
|
||||
int xxx = 8 + (xx << 4);
|
||||
for (int j = -s; j <= s; j++) {
|
||||
int zz = j + z;
|
||||
int zzz = 8 + (zz << 4);
|
||||
burst.queue(() -> {
|
||||
RNG rng = new RNG(Cache.key(xx, zz) + seed());
|
||||
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
|
||||
IrisBiome biome = getComplex().getTrueBiomeStreamNoFeatures().get(xxx, zzz);
|
||||
placeObjects(rng, xx, zz, biome, region, post);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
burst.complete();
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void placeObjects(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);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Iris.error("Failed to place objects in the following biome: " + biome.getName());
|
||||
Iris.error("Object(s) " + i.getPlace().toString(", ") + " (" + e.getClass().getSimpleName() + ").");
|
||||
Iris.error("Are these objects missing?");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Iris.error("Failed to place objects in the following region: " + region.getName());
|
||||
Iris.error("Object(s) " + i.getPlace().toString(", ") + " (" + e.getClass().getSimpleName() + ").");
|
||||
Iris.error("Are these objects missing?");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void placeObject(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) {
|
||||
return;
|
||||
}
|
||||
int xx = rng.i(x, x + 16);
|
||||
int zz = rng.i(z, z + 16);
|
||||
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(),
|
||||
v.getLoadKey() + "@" + id), null, getData());
|
||||
|
||||
if (objectPlacement.usesFeatures()) {
|
||||
if (objectPlacement.isVacuum()) {
|
||||
|
||||
double a = Math.max(v.getW(), v.getD());
|
||||
IrisFeature f = new IrisFeature();
|
||||
f.setConvergeToHeight(h - (v.getH() >> 1));
|
||||
f.setBlockRadius(a);
|
||||
f.setInterpolationRadius(objectPlacement.getVacuumInterpolationRadius());
|
||||
f.setInterpolator(objectPlacement.getVacuumInterpolationMethod());
|
||||
f.setStrength(1D);
|
||||
getMantle().set(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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (objectPlacement.usesFeatures()) {
|
||||
r.run();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
post.accept(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package com.volmit.iris.util.parallel;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@@ -42,7 +43,7 @@ public class BurstExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
public BurstExecutor queue(KList<Runnable> r) {
|
||||
public BurstExecutor queue(List<Runnable> r) {
|
||||
synchronized (futures) {
|
||||
for (Runnable i : r) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Supplier;
|
||||
@@ -99,7 +100,7 @@ public class MultiBurst {
|
||||
burst(r.length).queue(r).complete();
|
||||
}
|
||||
|
||||
public void burst(KList<Runnable> r) {
|
||||
public void burst(List<Runnable> r) {
|
||||
burst(r.size()).queue(r).complete();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user