Starcast is 60+% faster

This commit is contained in:
cyberpwn
2021-09-18 04:42:23 -04:00
parent 9caa89b733
commit a7aea8d1ed
17 changed files with 842 additions and 2044 deletions
@@ -38,8 +38,7 @@ public class CommandFind implements DecreeExecutor {
) { ) {
Engine e = engine(); Engine e = engine();
if(e == null) if (e == null) {
{
sender().sendMessage(C.GOLD + "Not in an Iris World!"); sender().sendMessage(C.GOLD + "Not in an Iris World!");
return; return;
} }
@@ -54,8 +53,7 @@ public class CommandFind implements DecreeExecutor {
) { ) {
Engine e = engine(); Engine e = engine();
if(e == null) if (e == null) {
{
sender().sendMessage(C.GOLD + "Not in an Iris World!"); sender().sendMessage(C.GOLD + "Not in an Iris World!");
return; return;
} }
@@ -70,8 +68,7 @@ public class CommandFind implements DecreeExecutor {
) { ) {
Engine e = engine(); Engine e = engine();
if(e == null) if (e == null) {
{
sender().sendMessage(C.GOLD + "Not in an Iris World!"); sender().sendMessage(C.GOLD + "Not in an Iris World!");
return; return;
} }
@@ -86,8 +83,7 @@ public class CommandFind implements DecreeExecutor {
) { ) {
Engine e = engine(); Engine e = engine();
if(e == null) if (e == null) {
{
sender().sendMessage(C.GOLD + "Not in an Iris World!"); sender().sendMessage(C.GOLD + "Not in an Iris World!");
return; return;
} }
@@ -34,7 +34,6 @@ import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.data.DataProvider; import com.volmit.iris.util.data.DataProvider;
import com.volmit.iris.util.interpolation.IrisInterpolation;
import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.noise.CNG;
@@ -291,10 +290,8 @@ public class IrisComplex implements DataProvider {
return biome; return biome;
} }
private double interpolateGenerators(Engine engine, IrisInterpolator interpolator, KSet<IrisGenerator> generators, double x, double z, long seed) private double interpolateGenerators(Engine engine, IrisInterpolator interpolator, KSet<IrisGenerator> generators, double x, double z, long seed) {
{ if (generators.isEmpty()) {
if(generators.isEmpty())
{
return 0; return 0;
} }
@@ -338,8 +335,7 @@ public class IrisComplex implements DataProvider {
double d = 0; double d = 0;
for(IrisGenerator i : generators) for (IrisGenerator i : generators) {
{
d += M.lerp(lo, hi, i.getHeight(x, z, seed + 239945)); d += M.lerp(lo, hi, i.getHeight(x, z, seed + 239945));
} }
@@ -228,10 +228,8 @@ public class IrisEngine implements Engine {
} }
private void warmupChunk(int x, int z) { private void warmupChunk(int x, int z) {
for(int i = 0; i < 16; i++) for (int i = 0; i < 16; i++) {
{ for (int j = 0; j < 16; j++) {
for(int j = 0; j < 16; j++)
{
int xx = x + (i << 4); int xx = x + (i << 4);
int zz = z + (z << 4); int zz = z + (z << 4);
getComplex().getTrueBiomeStream().get(xx, zz); getComplex().getTrueBiomeStream().get(xx, zz);
@@ -118,8 +118,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
} }
if (getEngine().getWorld().hasRealWorld()) { if (getEngine().getWorld().hasRealWorld()) {
if(getEngine().getWorld().getPlayers().isEmpty()) if (getEngine().getWorld().getPlayers().isEmpty()) {
{
return 5000; return 5000;
} }
@@ -492,22 +491,19 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
Map<IrisPosition, KSet<IrisSpawner>> p = new KMap<>(); Map<IrisPosition, KSet<IrisSpawner>> p = new KMap<>();
Set<IrisPosition> b = new KSet<>(); Set<IrisPosition> b = new KSet<>();
getMantle().iterateChunk(c.getX(), c.getZ(), MatterMarker.class, (x, y, z, t) -> { getMantle().iterateChunk(c.getX(), c.getZ(), MatterMarker.class, (x, y, z, t) -> {
if(t.getTag().equals("cave_floor") || t.getTag().equals("cave_ceiling")) if (t.getTag().equals("cave_floor") || t.getTag().equals("cave_ceiling")) {
{
return; return;
} }
IrisMarker mark = getData().getMarkerLoader().load(t.getTag()); IrisMarker mark = getData().getMarkerLoader().load(t.getTag());
IrisPosition pos = new IrisPosition((c.getX() << 4) + x, y, (c.getZ() << 4) + z); IrisPosition pos = new IrisPosition((c.getX() << 4) + x, y, (c.getZ() << 4) + z);
if(mark.isEmptyAbove()) if (mark.isEmptyAbove()) {
{
AtomicBoolean remove = new AtomicBoolean(false); AtomicBoolean remove = new AtomicBoolean(false);
try { try {
J.sfut(() -> { J.sfut(() -> {
if(c.getBlock(x, y+1, z).getBlockData().getMaterial().isSolid() || c.getBlock(x, y+2, z).getBlockData().getMaterial().isSolid()) if (c.getBlock(x, y + 1, z).getBlockData().getMaterial().isSolid() || c.getBlock(x, y + 2, z).getBlockData().getMaterial().isSolid()) {
{
remove.set(true); remove.set(true);
} }
}).get(); }).get();
@@ -515,8 +511,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
e.printStackTrace(); e.printStackTrace();
} }
if(remove.get()) if (remove.get()) {
{
b.add(pos); b.add(pos);
return; return;
} }
@@ -534,8 +529,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
} }
}); });
for(IrisPosition i : b) for (IrisPosition i : b) {
{
getEngine().getMantle().getMantle().remove(i.getX(), i.getY(), i.getZ(), MatterMarker.class); getEngine().getMantle().getMantle().remove(i.getX(), i.getY(), i.getZ(), MatterMarker.class);
} }
@@ -550,8 +544,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
MatterMarker marker = getMantle().get(e.getBlock().getX(), e.getBlock().getY(), e.getBlock().getZ(), MatterMarker.class); MatterMarker marker = getMantle().get(e.getBlock().getX(), e.getBlock().getY(), e.getBlock().getZ(), MatterMarker.class);
if (marker != null) { if (marker != null) {
if(marker.getTag().equals("cave_floor") || marker.getTag().equals("cave_ceiling")) if (marker.getTag().equals("cave_floor") || marker.getTag().equals("cave_ceiling")) {
{
return; return;
} }
@@ -78,14 +78,14 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
int finalI = i; int finalI = i;
burst.queue(() -> { burst.queue(() -> {
int height; int height;
int realX = (int) Math.round(x + finalI); int realX = Math.round(x + finalI);
int realZ; int realZ;
IrisBiome biome, cave; IrisBiome biome, cave;
for (int j = 0; j < output.getDepth(); j++) { for (int j = 0; j < output.getDepth(); j++) {
boolean solid; boolean solid;
int emptyFor = 0; int emptyFor = 0;
int lastSolid = 0; int lastSolid = 0;
realZ = (int) Math.round(z + j); realZ = Math.round(z + j);
height = (int) Math.round(getComplex().getHeightStream().get(realX, realZ)); height = (int) Math.round(getComplex().getHeightStream().get(realX, realZ));
biome = getComplex().getTrueBiomeStream().get(realX, realZ); biome = getComplex().getTrueBiomeStream().get(realX, realZ);
cave = shouldRay ? getComplex().getCaveBiomeStream().get(realX, realZ) : null; cave = shouldRay ? getComplex().getCaveBiomeStream().get(realX, realZ) : null;
@@ -96,8 +96,8 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
if (height < getDimension().getFluidHeight()) { if (height < getDimension().getFluidHeight()) {
getSeaSurfaceDecorator().decorate(finalI, j, getSeaSurfaceDecorator().decorate(finalI, j,
realX, (int) Math.round( + finalI + 1), (int) Math.round(x + finalI - 1), realX, Math.round(+finalI + 1), Math.round(x + finalI - 1),
realZ, (int) Math.round(z + j + 1), (int) Math.round(z + j - 1), realZ, Math.round(z + j + 1), Math.round(z + j - 1),
output, biome, getDimension().getFluidHeight(), getEngine().getHeight()); output, biome, getDimension().getFluidHeight(), getEngine().getHeight());
getSeaFloorDecorator().decorate(finalI, j, getSeaFloorDecorator().decorate(finalI, j,
realX, realZ, output, biome, height + 1, realX, realZ, output, biome, height + 1,
@@ -106,8 +106,8 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
if (height == getDimension().getFluidHeight()) { if (height == getDimension().getFluidHeight()) {
getShoreLineDecorator().decorate(finalI, j, getShoreLineDecorator().decorate(finalI, j,
realX, (int) Math.round(x + finalI + 1), (int) Math.round(x + finalI - 1), realX, Math.round(x + finalI + 1), Math.round(x + finalI - 1),
realZ, (int) Math.round(z + j + 1), (int) Math.round(z + j - 1), realZ, Math.round(z + j + 1), Math.round(z + j - 1),
output, biome, height, getEngine().getHeight()); output, biome, height, getEngine().getHeight());
} }
@@ -80,8 +80,8 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<BlockData>
IrisBiome biome; IrisBiome biome;
for (zf = 0; zf < h.getDepth(); zf++) { for (zf = 0; zf < h.getDepth(); zf++) {
realX = (int) xf + x; realX = xf + x;
realZ = (int) zf + z; realZ = zf + z;
biome = getComplex().getTrueBiomeStream().get(realX, realZ); biome = getComplex().getTrueBiomeStream().get(realX, realZ);
he = (int) Math.round(Math.min(h.getHeight(), getComplex().getHeightStream().get(realX, realZ))); he = (int) Math.round(Math.min(h.getHeight(), getComplex().getHeightStream().get(realX, realZ)));
hf = Math.round(Math.max(Math.min(h.getHeight(), getDimension().getFluidHeight()), he)); hf = Math.round(Math.max(Math.min(h.getHeight(), getDimension().getFluidHeight()), he));
@@ -286,33 +286,19 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
return; return;
} }
boolean u = false; boolean u = false;
if(B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.DOWN).getBlockData())) if (B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.DOWN).getBlockData())) {
{ u = true;
} else if (B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.WEST).getBlockData())) {
u = true;
} else if (B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.EAST).getBlockData())) {
u = true;
} else if (B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.SOUTH).getBlockData())) {
u = true;
} else if (B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.NORTH).getBlockData())) {
u = true; u = true;
} }
else if(B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.WEST).getBlockData())) if (u) {
{
u = true;
}
else if(B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.EAST).getBlockData()))
{
u = true;
}
else if(B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.SOUTH).getBlockData()))
{
u = true;
}
else if(B.isAir(c.getBlock(x & 15, y, z & 15).getRelative(BlockFace.NORTH).getBlockData()))
{
u = true;
}
if(u)
{
updates.compute(Cache.key(x & 15, z & 15), (k, vv) -> { updates.compute(Cache.key(x & 15, z & 15), (k, vv) -> {
if (vv != null) { if (vv != null) {
return Math.max(vv, y); return Math.max(vv, y);
@@ -785,8 +771,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
return getBiomeOrMantle(l.getBlockX(), l.getBlockY(), l.getBlockZ()); return getBiomeOrMantle(l.getBlockX(), l.getBlockY(), l.getBlockZ());
} }
default void gotoBiome(IrisBiome biome, Player player) default void gotoBiome(IrisBiome biome, Player player) {
{
Set<String> regionKeys = getDimension() Set<String> regionKeys = getDimension()
.getAllRegions(this).stream() .getAllRegions(this).stream()
.filter((i) -> i.getAllBiomes(this).contains(biome)) .filter((i) -> i.getAllBiomes(this).contains(biome))
@@ -797,28 +782,19 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
-> regionKeys.contains(getRegion((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey()) -> regionKeys.contains(getRegion((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey())
&& lb.matches(engine, chunk); && lb.matches(engine, chunk);
if(!regionKeys.isEmpty()) if (!regionKeys.isEmpty()) {
{
locator.find(player); locator.find(player);
} } else {
else
{
player.sendMessage(C.RED + biome.getName() + " is not in any defined regions!"); player.sendMessage(C.RED + biome.getName() + " is not in any defined regions!");
} }
} }
default void gotoJigsaw(IrisJigsawStructure s, Player player) default void gotoJigsaw(IrisJigsawStructure s, Player player) {
{
if (getDimension().getJigsawStructures().stream() if (getDimension().getJigsawStructures().stream()
.map(IrisJigsawStructurePlacement::getStructure) .map(IrisJigsawStructurePlacement::getStructure)
.collect(Collectors.toSet()).contains(s.getLoadKey())) .collect(Collectors.toSet()).contains(s.getLoadKey())) {
{
Locator.jigsawStructure(s.getLoadKey()).find(player); Locator.jigsawStructure(s.getLoadKey()).find(player);
} } else {
else
{
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream() Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
.filter((i) -> i.getJigsawStructures() .filter((i) -> i.getJigsawStructures()
.stream() .stream()
@@ -835,33 +811,24 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
Locator<IrisJigsawStructure> sl = Locator.jigsawStructure(s.getLoadKey()); Locator<IrisJigsawStructure> sl = Locator.jigsawStructure(s.getLoadKey());
Locator<IrisBiome> locator = (engine, chunk) -> { Locator<IrisBiome> locator = (engine, chunk) -> {
if(biomeKeys.contains(getSurfaceBiome((chunk.getX()<< 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey())) if (biomeKeys.contains(getSurfaceBiome((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey())) {
{
return sl.matches(engine, chunk); return sl.matches(engine, chunk);
} } else if (regionKeys.contains(getRegion((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey())) {
else if(regionKeys.contains(getRegion((chunk.getX()<< 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey()))
{
return sl.matches(engine, chunk); return sl.matches(engine, chunk);
} }
return false; return false;
}; };
if(!regionKeys.isEmpty()) if (!regionKeys.isEmpty()) {
{
locator.find(player); locator.find(player);
} } else {
else
{
player.sendMessage(C.RED + s.getLoadKey() + " is not in any defined regions, biomes or dimensions!"); player.sendMessage(C.RED + s.getLoadKey() + " is not in any defined regions, biomes or dimensions!");
} }
} }
} }
default void gotoObject(String s, Player player) default void gotoObject(String s, Player player) {
{
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream() Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
.filter((i) -> i.getObjects().stream().anyMatch((f) -> f.getPlace().contains(s))) .filter((i) -> i.getObjects().stream().anyMatch((f) -> f.getPlace().contains(s)))
.map(IrisRegistrant::getLoadKey) .map(IrisRegistrant::getLoadKey)
@@ -874,34 +841,24 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
Locator<IrisObject> sl = Locator.object(s); Locator<IrisObject> sl = Locator.object(s);
Locator<IrisBiome> locator = (engine, chunk) -> { Locator<IrisBiome> locator = (engine, chunk) -> {
if(biomeKeys.contains(getSurfaceBiome((chunk.getX()<< 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey())) if (biomeKeys.contains(getSurfaceBiome((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey())) {
{
return sl.matches(engine, chunk); return sl.matches(engine, chunk);
} } else if (regionKeys.contains(getRegion((chunk.getX() << 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey())) {
else if(regionKeys.contains(getRegion((chunk.getX()<< 4) + 8, (chunk.getZ() << 4) + 8).getLoadKey()))
{
return sl.matches(engine, chunk); return sl.matches(engine, chunk);
} }
return false; return false;
}; };
if(!regionKeys.isEmpty()) if (!regionKeys.isEmpty()) {
{
locator.find(player); locator.find(player);
} } else {
else
{
player.sendMessage(C.RED + s + " is not in any defined regions or biomes!"); player.sendMessage(C.RED + s + " is not in any defined regions or biomes!");
} }
} }
default void gotoRegion(IrisRegion r, Player player) default void gotoRegion(IrisRegion r, Player player) {
{ if (!getDimension().getAllRegions(this).contains(r)) {
if(!getDimension().getAllRegions(this).contains(r))
{
player.sendMessage(C.RED + r.getName() + " is not defined in the dimension!"); player.sendMessage(C.RED + r.getName() + " is not defined in the dimension!");
return; return;
} }
@@ -50,30 +50,25 @@ import java.util.function.Consumer;
public interface Locator<T> { public interface Locator<T> {
boolean matches(Engine engine, Position2 chunk); boolean matches(Engine engine, Position2 chunk);
static void cancelSearch() static void cancelSearch() {
{ if (LocatorCanceller.cancel != null) {
if(LocatorCanceller.cancel != null)
{
LocatorCanceller.cancel.run(); LocatorCanceller.cancel.run();
LocatorCanceller.cancel = null; LocatorCanceller.cancel = null;
} }
} }
default void find(Player player) default void find(Player player) {
{
find(player, 30_000); find(player, 30_000);
} }
default void find(Player player, long timeout) default void find(Player player, long timeout) {
{
AtomicLong checks = new AtomicLong(); AtomicLong checks = new AtomicLong();
long ms = M.ms(); long ms = M.ms();
new SingleJob("Searching", () -> { new SingleJob("Searching", () -> {
try { try {
Position2 at = find(IrisToolbelt.access(player.getWorld()).getEngine(), new Position2(player.getLocation().getBlockX() >> 4, player.getLocation().getBlockZ() >> 4), timeout, checks::set).get(); Position2 at = find(IrisToolbelt.access(player.getWorld()).getEngine(), new Position2(player.getLocation().getBlockX() >> 4, player.getLocation().getBlockZ() >> 4), timeout, checks::set).get();
if(at != null) if (at != null) {
{
J.s(() -> player.teleport(new Location(player.getWorld(), (at.getX() << 4) + 8, J.s(() -> player.teleport(new Location(player.getWorld(), (at.getX() << 4) + 8,
IrisToolbelt.access(player.getWorld()).getEngine().getHeight( IrisToolbelt.access(player.getWorld()).getEngine().getHeight(
(at.getX() << 4) + 8, (at.getX() << 4) + 8,
@@ -102,8 +97,7 @@ public interface Locator<T> {
} }
default Future<Position2> find(Engine engine, Position2 pos, long timeout, Consumer<Integer> checks) throws WrongEngineBroException { default Future<Position2> find(Engine engine, Position2 pos, long timeout, Consumer<Integer> checks) throws WrongEngineBroException {
if(engine.isClosed()) if (engine.isClosed()) {
{
throw new WrongEngineBroException(); throw new WrongEngineBroException();
} }
@@ -123,19 +117,15 @@ public interface Locator<T> {
Spiraler s = new Spiraler(100000, 100000, (x, z) -> next.set(new Position2(x, z))); Spiraler s = new Spiraler(100000, 100000, (x, z) -> next.set(new Position2(x, z)));
s.setOffset(cursor.getX(), cursor.getZ()); s.setOffset(cursor.getX(), cursor.getZ());
s.next(); s.next();
while(!found.get() && !stop.get() && px.getMilliseconds() < timeout) while (!found.get() && !stop.get() && px.getMilliseconds() < timeout) {
{
BurstExecutor e = burst.burst(tc); BurstExecutor e = burst.burst(tc);
for(int i = 0; i < tc; i++) for (int i = 0; i < tc; i++) {
{
Position2 p = next.get(); Position2 p = next.get();
s.next(); s.next();
e.queue(() -> { e.queue(() -> {
if(matches(engine, p)) if (matches(engine, p)) {
{ if (foundPos.get() == null) {
if(foundPos.get() == null)
{
foundPos.set(p); foundPos.set(p);
} }
@@ -151,8 +141,7 @@ public interface Locator<T> {
LocatorCanceller.cancel = null; LocatorCanceller.cancel = null;
if(found.get() && foundPos.get() != null) if (found.get() && foundPos.get() != null) {
{
return foundPos.get(); return foundPos.get();
} }
@@ -160,47 +149,39 @@ public interface Locator<T> {
}); });
} }
static Locator<IrisRegion> region(String loadKey) static Locator<IrisRegion> region(String loadKey) {
{
return (e, c) -> e.getRegion((c.getX() << 4) + 8, (c.getZ() << 4) + 8).getLoadKey().equals(loadKey); return (e, c) -> e.getRegion((c.getX() << 4) + 8, (c.getZ() << 4) + 8).getLoadKey().equals(loadKey);
} }
static Locator<IrisJigsawStructure> jigsawStructure(String loadKey) static Locator<IrisJigsawStructure> jigsawStructure(String loadKey) {
{
return (e, c) -> { return (e, c) -> {
IrisJigsawStructure s = e.getStructureAt(c.getX(), c.getZ()); IrisJigsawStructure s = e.getStructureAt(c.getX(), c.getZ());
return s != null && s.getLoadKey().equals(loadKey); return s != null && s.getLoadKey().equals(loadKey);
}; };
} }
static Locator<IrisObject> object(String loadKey) static Locator<IrisObject> object(String loadKey) {
{
return (e, c) -> e.getObjectsAt(c.getX(), c.getZ()).contains(loadKey); return (e, c) -> e.getObjectsAt(c.getX(), c.getZ()).contains(loadKey);
} }
static Locator<IrisBiome> surfaceBiome(String loadKey) static Locator<IrisBiome> surfaceBiome(String loadKey) {
{
return (e, c) -> e.getSurfaceBiome((c.getX() << 4) + 8, (c.getZ() << 4) + 8).getLoadKey().equals(loadKey); return (e, c) -> e.getSurfaceBiome((c.getX() << 4) + 8, (c.getZ() << 4) + 8).getLoadKey().equals(loadKey);
} }
static Locator<IrisBiome> caveBiome(String loadKey) static Locator<IrisBiome> caveBiome(String loadKey) {
{
return (e, c) -> e.getCaveBiome((c.getX() << 4) + 8, (c.getZ() << 4) + 8).getLoadKey().equals(loadKey); return (e, c) -> e.getCaveBiome((c.getX() << 4) + 8, (c.getZ() << 4) + 8).getLoadKey().equals(loadKey);
} }
static Locator<IrisBiome> caveOrMantleBiome(String loadKey) static Locator<IrisBiome> caveOrMantleBiome(String loadKey) {
{
return (e, c) -> { return (e, c) -> {
AtomicBoolean found = new AtomicBoolean(false); AtomicBoolean found = new AtomicBoolean(false);
e.generateMatter(c.getX(), c.getZ(), true); e.generateMatter(c.getX(), c.getZ(), true);
e.getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), MatterCavern.class, (x, y, z, t) -> { e.getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), MatterCavern.class, (x, y, z, t) -> {
if(found.get()) if (found.get()) {
{
return; return;
} }
if(t != null && t.getCustomBiome().equals(loadKey)) if (t != null && t.getCustomBiome().equals(loadKey)) {
{
found.set(true); found.set(true);
} }
}); });
@@ -243,8 +243,7 @@ public class PlannedPiece {
@Override @Override
public Engine getEngine() { public Engine getEngine() {
if(IrisToolbelt.isIrisWorld(world)) if (IrisToolbelt.isIrisWorld(world)) {
{
return IrisToolbelt.access(world).getEngine(); return IrisToolbelt.access(world).getEngine();
} }
@@ -260,5 +260,6 @@ public interface EngineMantle extends IObjectPlacer {
} }
MantleJigsawComponent getJigsawComponent(); MantleJigsawComponent getJigsawComponent();
MantleObjectComponent getObjectComponent(); MantleObjectComponent getObjectComponent();
} }
@@ -113,8 +113,7 @@ public class IrisEntitySpawn implements IRare {
World world = gen.getWorld().realWorld(); World world = gen.getWorld().realWorld();
if (spawns > 0) { if (spawns > 0) {
if(referenceMarker != null) if (referenceMarker != null) {
{
gen.getMantle().getMantle().remove(c.getX(), c.getY(), c.getZ(), MatterMarker.class); gen.getMantle().getMantle().remove(c.getX(), c.getY(), c.getZ(), MatterMarker.class);
} }
@@ -53,8 +53,7 @@ public class IrisMarker extends IrisRegistrant {
@Desc("If this marker is used, what is the chance it removes itself. For example 25% (0.25) would mean that on average 4 uses will remove a specific marker. Set this below 0 (-1) to never exhaust & set this to 1 or higher to always exhaust on first use.") @Desc("If this marker is used, what is the chance it removes itself. For example 25% (0.25) would mean that on average 4 uses will remove a specific marker. Set this below 0 (-1) to never exhaust & set this to 1 or higher to always exhaust on first use.")
private double exhaustionChance = 0.33; private double exhaustionChance = 0.33;
public boolean shouldExhaust() public boolean shouldExhaust() {
{
return RNG.r.chance(exhaustionChance); return RNG.r.chance(exhaustionChance);
} }
@@ -658,32 +658,26 @@ public class IrisObject extends IrisRegistrant {
KMap<BlockVector, String> markers = null; KMap<BlockVector, String> markers = null;
try { try {
if(config.getMarkers().isNotEmpty() && placer.getEngine() != null) if (config.getMarkers().isNotEmpty() && placer.getEngine() != null) {
{
markers = new KMap<>(); markers = new KMap<>();
for(IrisObjectMarker j : config.getMarkers()) for (IrisObjectMarker j : config.getMarkers()) {
{
IrisMarker marker = getLoader().getMarkerLoader().load(j.getMarker()); IrisMarker marker = getLoader().getMarkerLoader().load(j.getMarker());
if(marker == null) if (marker == null) {
{
continue; continue;
} }
int max = j.getMaximumMarkers(); int max = j.getMaximumMarkers();
for(BlockVector i : getBlocks().k().shuffle()) for (BlockVector i : getBlocks().k().shuffle()) {
{ if (max <= 0) {
if(max <= 0)
{
break; break;
} }
BlockData data = getBlocks().get(i); BlockData data = getBlocks().get(i);
for (BlockData k : j.getMark(rdata)) { for (BlockData k : j.getMark(rdata)) {
if(max <= 0) if (max <= 0) {
{
break; break;
} }
@@ -691,8 +685,7 @@ public class IrisObject extends IrisRegistrant {
boolean a = !blocks.containsKey(new BlockVector(i.clone().add(new BlockVector(0, 1, 0)))); boolean a = !blocks.containsKey(new BlockVector(i.clone().add(new BlockVector(0, 1, 0))));
boolean fff = !blocks.containsKey(new BlockVector(i.clone().add(new BlockVector(0, 2, 0)))); boolean fff = !blocks.containsKey(new BlockVector(i.clone().add(new BlockVector(0, 2, 0))));
if((marker.isEmptyAbove() && a && fff) || !marker.isEmptyAbove()) if ((marker.isEmptyAbove() && a && fff) || !marker.isEmptyAbove()) {
{
markers.put(i, j.getMarker()); markers.put(i, j.getMarker());
max--; max--;
} }
@@ -787,8 +780,7 @@ public class IrisObject extends IrisRegistrant {
listener.accept(new BlockPosition(xx, yy, zz)); listener.accept(new BlockPosition(xx, yy, zz));
} }
if(markers != null && markers.containsKey(g)) if (markers != null && markers.containsKey(g)) {
{
placer.getEngine().getMantle().getMantle().set(xx, yy, zz, new MatterMarker(markers.get(g))); placer.getEngine().getMantle().getMantle().set(xx, yy, zz, new MatterMarker(markers.get(g)));
} }
@@ -19,17 +19,14 @@
package com.volmit.iris.util.interpolation; package com.volmit.iris.util.interpolation;
import com.google.common.util.concurrent.AtomicDouble; import com.google.common.util.concurrent.AtomicDouble;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.NoiseStyle; import com.volmit.iris.engine.object.NoiseStyle;
import com.volmit.iris.util.format.Form; import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.function.Consumer2; import com.volmit.iris.util.function.Consumer2;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.function.NoiseProvider; import com.volmit.iris.util.function.NoiseProvider;
import com.volmit.iris.util.function.NoiseProvider3; import com.volmit.iris.util.function.NoiseProvider3;
import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.noise.CNG;
import com.volmit.iris.util.noise.SimplexNoise;
import com.volmit.iris.util.scheduling.PrecisionStopwatch; import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -307,12 +304,10 @@ public class IrisInterpolation {
//@done //@done
} }
public static void test(String m, Consumer2<Integer, Integer> f) public static void test(String m, Consumer2<Integer, Integer> f) {
{
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
for(int i = 0; i < 8192; i++) for (int i = 0; i < 8192; i++) {
{
f.accept(i, -i * 234); f.accept(i, -i * 234);
} }
@@ -322,45 +317,58 @@ public class IrisInterpolation {
} }
public static void main(String[] args) { public static void main(String[] args) {
CNG cng = new CNG(new RNG()); printOptimizedSrc(false);
NoiseProvider n = cng::noise;
System.out.println(generateOptimizedStarcast(3));
System.out.println(generateOptimizedStarcast(5));
System.out.println(generateOptimizedStarcast(6));
System.out.println(generateOptimizedStarcast(7));
System.out.println(generateOptimizedStarcast(9));
System.out.println(generateOptimizedStarcast(12));
System.out.println(generateOptimizedStarcast(24));
System.out.println(generateOptimizedStarcast(32));
System.out.println(generateOptimizedStarcast(48));
System.out.println(generateOptimizedStarcast(64));
System.out.println(generateOptimizedStarcast(72));
System.out.println(generateOptimizedStarcast(96));
System.out.println(generateOptimizedStarcast(128));
System.out.println(generateOptimizedStarcast(186));
System.out.println(generateOptimizedStarcast(256));
} }
public static String generateOptimizedStarcast(double checks) { public static void printOptimizedSrc(boolean arrays) {
System.out.println(generateOptimizedStarcast(3, arrays));
System.out.println(generateOptimizedStarcast(5, arrays));
System.out.println(generateOptimizedStarcast(6, arrays));
System.out.println(generateOptimizedStarcast(7, arrays));
System.out.println(generateOptimizedStarcast(9, arrays));
System.out.println(generateOptimizedStarcast(12, arrays));
System.out.println(generateOptimizedStarcast(24, arrays));
System.out.println(generateOptimizedStarcast(32, arrays));
System.out.println(generateOptimizedStarcast(48, arrays));
System.out.println(generateOptimizedStarcast(64, arrays));
}
public static String generateOptimizedStarcast(double checks, boolean array) {
double m = (360 / checks); double m = (360 / checks);
int ig = 0; int ig = 0;
int igx = 0; int igx = 0;
StringBuilder fb = new StringBuilder(); StringBuilder fb = new StringBuilder();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (array) {
fb.append("private static final double[] F" + (int) checks + "A = {"); fb.append("private static final double[] F" + (int) checks + "A = {");
}
sb.append("private static double sc" + (int) checks + "(int x, int z, double r, NoiseProvider n) {\n return ("); sb.append("private static double sc" + (int) checks + "(int x, int z, double r, NoiseProvider n) {\n return (");
for (int i = 0; i < 360; i += m) { for (int i = 0; i < 360; i += m) {
double sin = Math.sin(Math.toRadians(i)); double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i)); double cos = Math.cos(Math.toRadians(i));
String cof = new BigDecimal(cos).toPlainString(); String cof = new BigDecimal(cos).toPlainString();
String sif = new BigDecimal(sin).toPlainString(); String sif = new BigDecimal(sin).toPlainString();
String cc = "F"+(int)checks+"A["+(igx++)+"]"; String cc = array ? "F" + (int) checks + "A[" + (igx++) + "]" : "F" + (int) checks + "C" + ig;
String ss = "F"+(int)checks+"A["+(igx++)+"]"; String ss = array ? "F" + (int) checks + "A[" + (igx++) + "]" : "F" + (int) checks + "S" + ig;
fb.append((ig > 0 ? (ig % 3 == 0 ? ",\n" : ",") : "") + cof + "," + sif);
if (array) {
fb.append((ig > 0 ? (ig % 6 == 0 ? ",\n" : ",") : "") + cof + "," + sif);
} else {
fb.append("private static final double " + cc + " = " + cof + ";\n");
fb.append("private static final double " + ss + " = " + sif + ";\n");
}
sb.append((ig > 0 ? "\n +" : "") + "n.noise(x + ((r * " + cc + ") - (r * " + ss + ")), z + ((r * " + ss + ") + (r * " + cc + ")))"); sb.append((ig > 0 ? "\n +" : "") + "n.noise(x + ((r * " + cc + ") - (r * " + ss + ")), z + ((r * " + ss + ") + (r * " + cc + ")))");
ig++; ig++;
} }
if (array) {
fb.append("};"); fb.append("};");
}
sb.append(")/" + checks + "D;\n}"); sb.append(")/" + checks + "D;\n}");
return fb + "\n" + sb; return fb + "\n" + sb;
} }
File diff suppressed because it is too large Load Diff
@@ -60,8 +60,7 @@ public class Spiral implements Iterable<Position2> {
return p; return p;
} }
public static Spiral from(Position2 p, long iterations) public static Spiral from(Position2 p, long iterations) {
{
return new Spiral(p, iterations); return new Spiral(p, iterations);
} }